Which Oracle table uses a sequence?

前端 未结 5 1172
夕颜
夕颜 2021-01-05 08:17

Having a sequence, I need to find out which table.column gets its values. As far as I know, Oracle doesn\'t keep track of this relationship. So, looking up for the sequence

5条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-05 08:41

    The problem is that Oracle allows us to use one sequence to populate columns in several tables. Scenarios where this might be desirable include super-type/sub-type implementations.

    You can use the dependencies in the data dictionary to identify relationships. For instance, if you use triggers to assign the values then this query will help you:

    select ut.table_name
           , ud.referenced_name as sequence_name
    from   user_dependencies ud
           join user_triggers ut on (ut.trigger_name = ud.name)
    where ud.type='TRIGGER' 
    and ud.referenced_type='SEQUENCE'
    /
    

    If you use PL/SQL then you can write something similar for TYPE in ('PACKAGE BODY', 'PROCEDURE', 'FUNCTION'), although you will still require some trawling through the source code to assign tables and sequences when you have multiple hits.

提交回复
热议问题