Alternative to select count..
ZjelJun 8 2012 — edited Jun 16 2012Hi folks,
I'm creating this procedure which needs to check if a value exists in a certain table.
If it exists, the data inside needs to be copied, if not, default data will be given instead.
This is a scrap of the code:
V_SQL := 'SELECT COUNT(ID) FROM ' || V_OLD_TABLE_LIST(J) || ' WHERE ' || V_OLD_COLUMN_LIST(J) || ' IS NOT NULL;
EXECUTE IMMEDIATE V_SQL INTO V_COUNT;
IF V_COUNT > 0 THEN
-- do other stuff
END IF;
Now, the above statement is encapsuled by a for loop. This loop contains thousands of values.
This is causing the procedure to be very slow. The thing taking the most time in my procedure, is the 'select count...' part.
Is there any alternative to this, which is much more performant?
Many thanks in advance!
Zjel