在一条语句中列出表和列 [英] List table and columns in one statement

查看:66
本文介绍了在一条语句中列出表和列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您将如何在oracle SQL中打印每个表的名称以及该表中的列,方法是先打印表名,然后在单独的行中打印该表中的每一列.

How would you in oracle SQL print the name of each table and the columns within that table- by printing the table name once followed by each column within that table on a separate line.

格式应该是这样的:

Table1
  columns
Table2
  Columns

推荐答案

这应该可以解决问题.

    DECLARE 
TNAME user_tables.table_name%TYPE;
CNAME user_tab_columns.column_name%TYPE;
CURSOR ct1
IS SELECT table_name from user_tables;
CURSOR ct2 IS SELECT column_name FROM user_tab_columns WHERE table_name =TNAME;
BEGIN
OPEN ct1;
LOOP
FETCH ct1 INTO TNAME;
EXIT WHEN ct1%NOTFOUND;
DBMS_OUTPUT.PUT_LINE('TABLENAME:-->'|| TRIM(TNAME));
      OPEN ct2;
      LOOP
      FETCH ct2 INTO CNAME;
      EXIT WHEN ct2%NOTFOUND;
      DBMS_OUTPUT.PUT_LINE('             '|| TRIM(CNAME));
      END LOOP;
      CLOSE CT2;
END LOOP;
CLOSE ct1;
END;    

这篇关于在一条语句中列出表和列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆