How do i select a value into a variable before opening SYS_REFCURSOR?

Viewed 43

i'm currently working with a stored procedure ( on oracle toad )which has a lot of unions and left joins. I want to declare a variable and get a unique value from a table. this is what i want to do:

CREATE OR REPLACE PROCEDURE owner.SP_nameofsp
(
parameters
) 

is 

begin

 declare variable nvarchar2;
 select value into variable from  table; <- this is not working

OPEN pcursorFOR
select  
(.....)
end;
/

is this possible? if so how can i do it? thanks!

1 Answers

"select value into variable from table" : there is a good chance that more than 1 row will be matched... when selecting "INTO variable" make sure the query has a WHERE clause so to return at most 1 row... (and be prepared none is returned)

Related