如何在动态sql(ORACLE PLSQL)中获取本地临时变量count(*)值



我想在动态plsql语句中获得count(*)值。我们可以将静态stmt写成:

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

但是如何在编写动态sql雄蕊时获得tmp_cnt值呢?或者以任何其他方式将CCD_ 3值获取到CCD_?

也许是不同的oracle版本,但对我有效的是:

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

您可以使用EXECUTE IMMEDIATE来实现它。。。返回到:

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;

最新更新