Which Oracle table uses a sequence?

前端 未结 5 1173
夕颜
夕颜 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:21

    In the database you can search all stored code in your schema like this:

    select type, name, line, text
    from all_source
    where owner = 'MYSCHEMA'
    and upper(text) like '%MYSEQ.NEXTVAL%';
    

    In SQL Developer, there is a report to do this.

    0 讨论(0)
  • 2021-01-05 08:37

    Use GREP to scan your entire source for "myseq.NextVal" - myseq being the one you're looking for....

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-05 08:42

    I'd like to add background information on sequences.

    0 讨论(0)
  • 2021-01-05 08:46

    If your sequence is used in a trigger, the trigger will be listed in the sequence's "referenced by" list.

    If your sequence is only used in the source-code queries, than yes, browsing the code is the only way.

    0 讨论(0)
提交回复
热议问题