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!

How to get rowcount on dynamic sql?

889110Dec 7 2011 — edited Dec 8 2011
Gurus, experts, and just plain people who are smarter than me. I've googled and googled and I while there are examples of how to do this, there is some complication that doesn't apply to me!
I have a PLSQL function that depends upon knowing the number of rows returned in order to figure out what to set a variable to.

E.g.:

v_sql := 'select element_id from '||v_lsidt||'_base where element_id = '||chr(39)||v_osid||chr(39);
EXECUTE IMMEDIATE v_sql
IF SQL%ROWCOUNT > 0 THEN
...
ELSE
...
END IF

Unfortunately, it seems like the rowcount is always coming back as so the code doesn't pass through the IF block. Can someone explain to me what I'm doing wrong?

Thank you.

PS - I realize this may be a common question so I apologize in advance if the answer was in plain sight and I failed to recognize it lol.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 5 2012
Added on Dec 7 2011
3 comments
2,657 views