Skip to Main Content

Oracle Forms

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to Run a Select Query stored in a Variable

TrojanSpiritNov 20 2012 — edited Nov 20 2012
Hello,

I have a following requirement:

Result of one select query on Var1 , result of other select query in Var2 ,
if Va2 = 'value11' OR Var2 = 'Value2' then Var1 = 'select query'. Now how can I run this SQL query at the end of the Pl/SQL?

so I'm writing following query for the same:

DECLARE
qry nvarchar2(500);
result nvarchar2(500);

BEGIN

select 'select TEXTVAL as "CHARG" FROM TABLE1 WHERE LOC =''[ParameterValue]'' and KEYNAME =''<<REPLACE>>''' INTO qry from dual;

SELECT CASE WHEN count(RW."CountofBATCH") > 1 then 'Mixing'
WHEN count(RW."CountofMAT") = 0 then 'None'
ELSE 'Other'
END
INTO result
FROM TABLENAME2 TT, XMLTable('/Rowsets/Rowset/Row' PASSING TT.XMLCOL
COLUMNS
"CountofBATCH" PATH '/Row[CLABS > 0]/CHARG',
"CountofMAT" PATH '/Row[MATNR = "[Parameter Value]"]/MAT'
) AS RW

where
TT.PL = '[Parameter Value]' and
TT.TANK = '[Parametr Value]' ;

IF result = 'Mixing' OR result = 'None' THEN
qry := replace( qry , '<<REPLACE>> ' , result);
else
qry := 'Nothing';
END IF;

This way the variable qry will have select statement. Now How can I run this qry variable to get the output of that select statement in the same query?
This post has been answered by vansul on Nov 20 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 18 2012
Added on Nov 20 2012
1 comment
1,558 views