Home » SQL & PL/SQL » SQL & PL/SQL » help with ...
help with ... [message #225513] Tue, 20 March 2007 03:36 Go to next message
progdoc
Messages: 9
Registered: January 2007
Location: Sr
Junior Member
hi all
I need help for this

I want to make some dynamic column name so I can use it in select in procedure. Table has column names like P1, P2, P3, P4...P40

and I need select like this

declare

iznos number;
sum number;
pp varchar2(3);

begin
--some code

for i in 1..31 loop
pp := 'P'||to_char(i);
begin

select pp into iznos from poent
where POEN_OBr = slog.obr And
poen_rad = slog.rad And
pri = slog.pri ;


end;
sum := sum + iznos;

end loop;
end;

instead if this doesn't work I must use

select P1,P2,P3...P40
into iznosP1,iznosP2, iznosP3... iznosP40
from poent
Re: help with ... [message #225522 is a reply to message #225513] Tue, 20 March 2007 03:58 Go to previous messageGo to next message
bonker
Messages: 402
Registered: July 2005
Senior Member

declare

iznos number;
sum number;
pp varchar2(3);
begin
--some code

for i in 1..31 loop
pp := 'P'||to_char(i);
begin

execute immediate 'select ' || pp ||' from poent
where POEN_OBr = :slogobr And
poen_rad = :slograd And
pri = :slogpri ' into iznos using slog.obr , slog.rad, slog.pri;


end;
sum := sum + iznos;

end loop;
end;






Re: help with ... [message #225529 is a reply to message #225522] Tue, 20 March 2007 04:26 Go to previous message
progdoc
Messages: 9
Registered: January 2007
Location: Sr
Junior Member
it works
thanks a lot
Previous Topic: Trigger issue
Next Topic: need some help with comparing 2 same database
Goto Forum:
  


Current Time: Fri Dec 13 06:58:00 CST 2024