Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 我们如何确定oracle表中的一列正在由另一个表的触发器填充/更新?_Sql_Database_Oracle_Plsql - Fatal编程技术网

Sql 我们如何确定oracle表中的一列正在由另一个表的触发器填充/更新?

Sql 我们如何确定oracle表中的一列正在由另一个表的触发器填充/更新?,sql,database,oracle,plsql,Sql,Database,Oracle,Plsql,考虑一个场景,其中有两个表a和B 表A有一个触发器Ta[在我加入这个项目之前很久就写了,因此我完全不知道这个触发器],它更新了表B中一个名为colB的列 现在,由于我主要使用表B,并且担心colB的使用方式,所以我不知道触发器Ta是否正在更新此列 所以我的问题是,有没有一种直接的oracle查询/方法来查找一个表中的列是否被另一个表上运行的任何触发器更新 提前感谢你在这方面对我的教育 问候 a、 b 但如果查询分为两行,例如: UPDATE A SET ... 因为文本与相应对象

考虑一个场景,其中有两个表a和B

表A有一个触发器Ta[在我加入这个项目之前很久就写了,因此我完全不知道这个触发器],它更新了表B中一个名为colB的列

现在,由于我主要使用表B,并且担心colB的使用方式,所以我不知道触发器Ta是否正在更新此列

所以我的问题是,有没有一种直接的oracle查询/方法来查找一个表中的列是否被另一个表上运行的任何触发器更新

提前感谢你在这方面对我的教育

问候 a、 b

但如果查询分为两行,例如:

UPDATE
    A
SET
   ...
因为文本与相应对象中的给定行匹配。

简单示例:

create table table_a(
 id number primary key,
 val varchar2( 100 )
);

create table table_b(
 len number
);

insert into table_b values ( 0 );

set define off
create or replace trigger after_table_a
after insert on table_a for each row
begin
   UpDate 
     table_B
       set len = len + length( :new.val );
end;
/

insert into table_a values ( 1, 'Ala ma kota');
insert into table_a values ( 2, 'As to ali pies');
commit;

select * from table_b;

       LEN
----------
        25 
以及查询:

select trigger_name, 
       regexp_substr( trigger_body, 'update\s+table_b',1,1,'i') update_command
from (
  select ut.trigger_name, 
         dbms_metadata.GET_DDL('TRIGGER', ut.trigger_name) trigger_body 
  from user_dependencies ud
  join user_triggers ut on ( ud.type = 'TRIGGER' 
                             and ut.trigger_name = ud.name 
                             and ut.table_name <> ud.referenced_name )
  where ud.referenced_name = 'TABLE_B'
)
where regexp_instr( trigger_body, 'update\s+table_b',1,1,0,'i') > 0 ;


TRIGGER_NAME  UPDATE_COMMAND
------------- ------------------ 
AFTER_TABLE_A UpDate
                table_B

Oracle细粒度依赖项跟踪知道使用哪些列。不幸的是,没有办法跟踪这种依赖关系是用于读还是写。并且没有默认的DBA_DEPENDENCY_COLUMNS视图来查找此信息

但幸运的是,他创造了这样一种观点。他的博客有更多的信息,包括grants和CreateView语句,大约在页面的一半

例如:

drop table a;
drop table b;

create table a(colA number);
create table b(colB number, read_only number, not_used number);

create or replace trigger Ta
after update or insert or delete on a
begin
    update b set colB = read_only;
end;
/

--What triggers are referencing B's columns?
select owner, name, type, referenced_column
from dba_dependency_columns
where referenced_owner = user
    and referenced_name = 'B'
    and type = 'TRIGGER';

OWNER    NAME  TYPE     REFERENCED_COLUMN
-----    ----  ----     -----------------
JHELLER  TA    TRIGGER  COLB
JHELLER  TA    TRIGGER  READ_ONLY

该视图使用了几个未记录的表和一些高级SQL特性。在生产服务器上,此视图不是一个好主意。但它可能比任何涉及解析SQL的解决方案都要精确得多。

是什么阻止了您查看触发器的代码并查看它是否更新了表B?查看您最喜欢的数据库工具mine is Toad中表B属性的tab使用的。从user_source中选择*,其中。。。还有regexp_liketext、'update[^[:alnum:]a'、'i',或者,看看那个特定的触发器……他说他想假设他不认识触发器。感谢大师们的帮助。感谢您:-!
drop table a;
drop table b;

create table a(colA number);
create table b(colB number, read_only number, not_used number);

create or replace trigger Ta
after update or insert or delete on a
begin
    update b set colB = read_only;
end;
/

--What triggers are referencing B's columns?
select owner, name, type, referenced_column
from dba_dependency_columns
where referenced_owner = user
    and referenced_name = 'B'
    and type = 'TRIGGER';

OWNER    NAME  TYPE     REFERENCED_COLUMN
-----    ----  ----     -----------------
JHELLER  TA    TRIGGER  COLB
JHELLER  TA    TRIGGER  READ_ONLY