PL / SQL过程,用于将table_name中的列数生成为CSV文件

时间:2012-08-23 17:00:18

标签: oracle plsql

select table_name,count(column_name) from all_tab_columns where owner ='HR'  

此查询检索结果,但我想要计算列数 在使用PL / SQL过程的表中,该输出应该进入CSV文件。

1 个答案:

答案 0 :(得分:0)

here

的帮助下创建CSV版本1(不使用PL / SQL,但仍会创建CSV文件)
set colsep ,     
set pagesize 0   
set trimspool on 
set headsep off  
set linesize 100   
set numw 10      

spool myfile.csv

select table_name,count(column_name) as cnt 
from all_tab_columns where owner ='HR' 
group by table_name);

版本2,带有一点PL / SQL

set serveroutput on
begin
  for  c in (select table_name,count(column_name) as cnt 
             from all_tab_columns where owner ='HR' group by table_name)  
  loop
    dbms_output.put_line(c.table_name||';'||c.cnt);
  end loop;
end;
/

如果您想要文件服务器端,版本3将使用utl_file包但我现在假设您在SQLplus或SQLdeveloper中运行它。