动态选择没有得到结果
我正在尝试在循环中执行动态选择,但没有得到任何结果。我想让它像正常选择一样工作。
create or replace type proc_args as varray(20) of varchar2(50);
/
create or replace procedure proc_show_tab(args proc_args)
is
id_kursora integer;
wart integer;
polecenie varchar2(30);
begin
for i in 1..args.count loop
polecenie := 'SELECT * FROM '||args(i);
execute immediate polecenie;
end loop;
end;
/
show error;
declare
args2 proc_args;
begin
args2 := proc_args();
args2.extend(2);
args2(1) := 'osrodek';
args2(2) := 'trasa';
proc_show_tab(args2);
end;
/
I'm trying to execute dynamic select in loop but i don't get any results. I would like to make it work like normal select.
create or replace type proc_args as varray(20) of varchar2(50);
/
create or replace procedure proc_show_tab(args proc_args)
is
id_kursora integer;
wart integer;
polecenie varchar2(30);
begin
for i in 1..args.count loop
polecenie := 'SELECT * FROM '||args(i);
execute immediate polecenie;
end loop;
end;
/
show error;
declare
args2 proc_args;
begin
args2 := proc_args();
args2.extend(2);
args2(1) := 'osrodek';
args2(2) := 'trasa';
proc_show_tab(args2);
end;
/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PL/SQL 在将数据返回到执行客户端的方式上与 T-SQL 不同。
SQL SELECT 语句在您的代码中执行两次,但不会将结果返回给任何内容 - 要将数据返回给客户端,您需要显式返回 REF CURSOR(并且客户端需要知道您是)或使用DBMS_OUTPUT.put_line 或类似的东西在“输出”中显示结果。当您收到“匿名块已完成”时,这意味着您的块已完成且没有错误。
如何返回结果将根据您想要完成的任务而有所不同。
PL/SQL is not like T-SQL in how it returns data to the executing client.
A SQL SELECT statement is being executed twice in your code, but does not return the results back to anything - to return data to a client, you need to explicitly return a REF CURSOR (and the client needs to know that you are) or use DBMS_OUTPUT.put_line or something similar to display your results in the "output." When you get "anonymous block completed" that means that your block completed without errors.
How to return the results will vary depending on what you are trying to accomplish.