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!

Generating Dynamic sql to count records on a table

TinaMar 22 2021 — edited Mar 23 2021

Hi Gurus,
I am trying to come up with one requirement to generate sql statements dynamically , and run each statement individually.Before running any job, we load multiple tables from one procedure.Now I have a requirement to check if all dependency tables for that package is loaded for a given day or not.If we don't have data then throw error.
I am using all_dependencies to pull dependent tables I can get the list of queries however what would be efficient way to execute each statement? Is there a way to process each statements using some cursor?

SELECT 'SELECT COUNT(*) FROM '||REFERENCED_NAME ||' WHERE CREATED_DATE = SYSDATE;' FROM ALL_DEPENDENCIES
WHERE OWNER=SCHEMA_1
AND NAME = MY_PKG
AND REFERENCED_TYPE='TABLE';

Thanks

Comments
Post Details
Added on Mar 22 2021
4 comments
2,330 views