功能作用:應用對應的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中的操作二:切換到【輸出】選項卡,查看結果,截圖如下:
---------------------------------------------------------------------------------------------------------------