I have a question regarding sys_refcursor.
A sys_refcursor can only be used with a select statement or can this be used like the following. I would like the function to return sys_refcursor.
p_cursor is defined as sys_refcursor
FOR i IN c
LOOP
IF (p_start_date BETWEEN i.start_date AND i.end_date)
OR (p_end_date BETWEEN i.start_date AND i.end_date)
THEN
p_cursor := i.product_no;
END IF;
END LOOP;
You have two ways of doing this depending on what you want.
First
If you always want to have the column in your cursor, and depending on that condition, to assign a value to the column or not. You can do the following
Code:
Second
If you want sometimes to have the column and sometimes you just dont. You can dinamically create the query in a
varcharvariable and then assign that query to the cursor.Code: