LarrySteele
Programmer
I have a few dozen scripts that share 90% of their code. Primary difference is the cursor that's opened while running said script.
What I'd like to do is create a PROC and pass the SQL for the cursor I want the PROC to use. I've Googled and found references to REFCURSOR which I thought might be applicable, but have not had success. I've tried so many variations that I'm to the point where I need to clear the slate and start over.
Here's what I want to do...
You see what I have in bold. The idea is that I want the text from in_cursor to be used in the cursor definition.
One of the things I tried was creating a PROC that's supposed to generate a cursor. I pulled said script from here:
In a PROC, I mimicked what I saw:
Oracle's response:
The first line was highlighted.
Tried what I'm a bit more used to:
This time Oracle complained about the second line:
Other variations met with the same level of success (read: failure).
How do I pass an SQL string to a PROC and have the PROC use that SQL string as a cursor? I'm sure the answer's easy, but it's eluded me so far...
Thanks in advance,
Larry
What I'd like to do is create a PROC and pass the SQL for the cursor I want the PROC to use. I've Googled and found references to REFCURSOR which I thought might be applicable, but have not had success. I've tried so many variations that I'm to the point where I need to clear the slate and start over.
Here's what I want to do...
Code:
create or replace procedure table_stuff ([b]in_cursor varchar2[/b]) as
cursor csr_data is [b]in_cursor[/b];
begin
open csr_data;
loop
fetch csr_data
{do stuff}
end loop;
close csr_data;
exception
{get over it}
end;
/
One of the things I tried was creating a PROC that's supposed to generate a cursor. I pulled said script from here:
Code:
create or replace procedure gen_cur(str in varchar2,rc in out sys_refcursor) is
str1 varchar2(2000);
begin
str1 := str;
open rc for str1;
exception
when others then dbms_output.put_line(sqlerrm);
end;
/
In a PROC, I mimicked what I saw:
Code:
variable csr_data refcursor;
gen_cur(in_cursor,:csr_data);
Oracle's response:
Code:
PLS-00103: Encountered the symbol "REFCURSOR" when expecting one of the following:
:= . ( @ % ; not null range default character
Tried what I'm a bit more used to:
Code:
csr_data refcursor;
gen_cur(in_cursor,:csr_data);
This time Oracle complained about the second line:
Code:
PLS-00049: bad bind variable 'CSR_DATA'
Other variations met with the same level of success (read: failure).
How do I pass an SQL string to a PROC and have the PROC use that SQL string as a cursor? I'm sure the answer's easy, but it's eluded me so far...
Thanks in advance,
Larry