Avatar of pointeman
pointeman
Flag 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 ....
Oracle Database

Avatar of undefined
Last Comment
pointeman

8/22/2022 - Mon
David VanZandt

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
Sean Stuber

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
pointeman

ASKER
:b is what ???
Sean Stuber

:b1 is the bind variable

you could give it another name

remember to keep the colon in front of it
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
pointeman

ASKER
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
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
pointeman

ASKER
Now changing the 'For' statements...