zoukankan      html  css  js  c++  java
  • Oracle使用游标查询所有数据表备注

    功能作用:应用对应的SQL语句,能方便快速的查询Oracle数据库指定用户的所有用户表说明,快速知道每个数据表是做什么的,方便写文档和方案。

    运行环境:搭建好Oracle数据库,并使用PQ/SQL Developer软件和指定的数据库账号密码连接上您要查询的数据库。

    详细内容如下:

    1、使用到的SQL查询脚本如下:

    ---------------------------------------------------------------------------------------------------------------
    --Oracle使用游标查询所有数据表备注

    declare 
    mytablename NVARCHAR2(200):=''; --定义要查询的数据表名称变量 
    mytablecomment NVARCHAR2(200):=''; --定义要查询的数据表注释变量 
    commentsql VARCHAR2(2000):=''; --定义要输出的注释结果变量  
    cursor mycursor1 is select * from user_tab_comments  order by table_name;--定义游标  
          
    myrecord1 mycursor1%rowtype;  --定义游标记录类型   


    begin   
    open mycursor1;  --打开游标   
    if mycursor1%isopen  then  --判断打开成功   
    loop --循环获取记录集     
      fetch mycursor1 into myrecord1;
      
      if mycursor1%found then  --游标的found属性判断是否有记录  
      begin
      
        mytablename:=myrecord1.table_name;
        mytablecomment:=myrecord1.comments;
        
        --commentsql:='表名为    '||mytablename||'    注释为    '||mytablecomment;
        commentsql:=mytablename||'    '||mytablecomment;
        dbms_output.put_line(commentsql);     
        
      end;
       
      else
      exit; --获取游标中的记录      
      
      end if;


    end loop;   
    else     
    dbms_output.put_line('游标没有打开');   
    end if; 


    close mycursor1;

    end;

    ---------------------------------------------------------------------------------------------------------------

    2、PL/SQL Developer中的操作一:复制上面的查询脚本到【SQL】选项卡,并执行查询,截图如下:

    3、PL/SQL Developer中的操作二:切换到【输出】选项卡,查看结果,截图如下:牛肉板面

  • 相关阅读:
    Asp.Net MVC 2 RC 2 发布
    SqlServer2008修改表时出现“save changes is not permitted…”解决方法
    使用LoadRunner测试WMS
    使用Expression Encoder 3发布媒体文件到WebDAV
    Net Remoting Error:试图创建未绑定类型的代理
    Net4.0VS2010新特性
    WCF的一些基本知识点
    WCF中的ServiceHost初始化两种方式
    WMS中添加默认发布点
    HTTP 错误 500.19 Internal Server Error 错误解决方法
  • 原文地址:https://www.cnblogs.com/xxr1/p/7670743.html
Copyright © 2011-2022 走看看