在cursor遊標中使用dbms_metadata.get_ddl提取依賴其它物件的父物件之相關性
--驗證依賴其它物件的父物件,如其子物件未用dbms_metadata.get_ddl複製到目標庫,會否在遊標開啟範圍內導致後續的源庫物件不能繼續複製到目標庫
如object_name還要引用其它的物件
--select dbms_metadata.get_ddl(v_object_type,v_tname,'E_CHANNEL') into v_text from dual;
--1,在scott使用者構建要複製的儲存過程(此使用者為源庫),且此儲存過程要引用測試表
--先建立測試表
create table t_oy(a int);
--建立引用上述表的儲存過程
create or replace procedure proc_oy
as
v_cnt pls_integer;
begin
select a into v_cnt from t_oy;
end;
--建立另一個儲存過程
create or replace procedure proc_non
as
begin
null;
end;
--2,在tbl_bck的儲存過程如下:
create or replace procedure proc_dep
as
cursor cur_test is select object_name,object_type,owner from dba_objects where object_name in ('PROC_OY','PROC_NON');
v_object_type dba_objects.object_type%type;
v_object_name dba_objects.object_name%type;
v_owner dba_objects.object_name%type;
v_text clob;
begin
open cur_test;
loop
fetch cur_test into v_object_name,v_object_type,v_owner;
exit when cur_test%notfound;
dbms_metadata.set_transform_param( dbms_metadata.SESSION_TRANSFORM,'TABLESPACE',false);
select dbms_metadata.get_ddl(v_object_type,v_object_name,v_owner) into v_text from dual;
v_text:=replace(v_text,v_owner,'tbl_bck');
execute immediate v_text;
end loop;
close cur_test;
end;
--儲存過程編譯正常,但執行報使用者不存在,經分析,是dbms_metadata.get_ddl的引數schema值必須是大寫,真是鬼鬼
SQL> create or replace procedure proc_dep
2 authid current_user is
3 cursor cur_test is select object_name,object_type,owner from dba_objects where wner='SCOTT' and object_name in ('PROC_OY','PROC_NON');
4 v_object_type dba_objects.object_type%type;
5 v_object_name dba_objects.object_name%type;
6 v_owner dba_objects.object_name%type;
7 v_text clob;
8 begin
9 open cur_test;
10 loop
11 fetch cur_test into v_object_name,v_object_type,v_owner;
12 exit when cur_test%notfound;
13 dbms_metadata.set_transform_param( dbms_metadata.SESSION_TRANSFORM,'TABLESPACE',false);
14 select dbms_metadata.get_ddl(v_object_type,v_object_name,v_owner) into v_text from dual;
15 v_text:=replace(v_text,v_owner,'tbl_bck');
16 execute immediate v_text;
17 end loop;
18 close cur_test;
19 end;
20 /
Procedure created
SQL> exec proc_dep;
begin proc_dep; end;
ORA-01435: user does not exist
ORA-06512: at "TBL_BCK.PROC_DEP", line 16
ORA-06512: at line 2
---經修正後執行正常,但仍報錯,不過是另一個錯誤了。
SQL> create or replace procedure proc_dep
2 authid current_user is
3 cursor cur_test is select object_name,object_type,owner from dba_objects where wner='SCOTT' and object_name in ('PROC_OY','PROC_NON');
4 v_object_type dba_objects.object_type%type;
5 v_object_name dba_objects.object_name%type;
6 v_owner dba_objects.object_name%type;
7 v_text clob;
8 begin
9 open cur_test;
10 loop
11 fetch cur_test into v_object_name,v_object_type,v_owner;
12 exit when cur_test%notfound;
13 dbms_metadata.set_transform_param( dbms_metadata.SESSION_TRANSFORM,'TABLESPACE',false);
14 select dbms_metadata.get_ddl(v_object_type,v_object_name,v_owner) into v_text from dual;
15 v_text:=replace(v_text,v_owner,'TBL_BCK');
16 execute immediate v_text;
17 end loop;
18 close cur_test;
19 end;
20 /
Procedure created
SQL> exec proc_dep;
Warning: PL/SQL procedure successfully completed with compilation errors
SQL> show err
No errors
SQL> select * from tab;
TNAME TABTYPE CLUSTERID
------------------------------ ------- ----------
--注意:依賴表的儲存過程proc_oy狀態為invalid
SQL> select * from user_objects;
OBJECT_NAME SUBOBJECT_NAME OBJECT_ID DATA_OBJECT_ID OBJECT_TYPE CREATED LAST_DDL_TIME TIMESTAMP STATUS TEMPORARY GENERATED SECONDARY NAMESPACE EDITION_NAME
-------------------------------------------------------------------------------- ------------------------------ ---------- -------------- ------------------- ----------- ------------- ------------------- ------- --------- --------- --------- ---------- ------------------------------
PROC_OY 68402 PROCEDURE 2013/2/28 2 2013/2/28 21: 2013-02-28:21:41:41 INVALID N N N 1
PROC_NON 68401 PROCEDURE 2013/2/28 2 2013/2/28 21: 2013-02-28:21:41:41 VALID N N N 1
PROC_DEP 68400 PROCEDURE 2013/2/28 2 2013/2/28 21: 2013-02-28:21:41:36 VALID N N N 1
--為了先執行依賴表的儲存過程,修正了儲存過程,新增了order by
SQL> create or replace procedure proc_dep
2 authid current_user is
3 cursor cur_test is select object_name,object_type,owner from dba_objects where wner='SCOTT' and object_name in ('PROC_OY','PROC_NON') order by object_name desc;
4 v_object_type dba_objects.object_type%type;
5 v_object_name dba_objects.object_name%type;
6 v_owner dba_objects.object_name%type;
7 v_text clob;
8 begin
9 open cur_test;
10 loop
11 fetch cur_test into v_object_name,v_object_type,v_owner;
12 exit when cur_test%notfound;
13 dbms_metadata.set_transform_param( dbms_metadata.SESSION_TRANSFORM,'TABLESPACE',false);
14 select dbms_metadata.get_ddl(v_object_type,v_object_name,v_owner) into v_text from dual;
15 v_text:=replace(v_text,v_owner,'TBL_BCK');
16 execute immediate v_text;
17 end loop;
18 close cur_test;
19 end;
20 /
Procedure created
--再次執行,依舊報上述的錯誤
SQL> exec proc_dep;
Warning: PL/SQL procedure successfully completed with compilation errors
--查詢2個物件,因proc_oy儲存過程依賴於表t_oy,但此表未複製過來,故狀態為invalid,導致後續的儲存過程proc_non也未複製過來
SQL> select * from user_objects;
OBJECT_NAME SUBOBJECT_NAME OBJECT_ID DATA_OBJECT_ID OBJECT_TYPE CREATED LAST_DDL_TIME TIMESTAMP STATUS TEMPORARY GENERATED SECONDARY NAMESPACE EDITION_NAME
-------------------------------------------------------------------------------- ------------------------------ ---------- -------------- ------------------- ----------- ------------- ------------------- ------- --------- --------- --------- ---------- ------------------------------
PROC_OY 68402 PROCEDURE 2013/2/28 2 2013/2/28 21: 2013-02-28:21:48:15 INVALID N N N 1
PROC_DEP 68400 PROCEDURE 2013/2/28 2 2013/2/28 21: 2013-02-28:21:47:29 VALID N N N 1
小結:
1,invalid狀態的物件,開啟遊標時,在應用dbms_metadata.get_ddl會導致後續的物件不能繼續複製
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/9240380/viewspace-754996/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 在SQL Server 2008中物件相關性的使用SQLServer物件
- 【物件導向依賴關係概念總結】物件導向程式設計的五種依賴關係物件程式設計
- SpringIOC容器-物件依賴Spring物件
- js,javascript陣列物件的父級物件 – 子集物件(陣列物件相減)JSJavaScript陣列物件
- 詳解.NET依賴注入中物件的建立與“銷燬”依賴注入物件
- Oracle中查詢依賴的無效物件(invalid object)Oracle物件Object
- Oracle使用cursor for隱式遊標Oracle
- 通過DBMS_METADATA.GET_DDL包獲得相關物件ddl語句物件
- SQL 遊標cursorSQL
- JavaScript 複習之 Object物件的相關方法JavaScriptObject物件
- 12、Oracle中的其它資料庫物件Oracle資料庫物件
- flask-sqlalchemy中使用cursor遊標FlaskSQL
- v$sql v$sqlarea v$sql_shared_cursor及父遊標,子游標SQL
- 物件導向~如何解除具體依賴物件
- 從檢視看Oracle物件依賴機制Oracle物件
- 物件導向相關物件
- Java 中建立子類物件會建立父類物件麼?Java物件
- 【CURSOR】Oracle 遊標 (cursor)知識梳理Oracle
- 在spring中獲取代理物件代理的目標物件工具類Spring物件
- oracle串物件相關的bugOracle物件
- docker 刪除依賴的父映象的命令Docker
- 使用selenium定位獲取標籤物件並提取資料物件
- 使用 tpl 標籤和 for 讀取物件屬性值中的陣列物件陣列
- SQL 遊標cursor的運用SQL
- winform之滑鼠進入及停留相關事件及游標cursorORM事件
- 物件及函式相關物件函式
- 使用IDEA模組之間依賴找不到依賴類Idea
- PL/SQL 04 遊標 cursorSQL
- OSGI中的service依賴關係管理
- 2 Day DBA-管理方案物件-關於方案物件管理許可權-管理其它方案物件物件
- 解讀數倉中的資料物件及相關關係物件
- 使用DBMS_METADATA.GET_DDL獲取物件的DDL指令碼物件指令碼
- WPF 之 依賴屬性與附加屬性(五)
- 關於值物件中不解之處物件
- 依賴屬性之“風雲再起”薦
- 鏈式-父類中返回子類物件物件
- 關於aud$物件相關處理物件
- 物體物件在螢幕中的座標及滑鼠座標物件