您好,登錄后才能下訂單哦!
小編給大家分享一下dbms_metadata怎么用,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
dbms_metadata包中的get_ddl函數(shù)
1.得到一個表或索引的ddl語句
SELECT DBMS_METADATA.GET_DDL('TABLE','DEPT','SCOTT') FROM DUAL;
select dbms_metadata.get_ddl('INDEX','PK_DEPT','SCOTT') from dual;
2.得到一個用戶下的所有表,索引,存儲過程的ddl
SELECT DBMS_METADATA.GET_DDL(U.OBJECT_TYPE, u.object_name)
FROM USER_OBJECTS u
where U.OBJECT_TYPE IN ('TABLE','INDEX','PROCEDURE');
存儲過程:查看 存儲過程 的定義語句
SQL> SET LONG 9999
SQL> select dbms_metadata.get_ddl('PROCEDURE','ANALYZEDB','NEWCCS') from dual;
CREATE OR REPLACE PROCEDURE "NEWCCS"."ANALYZEDB"
IS
CURSOR get_ownertable
IS
SELECT table_name
FROM user_tables;
ownertable get_ownertable%ROWTYPE;
BEGIN
OPEN get_ownertable;
LOOP
FETCH get_ownertable
INTO ownertable;
EXIT WHEN get_ownertable%NOTFOUND;
EXECUTE IMMEDIATE 'analyze table '
|| ownertable.table_name
|| ' compute statistics for table for all indexes for all indexed columns';
END LOOP;
EXCEPTION
WHEN OTHERS
THEN
RAISE;
END;
3.得到所有表空間的ddl語句
SELECT DBMS_METADATA.GET_DDL('TABLESPACE', TS.tablespace_name)
FROM DBA_TABLESPACES TS;
4.得到所有創(chuàng)建用戶的ddl
SELECT DBMS_METADATA.GET_DDL('USER',U.username)
FROM DBA_USERS U;
================================================================================
9i 中可以利用DBMS_METADATA.GET_DDL包得到數(shù)據(jù)庫的對象的ddl腳本。如下(SQLPLUS中執(zhí)行):
a. 獲取單個的建表、視圖和建索引的語法
set pagesize 0
set long 90000
set feedback off
set echo off
spool DEPT.sql
select dbms_metadata.get_ddl('TABLE','TAB_NAME','SCOTT') from dual;
select dbms_metadata.get_ddl('VIEW','VIEW_NAME','SCOTT') from dual;
select dbms_metadata.get_ddl('INDEX','IDX_NAME','SCOTT') from dual;
spool off;
b.獲取一個SCHEMA下的所有建表、視圖和建索引的語法,以scott為例:
set pagesize 0
set long 90000
set feedback off
set echo off
spool schema.sql
connect scott/tiger;
SELECT DBMS_METADATA.GET_DDL('TABLE',u.table_name) FROM USER_TABLES u;
SELECT DBMS_METADATA.GET_DDL('VIEW',u.VIEW_name) FROM USER_VIEWS u;
SELECT DBMS_METADATA.GET_DDL('INDEX',u.index_name) FROM USER_INDEXES u;
spool off;
c. 獲取某個SCHEMA的建全部存儲過程的語法
set pagesize 0
set long 90000
set feedback off
set echo off
spool procedures.sql
select DBMS_METADATA.GET_DDL('PROCEDURE',u.object_name) from user_objects u where object_type = 'PROCEDURE';
spool off;
d. 獲取某個SCHEMA的建全部函數(shù)的語法
set pagesize 0
set long 90000
set feedback off
set echo off
spool function.sql
select DBMS_METADATA.GET_DDL('FUNCTION',u.object_name) from user_objects u where object_type = 'FUNCTION';
spool off;
看完了這篇文章,相信你對“dbms_metadata怎么用”有了一定的了解,如果想了解更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。