在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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【物件導向依賴關係概念總結】物件導向程式設計的五種依賴關係物件程式設計
- 詳解.NET依賴注入中物件的建立與“銷燬”依賴注入物件
- JavaScript 複習之 Object物件的相關方法JavaScriptObject物件
- 12、Oracle中的其它資料庫物件Oracle資料庫物件
- 使用selenium定位獲取標籤物件並提取資料物件
- 在spring中獲取代理物件代理的目標物件工具類Spring物件
- 物件導向相關物件
- Java 中建立子類物件會建立父類物件麼?Java物件
- 物件及函式相關物件函式
- docker 刪除依賴的父映象的命令Docker
- .netcore ioc 迴圈依賴問題及其相關思考之DispatchProxyNetCore
- 解讀數倉中的資料物件及相關關係物件
- 鏈式-父類中返回子類物件物件
- composer依賴相關的問題和解決辦法
- HttpServletRespnse 物件 相關基本應用HTTPServlet物件
- 使用IDEA模組之間依賴找不到依賴類Idea
- 物體物件在螢幕中的座標及滑鼠座標物件
- openGauss libpq使用依賴的標頭檔案
- 物件導向程式設計程式碼詳解(依賴關係,關聯關係,組合關係)物件程式設計
- Unity通過子物件獲取父物件例子Unity物件
- PHP 設計模式答疑-物件池與依賴注入的區別PHP設計模式物件依賴注入
- 面象物件設計6大原則之五:依賴倒置原則物件
- Swift在擴充套件中關聯物件Swift套件物件
- 關於CSS中的定位使用子絕父相(子類絕對位置和父類相對位置)CSS
- 殺會話之查詢鎖表的物件及相關操作會話物件
- WPF 之 依賴屬性與附加屬性(五)
- flask-sqlalchemy中使用cursor遊標FlaskSQL
- MySQL的多層SP中Cursor的m_max_cursor_index相關BUG分析MySqlIndex
- 理解Python中的類物件、例項物件、屬性、方法Python物件
- Android -Gradle依賴匯入及相關知識AndroidGradle
- Python深入分享之物件的屬性Python物件
- 關於一些php面試之物件導向的相關知識PHP面試物件
- 【CURSOR】Oracle 遊標 (cursor)知識梳理Oracle
- 物件儲存服務中物件業務的非標介面物件
- 前端筆記之JavaScript物件導向(二)內建建構函式&相關方法|屬性|運算子&繼承&物件導向前端筆記JavaScript物件函式繼承
- 使用Gradle檢視Android專案中庫的依賴關係GradleAndroid
- 瀏覽器中的JavaScript核心BOM(瀏覽器物件模型)重點掌握物件之Location物件的屬性與方法瀏覽器JavaScript物件模型
- 關於Golang中的依賴注入實現Golang依賴注入
- 120 C++中的物件指標C++物件指標