我想在动态plsql语句中获得count(*)
值。我们可以将静态stmt编写为:
select count(*) into tmp_cnt from table_info where nbr_entry='0123456789';
但是在编写动态sql语句时如何获取tmp_cnt
值?或通过其他任何方式将count(*)
值转换为tmp_cnt
变量?
您可以通过立即执行...返回到:
function count_rows(p_table_name varchar2)
return number
is
l_count number;
begin
execute immediate 'select count(*) from ' || p_table_name into l_count;
return l_count;
end count_rows;
也许是不同的oracle版本,但是对我有用的是:
...
execute immediate 'select count(*) from ' || p_table_name into l_count;
...