how to get count(*) value in local temp variable in dynamic sql (ORACLE PLSQL)

Vijay Kolte picture Vijay Kolte · Jul 23, 2012 · Viewed 14.2k times · Source

I want to get count(*) value in dynamic plsql statement. We can write static stmt as:

select count(*) into tmp_cnt from table_info where nbr_entry='0123456789';

but how to get tmp_cnt value while writing the dynamic sql stament? or any other way to get count(*) value into tmp_cnt variable?

Answer

Miguel picture Miguel · Jan 30, 2015

Maybe different oracle version, but what worked for me was:

...
execute immediate 'select count(*) from ' || p_table_name into l_count;
...