I\'m using Oracle, and I have a very large table. I need to check for the existence of any row meeting some simple criteria. What\'s the best way to go about this using simple
SELECT NULL
FROM x
WHERE x.col_a = value_a
AND x.col_b = value_b
AND rownum = 1
COUNT(*)
is certainly not the best way since it will need to count all the rows, while ROWNUM = 1
returns as soon as it finds the first matching row.
Here's the PL/SQL
code:
DECLARE
ex INT;
BEGIN
BEGIN
SELECT NULL
INTO ex
FROM dual
WHERE 1 = 1
AND rownum = 1;
DBMS_OUTPUT.put_line('found');
EXCEPTION
WHEN no_data_found THEN
DBMS_OUTPUT.put_line('not found');
END;
END;