declare
sql_stmt varchar2(200);
BU varchar2(5);
col_name varchar2(30);
col_val varchar2(4000);
begin
------cursor
for x in (select COLUMN_NAME from user_tab_columns where TABLE_NAME=upper('ps_voucher') order by COLUMN_ID ) loop
cnt:=cnt+1;
sql_stmt:='select '''||x.COLUMN_NAME||''', to_char('|| x.COLUMN_NAME|| ') from ps_voucher where business_unit=:1 and voucher_id = :2';
--DBMS_OUTPUT.PUT_LINE('sql='||sql_stmt);
EXECUTE IMMEDIATE sql_stmt into col_name, col_val USING 'BU', 'VI'
DBMS_OUTPUT.PUT_LINE(col_name||'='||col_val);
end loop;
exception
WHEN OTHERS then
declare
errcd NUMBER := SQLCODE;
errmsg VARCHAR2(300) := SQLERRM;
begin
DBMS_OUTPUT.PUT_LINE('Error: rec#'|| cnt || ' rc='|| errcd ||','||errmsg);
end;
end;
/