Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Alternative to select count..

ZjelJun 8 2012 — edited Jun 16 2012
Hi 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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 14 2012
Added on Jun 8 2012
10 comments
1,761 views