I have a stored procedure which used the EXECUTE IMMEDIATE
command to execute a very long string. How do I support a very long string and return the data into a refcursor?
Asked
Active
Viewed 4.3k times
11

Peter Mortensen
- 30,738
- 21
- 105
- 131

Ankit
- 6,388
- 8
- 54
- 79
-
4How long is "very long"? More than 32K? – Tony Andrews Jan 17 '11 at 15:35
1 Answers
20
Assuming that your SQL is not longer than 32K (as @Tony Andrews hinted at), you should be able to use something like this:
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-for
can be used directly, instead of execute immediate
.

Allan
- 17,141
- 4
- 52
- 69