Vij*_*lte 6 oracle plsql plsqldeveloper
我想count(*)在动态plsql语句中获得价值.我们可以编写静态stmt:
select count(*) into tmp_cnt from table_info where nbr_entry='0123456789';
Run Code Online (Sandbox Code Playgroud)
但是如何tmp_cnt在编写动态sql stament时获得价值?或任何其他方式将count(*)价值变为tmp_cnt变量?
小智 9
也许不同的oracle版本,但对我有用的是:
...
execute immediate 'select count(*) from ' || p_table_name into l_count;
...
Run Code Online (Sandbox Code Playgroud)
您可以通过EXECUTE IMMEDIATE实现它...返回:
function count_rows(p_table_name varchar2)
return number
is
l_count number;
begin
execute immediate 'select count(*) from ' || p_table_name returning into l_count;
return l_count;
end count_rows;
Run Code Online (Sandbox Code Playgroud)