Home » SQL & PL/SQL » SQL & PL/SQL » can use a SQL dynamic in a CURSOR ?
can use a SQL dynamic in a CURSOR ? [message #39039] Mon, 10 June 2002 00:04 Go to next message
Samir
Messages: 32
Registered: April 2002
Member
Hello,
my question is:
can i use a SQL dynamic in a declaration of a CURSOR.
ex:
CURSOR C1 is
here SQL DYNAMIC ??

Thanks for all .
Re: can use a SQL dynamic in a CURSOR ? [message #39042 is a reply to message #39039] Mon, 10 June 2002 01:38 Go to previous message
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
Previous Topic: from sysdate
Next Topic: Errors
Goto Forum:
  


Current Time: Fri Apr 19 16:19:07 CDT 2024