存储过程的运用之print_table(二)

2014-11-24 14:50:27 · 作者: · 浏览: 1
n
(l_theCursor, i, l_columnValue, 4000);
end if;
end loop;
-- execute the query, so we can fetch
l_status := dbms_sql.execute(l_theCursor);
-- loop and print out each column on a separate line
-- bear in mind that dbms_output only prints 255 characters/line
-- so we'll only see the first 200 characters by my design...
while ( dbms_sql.fetch_rows(l_theCursor) > 0 )
loop
for i in 1 .. l_colCnt loop
if ( l_descTbl(i).col_type not in ( 113 ) )
then
dbms_sql.column_value
( l_theCursor, i, l_columnValue );
dbms_output.put_line
( rpad( l_descTbl(i).col_name, 30 )
|| ': ' ||
substr( l_columnValue, 1, 200 ) );
end if;
end loop;
dbms_output.put_line( '-----------------' );
end loop;
-- now, restore the session state, no matter what
restore;
exception
when others then
restore;
raise;
end;
www.2cto.com
[sql]
SQL> set serverout on size 100000
SQL> select * from a;
ID COL
------ -----
1 AA
2 bb
3 cc
SQL> exec print_table('select * from a');
ID : 1
COL : AA
-----------------
ID : 2
COL : bb
-----------------
ID : 3
COL : cc
-----------------
PL/SQL procedure successfully completed