• <i id='KfDr3'><tr id='KfDr3'><dt id='KfDr3'><q id='KfDr3'><span id='KfDr3'><b id='KfDr3'><form id='KfDr3'><ins id='KfDr3'></ins><ul id='KfDr3'></ul><sub id='KfDr3'></sub></form><legend id='KfDr3'></legend><bdo id='KfDr3'><pre id='KfDr3'><center id='KfDr3'></center></pre></bdo></b><th id='KfDr3'></th></span></q></dt></tr></i><div id='KfDr3'><tfoot id='KfDr3'></tfoot><dl id='KfDr3'><fieldset id='KfDr3'></fieldset></dl></div>

    1. <tfoot id='KfDr3'></tfoot>
        <bdo id='KfDr3'></bdo><ul id='KfDr3'></ul>

      <small id='KfDr3'></small><noframes id='KfDr3'>

    2. <legend id='KfDr3'><style id='KfDr3'><dir id='KfDr3'><q id='KfDr3'></q></dir></style></legend>

        如何记录更改列 DDL 操作

        时间:2023-11-03
      1. <i id='WtMEh'><tr id='WtMEh'><dt id='WtMEh'><q id='WtMEh'><span id='WtMEh'><b id='WtMEh'><form id='WtMEh'><ins id='WtMEh'></ins><ul id='WtMEh'></ul><sub id='WtMEh'></sub></form><legend id='WtMEh'></legend><bdo id='WtMEh'><pre id='WtMEh'><center id='WtMEh'></center></pre></bdo></b><th id='WtMEh'></th></span></q></dt></tr></i><div id='WtMEh'><tfoot id='WtMEh'></tfoot><dl id='WtMEh'><fieldset id='WtMEh'></fieldset></dl></div>
      2. <tfoot id='WtMEh'></tfoot>
          <legend id='WtMEh'><style id='WtMEh'><dir id='WtMEh'><q id='WtMEh'></q></dir></style></legend>

              <tbody id='WtMEh'></tbody>
              <bdo id='WtMEh'></bdo><ul id='WtMEh'></ul>

              <small id='WtMEh'></small><noframes id='WtMEh'>

                  本文介绍了如何记录更改列 DDL 操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要创建一个数据库触发器,它会记录特定的每个更改(Add Column,Modify Column,Drop Column)语句表使用 Oracle 的模式触发器.如何获得?

                  I need to create a database trigger which will record each alter (Add Column,Modify Column,Drop Column) statements in a specific table using Oracle's schema trigger. How to get it ?

                  到目前为止我尝试了下面的代码:

                  I tried the code below so far :

                  TRIGGER after_ddl_creation
                      after CREATE ON SCHEMA
                  DECLARE
                      V CLOB;
                  BEGIN
                  FOR REC IN(SELECT TEXT FROM user_source WHERE  NAME=SYS.DICTIONARY_OBJ_NAME)
                   LOOP
                     V:=V||REC.TEXT;
                   END LOOP ;
                   INSERT INTO myAudit VALUES
                        (SYS.DICTIONARY_OBJ_NAME,SYS.DICTIONARY_OBJ_TYPE,SYSDATE,USER,NULL,NULL,V);
                      END;
                  

                  推荐答案

                  你可以使用这样的数据库触发器:

                  You can use such a database trigger :

                  create or replace trigger after_ddl_creation after ddl on schema
                  declare
                    v_oty          varchar2(75) := ora_dict_obj_type;
                    v_don          varchar2(75) := ora_dict_obj_name;
                    v_evt          varchar2(75) := ora_sysevent;
                    v_olu          varchar2(75) := nvl(ora_login_user,'Undefined Schema');
                    v_sql          ora_name_list_t;
                    v_stm          clob;
                    v_sct          owa.vc_arr;
                    n              pls_integer;
                    n_max          pls_integer := 10000; 
                   --> can log upto ten-thousand rows of "text" value, within "stmt" column,
                   -->         which can be accessed by using (`[user|all|dba]_source`) views.
                  begin
                        v_sct(1) := 'SESSIONID';
                        v_sct(2) := 'IP_ADDRESS';
                        v_sct(3) := 'TERMINAL';
                        v_sct(4) := 'OS_USER';
                        v_sct(5) := 'AUTHENTICATION_TYPE';
                        v_sct(6) := 'CLIENT_INFO';
                        v_sct(7) := 'MODULE';
                        for i in 1..7
                        loop
                         v_sct(i) := sys_context('USERENV',v_sct(i));
                        end loop;
                  
                        select decode(v_sct(1),0,null,v_sct(1)),
                               decode(upper(v_sct(3)),'UNKNOWN',null,v_sct(3)) 
                          into v_sct(1),v_sct(3) from dual;
                         n := ora_sql_txt( v_sql );
                        if n > n_max then
                         n := n_max;
                        end if;
                  
                        for i in 1..n
                        loop
                         v_stm := v_stm || v_sql(i);
                        end loop;
                  
                        if ( evt = 'ALTER' and oty = 'TABLE' 
                            and regexp_like(v_stm,'Add|Modify|Drop','i') ) then 
                         insert into myAudit(ts,usr,evnt,stmt,sessionid,ip,terminal,os_user,auth_type,
                                             object_type,object_name,client_info,module_info)
                         values(sysdate,v_olu,v_evt,v_stm,v_sct(1),v_sct(2),v_sct(3),v_sct(4),v_sct(5),
                                v_oty,v_don,v_sct(6),v_sct(7));
                        end if;
                  
                  end;
                  

                  由于上述 INSERT 语句而重新创建 myAudit 表.

                  by recreating myAudit table due to the above INSERT statement.

                  这篇关于如何记录更改列 DDL 操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:无效的标识符 SQL 下一篇:用于列出数据库中所有模式的 Oracle SQL 查询

                  相关文章

                    <legend id='xP7ra'><style id='xP7ra'><dir id='xP7ra'><q id='xP7ra'></q></dir></style></legend>

                    <tfoot id='xP7ra'></tfoot>
                    • <bdo id='xP7ra'></bdo><ul id='xP7ra'></ul>

                    <small id='xP7ra'></small><noframes id='xP7ra'>

                    1. <i id='xP7ra'><tr id='xP7ra'><dt id='xP7ra'><q id='xP7ra'><span id='xP7ra'><b id='xP7ra'><form id='xP7ra'><ins id='xP7ra'></ins><ul id='xP7ra'></ul><sub id='xP7ra'></sub></form><legend id='xP7ra'></legend><bdo id='xP7ra'><pre id='xP7ra'><center id='xP7ra'></center></pre></bdo></b><th id='xP7ra'></th></span></q></dt></tr></i><div id='xP7ra'><tfoot id='xP7ra'></tfoot><dl id='xP7ra'><fieldset id='xP7ra'></fieldset></dl></div>