-->

Count(*) is unsafe

SELECT COUNT(*) INTO var WHERE condition;

IF var > 0 THEN
SELECT NEEDED_FIELD INTO otherVar WHERE condition;

In PLSQL method with count(*) is unsafe in above code. If another session deletes the row that met the condition after the line with the count(*), and before the line with the select ... into, the code will throw an exception that will not get handled.

Use the below insted,

SELECT NEEDED_FIELD INTO var WHERE condition;
EXCEPTION
WHEN NO_DATA_FOUND

Stack Overflow


bino kochumol varghese profile pic

Written By

Bino Kochumol Varghese

A software engineer who is a voracious reader and an active blogger.