Oracle 脚本:列出指定表的所有字段


晚上时,师弟yy说他有一个表,里面有90多个字段,需要把所有字段都列出来,如果手动一个一个复制出来的话,太麻烦了,就写了个小脚本.

  1. /*  
  2.  列出指定表的所有字段, 使用时将 SYS_TABLE 换成具体表名即可  
  3. */  
  4. declare  
  5.   cursor c is   
  6.   select a.COLUMN_NAME||' ' from user_tab_columns a  
  7.   where a.TABLE_NAME = 'SYS_TABLE';  
  8.     
  9.   col user_tab_columns.COLUMN_NAME%type;  
  10.   cols varchar2(4000);  
  11. begin  
  12.   open c;  
  13.   loop  
  14.     fetch c into col;  
  15.     exit when c%notfound;  
  16.     cols := cols || col;  
  17.   end loop;  
  18.   close c;  
  19.     
  20.   dbms_output.put_line(cols);  
  21. end;  

思考: 能不能使用一条 SQL 就将结果查出来?

相关内容