Oracle - 子程序或游标 c_tab 超出范围

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40834345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 03:20:18  来源:igfitidea点击:

Oracle - subprogram or cursor c_tab is out of scope

sqldatabaseoracleplsql

提问by Jan Maděra

create or replace procedure CV8_POCET_RADKU(p_schema VARCHAR2, p_razeni IN varchar2 default 'asc') as
i_dotaz varchar2(200) := 'select count(*) from ';
i_pocet number;  
cursor c_tab is 
  select object_name
  from dba_objects where object_type = 'TABLE' 
  and owner = upper(p_schema) 
  order by object_name asc;

  i_tab c_tab%rowtype;
begin 
dbms_output.put_line('Tabulky ze schematu: ' ||p_schema);
open c_tab;
loop
  fetch c_tab into i_tab;
  exit when c_tab%notfound;
  execute immediate i_dotaz || p_schema||'.'||i_tab.object_name into i_pocet;
  dbms_output.put_line(c_tab.object_name || ' - '|| i_pocet || 'radku');
end loop;
close c_tab;
end;

Oracle give me a error subprogram or cursor c_tab is out of scope. I think i have the cursor right.

Oracle 给我一个错误 subprogram or cursor c_tab is out of scope。我想我的光标是正确的。

回答by Bob Jarvis - Reinstate Monica

The problem is in the line which reads:

问题出在以下行中:

dbms_output.put_line(c_tab.object_name || ' - '|| i_pocet || 'radku');

You can't refer to c_tablike this - instead, refer to the row variable you read the data into:

您不能c_tab像这样引用- 相反,请引用您将数据读入的行变量:

dbms_output.put_line(i_tab.object_name || ' - '|| i_pocet || 'radku');

Best of luck.

祝你好运。