對於大多數情況,您可以使用通過user_dependencies進行連接。
確定依賴
樣品,其適用於自PUBLIC任何Oracle用戶已被授予選擇訪問對user_dependencies:
select name
, type
, prior name
, prior type
from user_dependencies
start
with name='BUBS#MUNT_EENHEDEN'
and type='PACKAGE'
connect
by nocycle
name = prior referenced_name
and type = prior referenced_type
樣本輸出
Level 1: BUBS#MUNT_EENHEDEN PACKAGE
Level 2: BUBS_MUNT_EENHEDEN_V VIEW BUBS#MUNT_EENHEDEN PACKAGE
Level 3: BUBS#VERTALINGEN PACKAGE BUBS_MUNT_EENHEDEN_V VIEW
Level 4: ITGEN_LANGUAGES_V VIEW BUBS#VERTALINGEN PACKAGE
複雜的場景
對於複雜的情況下,我發現它是必要的直接在數據字典上使用自己的視圖。只有當你知道你在做什麼以及你想支持的RDBMS版本時才這樣做!例如,數據模型版本引入了數據字典中的重大更改。
樣品:
create or replace force view itgen_object_tree_changes_r
as
select o_master.obj# ojt#
, o_master.name ojt_name
, o.mtime ojt_ref_mtime
, o.name ojt_ref_name
, o.owner# ojt_ref_owner#
, decode
(o.type#
, 0, 'NEXT OBJECT'
, 1, 'INDEX'
, 2, 'TABLE'
, 3, 'CLUSTER'
, 4, 'VIEW'
, 5, 'SYNONYM'
, 6, 'SEQUENCE'
, 7, 'PROCEDURE'
, 8, 'FUNCTION'
, 9, 'PACKAGE'
, 11, 'PACKAGE BODY'
, 12, 'TRIGGER'
, 13, 'TYPE'
, 14, 'TYPE BODY'
, 19, 'TABLE PARTITION'
, 20, 'INDEX PARTITION'
, 21, 'LOB'
, 22, 'LIBRARY'
, 23, 'DIRECTORY'
, 24, 'QUEUE'
, 28, 'JAVA SOURCE'
, 29, 'JAVA CLASS'
, 30, 'JAVA RESOURCE'
, 32, 'INDEXTYPE'
, 33, 'OPERATOR'
, 34, 'TABLE SUBPARTITION'
, 35, 'INDEX SUBPARTITION'
, 40, 'LOB PARTITION'
, 41, 'LOB SUBPARTITION'
, 42, nvl
((select 'REWRITE EQUIVALENCE'
from sys.sum$ s
where s.obj# = o.obj#
and bitand (s.xpflags, 8388608) = 8388608), 'MATERIALIZED VIEW'
)
, 43, 'DIMENSION'
, 44, 'CONTEXT'
, 46, 'RULE SET'
, 47, 'RESOURCE PLAN'
, 48, 'CONSUMER GROUP'
, 51, 'SUBSCRIPTION'
, 52, 'LOCATION'
, 55, 'XML SCHEMA'
, 56, 'JAVA DATA'
, 57, 'EDITION'
, 59, 'RULE'
, 60, 'CAPTURE'
, 61, 'APPLY'
, 62, 'EVALUATION CONTEXT'
, 66, 'JOB'
, 67, 'PROGRAM'
, 68, 'JOB CLASS'
, 69, 'WINDOW'
, 72, 'WINDOW GROUP'
, 74, 'SCHEDULE'
, 79, 'CHAIN'
, 81, 'FILE GROUP'
, 82, 'MINING MODEL'
, 87, 'ASSEMBLY'
, 90, 'CREDENTIAL'
, 92, 'CUBE DIMENSION'
, 93, 'CUBE'
, 94, 'MEASURE FOLDER'
, 95, 'CUBE BUILD PROCESS'
, 'UNDEFINED'
)
ojt_ref_type
from sys.obj$ o
, (/* All dependencies from the object if there are any. */
select distinct connect_by_root d_obj# obj#, dep.p_obj# obj_ref#
from sys.dependency$ dep
connect
by nocycle dep.d_obj# = prior dep.p_obj#
start
with dep.d_obj# in (select obj.obj# from itgen_schemas_r sma, sys.obj$ obj where obj.owner# = sma.owner#)
union all /* Union all allowed, 'in' ignores duplicates. */
/* The object itself. */
select obj.obj#
, obj.obj#
from itgen_schemas_r sma
, sys.obj$ obj
where obj.owner# = sma.owner#
) deps
, sys.obj$ o_master
where o_master.obj# = deps.obj#
and o.obj# = deps.obj_ref#
--
-- View: itgen_object_tree_changes_r
--
-- Overview of dependencies between a master object and all objects used by it. It can be used to analyze the reason why a project version views must be recalculated.
--
-- Code (alias): ote_r
--
-- Category: Hardcoded.
--
-- Example:
--
-- The object 'X' is invalid, since 'Y' is invalid.
--
'user_dependencies'將給只有第一層的依賴。我們不能得到多層次的依賴關係.. !! @Guido – ethan
@dastan這是正確的。使用連接可以循環使用。看樣品。請注意,在舊的Oracle版本中,您需要將user_dependencies作爲視圖進行內聯,以允許連接工作。 –
hi @dastan這是否有助於解決您的問題?如果沒有,請添加什麼不成功的問題。當答案對您有幫助時,您是否可以通過點擊旁邊的空心綠色複選標記來接受它? –