SQL Oracle EXECUTE IMMEDIATE 成游标

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4714163/
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-01 08:54:41  来源:igfitidea点击:

Oracle EXECUTE IMMEDIATE into a cursor

sqloraclestored-proceduresdynamic-sqlsys-refcursor

提问by Ankit

I have a stored procedure which used the EXECUTE IMMEDIATEcommand to execute a very long string. How do I support a very long string and return the data into a refcursor?

我有一个存储过程,它使用该EXECUTE IMMEDIATE命令来执行一个很长的字符串。如何支持很长的字符串并将数据返回到refcursor?

回答by Allan

Assuming that your SQL is not longer than 32K (as @Tony Andrews hinted at), you should be able to use something like this:

假设您的 SQL 不超过 32K(正如@Tony Andrews 所暗示的那样),您应该能够使用如下内容:

declare
   SQL_Text varchar2(32760) := 'select * from dual'; --your query goes here
   cur sys_refcursor;
begin
   open cur for SQL_Text;
end;

When working with Ref Cursors, open-forcan be used directly, instead of execute immediate.

使用 Ref Cursors 时,open-for可以直接使用,而不是execute immediate.