oracle - Output parameter value is shown as 'invalid identifier' -
i trying retrieve values temporarily created tables. return value throws error 'invalid identifier'
create or replace procedure edu_stream (input in varchar2,vals out varchar2) inp varchar2(30); valu varchar2(30); begin inp:=input; if inp='secondary education' execute immediate'with secedu ( (select "icse" name dual ) union (select "cbse" name dual ) union (select "state board" name dual) ) select name valu from(select name secedu order dbms_random.random)where rownum<2'; vals:=valu; else if inp='intermediate education' execute immediate'with intedu ( (select "mpc" name dual ) union (select "bipc" name dual ) union (select "mbipc" name dual) union (select "cec" name dual) ) select name valu from(select name intedu order dbms_random.random)where rownum<2'; vals:=valu; else if inp='graduation' execute immediate'with gedu ( (select "ece" name dual ) union (select "cse" name dual ) union (select "ce" name dual) union (select "eee" name dual)union (select "me" name dual)union (select "ae" name dual)union (select "biotech" name dual)union (select "eie" name dual) ) select name valu from(select name gedu order dbms_random.random)where rownum<2'; vals:=valu; else if inp='post-graduation' execute immediate'with pgedu ( (select "mca" name dual ) union (select "mtech" name dual ) union (select "msc" name dual) union (select "mba" name dual) ) select name valu from(select name pgedu order dbms_random.random)where rownum<2'; vals:=valu; else if inp='phd'then execute immediate' phdedu ( (select "doctorate of philosophy" name dual ) union (select "doctorate of medicine" name dual ) union (select "doctorate of science" name dual) union (select "doctorate of computer sciences" name dual) ) select name valu from(select name phdgedu order dbms_random.random)where rownum<2'; vals:=valu; end if; end if; end if; end if; end if; end;
execution:
declare value1 varchar2(30); cv varchar2(30); begin cv:='secondary education'; edu_stream(cv,value1); dbms_output.put_line('val is'||value1); end;
error report:
error starting @ line 2 in command: declare value1 varchar2(30); cv varchar2(30); begin cv:='secondary education'; edu_stream(cv,value1); dbms_output.put_line('val is'||value1); end; error report: ora-00904: "icse": invalid identifier ora-06512: @ "datafocus_group.edu_stream", line 9 ora-06512: @ line 6 00904. 00000 - "%s: invalid identifier" *cause:
*action:
if use 'icse'instead of "icse"
error shows-
pls-00103: encountered symbol "icse" when expecting 1 of following:
error 103 * & = - + ; < / > @ in mod remainder not rem return
returning <> or != or ~= >= <= <> , or
like2 like4 likec between using || multiset bulk
member submultiset
you can avoid dynamic sql; also, due confusion created dynamic sql, using "
instead of '
. can re-write code as:
create or replace procedure edu_stream(input in varchar2, vals out varchar2) inp varchar2(30); valu varchar2(30); begin inp := input; if inp = 'secondary education' secedu ((select 'icse' name dual) union (select 'cbse' name dual) union (select 'state board' name dual)) select name valu ( select name secedu order dbms_random.random) rownum < 2; vals := valu; else if inp = 'intermediate education' intedu ((select 'mpc' name dual) union (select 'bipc' name dual) union (select 'mbipc' name dual) union (select 'cec' name dual)) select name valu ( select name intedu order dbms_random.random) rownum < 2; vals := valu; else if inp = 'graduation' gedu ((select 'ece' name dual) union (select 'cse' name dual) union (select 'ce' name dual) union (select 'eee' name dual) union (select 'me' name dual) union (select 'ae' name dual) union (select 'biotech' name dual) union (select 'eie' name dual)) select name valu ( select name gedu order dbms_random.random) rownum < 2; vals := valu; else if inp = 'post-graduation' pgedu ((select 'mca' name dual) union (select 'mtech' name dual) union (select 'msc' name dual) union (select 'mba' name dual)) select name valu ( select name pgedu order dbms_random.random) rownum < 2; vals := valu; else if inp = 'phd' phdedu ((select 'doctorate of philosophy' name dual) union (select 'doctorate of medicine' name dual) union (select 'doctorate of science' name dual) union (select 'doctorate of computer sciences' name dual)) select name valu ( select name phdgedu order dbms_random.random) rownum < 2; vals := valu; end if; end if; end if; end if; end if; end;
also, please notice variables inp
, valu
not strictly necessary: can use parameters check input value , build output parameter.
in case need use dynamic sql (not here, maybe in future) right way like:
declare number; begin execute immediate 'select 1 dual' a; end;
Comments
Post a Comment