|
Re: can use a SQL dynamic in a CURSOR ? [message #39042 is a reply to message #39039] |
Mon, 10 June 2002 01:38 |
|
Maaher
Messages: 7065 Registered: December 2001
|
Senior Member |
|
|
Hi,
you can accomplish this by using a ref cursor. At OTN (http://otn.oracle.com), you can find more information concerning ref cursors, but here's an example.
declare
TYPE dual_cursor_type is ref cursor;
test_cv dual_cursor_type;
choice number := &input_number;
v_testing varchar2(25);
begin
IF choice = 1 THEN
OPEN test_cv FOR SELECT 'One' FROM dual;
ELSIF choice = 2 THEN
OPEN test_cv FOR SELECT 'Two' FROM emp WHERE rownum < 2;
ELSIF choice = 3 THEN
OPEN test_cv FOR SELECT 'Three' FROM dept WHERE rownum <2;
END IF;
FETCH test_cv INTO v_testing;
close test_cv;
dbms_output.put_line('Your choice was : '||v_testing);
end;
/
Of course, this example is useless, but you'll get the drift.
HTH,
MHE
|
|
|