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:
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'
END INTO result
FROM TABLENAME2 TT, XMLTable('/Rowsets/Rowset/Row' PASSING TT.XMLCOL
"CountofBATCH" PATH '/Row[CLABS > 0]/CHARG',
"CountofMAT" PATH '/Row[MATNR = "[Parameter Value]"]/MAT'
) AS RW
TT.PL = '[Parameter Value]' and
TT.TANK = '[Parametr Value]' ;
IF result = 'Mixing' OR result = 'None' THEN
qry := replace( qry , '<<REPLACE>> ' , result);
qry := 'Nothing';
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?
you can use execute immediate if the output of the query is in the single query.
that is very simple.
have the query in the signle string and then pass like this
vempid number :=1;
qry:='select empname from emp where empid=:empid';
execute immediate qry into result using vempid;
-----now the data result is in result