Link to home
Start Free TrialLog in
Avatar of pointeman
pointemanFlag for United States of America

asked on

Dynamic Cursor Where Clause?

Q. Anyway to include or change the where clause in a Oracle Cursor in a stored procedure?

CREATE OR REPLACE PROCEDURE "procedure1" (
tmpltno IN NUMBER)

AS

c_qstn cursor;
sql varchar(200);

if tmplt = 0
 sql = 'SELECT id FROM table1;
else
sql = 'SELECT id FROM table4 WHERE tmplt_id = tmpltno';

BEGIN ....
Avatar of David VanZandt
David VanZandt
Flag of United States of America image

The syntax for the case statement is:

CASE  [ expression ]
  WHEN condition_1 THEN result_1
  WHEN condition_2 THEN result_2
  ...
  WHEN condition_n THEN result_n
  ELSE result
END

source: http://www.techonthenet.com/oracle/functions/case.php  and many examples in E-E knowledge base.
ASKER CERTIFIED SOLUTION
Avatar of Sean Stuber
Sean Stuber

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pointeman

ASKER

:b is what ???
Avatar of Sean Stuber
Sean Stuber

:b1 is the bind variable

you could give it another name

remember to keep the colon in front of it
okay, now having issues trying to run a loop like so:

 FOR v_c_qstn IN c_qstn -- error
       LOOP
         ...

Error:
PLS-00221 (291: 27): PLS-00221: 'C_QSTN' is not a procedure or is undefined
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Now changing the 'For' statements...