PROCEDURE QUARY3(p_cursor OUT empcur,ayhaga in varchar2)is
BEGIN
OPEN p_cursor FOR
select f_no,ayhaga FROM hsabattree;
END QUARY3;
i get a constant value 'ayhaga' in all the tuples. what i need is if there is a column in hsabattree table called ahmad and a column called khaled.what i want ayhaga = 'ahmad' then ahmad column is selected.in
another query ayhaga = 'khaled' then khaled column is selected.when i tried to use : as sql at compilling the package i was promted to enter a value for ayhaga parameter.
can any one help. thanks in advance
ahmad
You cannot use varables directly in a select list; Oracle does not
perform substitutions outside of the WHERE clause. Building such
statements requires dynamic SQL, which you cannot use in the manner
you've illustrated. As an example for correctly using dynamic SQL:
declare
sqltxt varchar2(200);
ayhaga varchar2(40):='ahmad';
type ctyp is record(hsabattree.f_no%type, hsabattree.ahmad
%type);
type ccoll is table of ctyp index by binary_integer;
coll_v ccoll;
begin
sqltxt := 'select f_no,'||ayhaga||' FROM hsabattree';
execute immediate sqltxt bulk collect into coll_v;
for coll_v.first..coll_V.last loop
dbms_output.put_line(coll_v.f_no||' '||
coll_v.ahmad);
end loop;
end;
/
I know of no way to do what you posted using a dynamic cursor.
David Fitzjarrell