Re: Cycle thru columns in table? -
03-09-2010
, 09:35 AM
Hi,
try this:
create table kk_cdom
( first_name varchar2(30),
last_name varchar2(30),
birthday date,
children number);
insert into kk_cdom values ( 'fred', 'flintstone', sysdate-30000,
2);
insert into kk_cdom values ( 'barnie','gröllheimer', sysdate-29900,
3);
select * from kk_cdom;
declare
cursor col is
select COLUMN_NAME
from user_tab_columns
where table_name = 'KK_CDOM'
order by COLUMN_id;
inhalt varchar2(30);
--
begin
for spalte in col loop
execute immediate ( 'select to_char(' || spalte.column_name || ')
from KK_CDOM where rownum < 2' ) into inhalt;
dbms_output.put_line ( spalte.column_name || ' : ' || inhalt);
end loop;
end;
/
And that is the result:
FIRST_NAME : fred
LAST_NAME : flintstone
BIRTHDAY : 19.01.28
CHILDREN : 2
hth
Kay |