help with ... [message #225513] |
Tue, 20 March 2007 03:36 |
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 |
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;
|
|
|
|