Home » SQL & PL/SQL » SQL & PL/SQL » CURSOR with dynamic condition
CURSOR with dynamic condition [message #8452] Thu, 21 August 2003 07:47 Go to next message
fulvio
Messages: 6
Registered: March 2003
Junior Member
want to change the condition of my cursor programmatically.
I have two different condition, and a cursor per condition

Declare

c1 is select prod_name ,prod_price,prod_qty*1000
from products
where ABC;

c2 is select prod_name ,prod_price,prod_qty*1000
from products
where DEF;
Is it possible to pass the string in the where condition?
Otherwise i can i do?

PLZ HELP!!
Re: CURSOR with dynamic condition [message #8453 is a reply to message #8452] Thu, 21 August 2003 13:18 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
You'll need to use dynamic SQL and explicit cursors.

create or replace procedure p(p_where in varchar2)
is
  v_sql := 'select prod_name ,prod_price,prod_qty*1000
from products';
  v_rc  sys_refcursor;  -- 9i
begin
  open v_rc for v_sql || p_where;
  loop
    fetch v_rc into ...;
    exit when v_rc%notfound;
    -- do something
  end loop;
  close v_rc;
end;
Previous Topic: Outer joins- left and right
Next Topic: Query or the database?
Goto Forum:
  


Current Time: Wed Apr 24 15:38:42 CDT 2024