如何在动态pl-sql之外检索变量的值?

时间:2014-06-02 13:25:39

标签: plsql dynamic-sql execute-immediate

我执行以下查询:

declare 
  i number;
begin
  execute immediate 'select count(1) from someTable' returning into i;
  dbms_output.put_line(i);
end;

并得到此错误:returns子句必须与insert,update和delete一起使用!

1 个答案:

答案 0 :(得分:1)

只是一个小的语法错误(没有RETURNING):

DECLARE
    i NUMBER;
BEGIN
    EXECUTE IMMEDIATE 'select count(1) from user_tables' INTO i;
    dbms_output.put_line(i);
END;