Recover DDL of altered trigger

Hello everybody,
I've accidentally replaced an existing trigger without taking the back-up of older one on oracle 10g.
Now I wonder if I can get the DDL of older trigger back.
thanks,
Rossy.Rocs

I just tried your test case but its worked!
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - Prod
PL/SQL Release 10.2.0.2.0 - Production
CORE    10.2.0.2.0      Production
TNS for 32-bit Windows: Version 10.2.0.2.0 - Production
NLSRTL Version 10.2.0.2.0 - Production
SQL>
SQL> conn nishant/nis
Connected.
SQL> CREATE TABLE orders (
  2  somecolumn VARCHAR2(20),
  3  numbercol  NUMBER(10),
  4  datecol    DATE);
Table created.
SQL> CREATE OR REPLACE TRIGGER statement_level
  2  BEFORE UPDATE
  3  ON orders
  4  DECLARE
  5  vMsg VARCHAR2(30) := 'Statement Level Trigge
  6  BEGIN
  7  dbms_output.put_line(vMsg);
  8  END statement_level;
  9  /
Trigger created.
SQL> set time on
10:10:32 SQL> CREATE OR REPLACE TRIGGER statement_level
10:10:37   2  BEFORE UPDATE
10:10:37   3  ON orders
10:10:37   4  DECLARE
10:10:37   5  vMsg VARCHAR2(30) := 'Statement Level Trigger Fired';
10:10:37   6  BEGIN
10:10:37   7  dbms_output.put_line(vMsg);
10:10:37   8  dbms_output.put_line('A line added');  <--- just made one change here
10:10:37   9  END statement_level;
10:10:37  10  /
Trigger created.
SQL> set time on
10:12:19 SQL> CONN / AS SYSDBA
10:14:06 SQL> SELECT TEXT FROM DBA_SOURCE WHERE NAME='STATEMENT_LEVEL';
TEXT
TRIGGER statement_level
BEFORE UPDATE
ON orders
DECLARE
vMsg VARCHAR2(30) := 'Statement Level Trigger Fired';
BEGIN
dbms_output.put_line(vMsg);
dbms_output.put_line('A line added');
END statement_level;
9 rows selected.
10:14:41 SQL>
10:15:36 SQL> SELECT TEXT FROM DBA_SOURCE as of timestamp to_timestamp('19-jan-2
010 10:09','dd-mon-yyyy hh24:mi')  WHERE NAME='STATEMENT_LEVEL';
TEXT
TRIGGER statement_level
BEFORE UPDATE
ON orders
DECLARE
vMsg VARCHAR2(30) := 'Statement Level Trigger Fired';
BEGIN
dbms_output.put_line(vMsg);  
END statement_level;
8 rows selected.
10:18:47 SQL> drop trigger nishant.statement_level;
Trigger dropped.
10:19:03 SQL> SELECT TEXT FROM DBA_SOURCE as of timestamp to_timestamp('19-jan-2
010 10:10','dd-mon-yyyy hh24:mi')  WHERE NAME='STATEMENT_LEVEL';
TEXT
TRIGGER statement_level
BEFORE UPDATE
ON orders
DECLARE
vMsg VARCHAR2(30) := 'Statement Level Trigger Fired';
BEGIN
dbms_output.put_line(vMsg);
END statement_level;
8 rows selected.
10:19:12 SQL> SELECT TEXT FROM DBA_SOURCE as of timestamp to_timestamp('19-jan-2
010 10:11','dd-mon-yyyy hh24:mi')  WHERE NAME='STATEMENT_LEVEL';
TEXT
TRIGGER statement_level
BEFORE UPDATE
ON orders
DECLARE
vMsg VARCHAR2(30) := 'Statement Level Trigger Fired';
BEGIN
dbms_output.put_line(vMsg);
dbms_output.put_line('A line added');
END statement_level;
9 rows selected.
10:19:23 SQL>Thanks
Nishant

Similar Messages

  • ALTER TRIGGER PRIVILIGE

    Hi All,
    I have triggers creating in one schema. I want to edit the triggers now and recompile them, but when I do this, it prompts to me INSUFFICIENT PRIVILEGES. I am able to edit and recompile the packages, procedures and function but not the triggers. How can I check whether I have the privilege to alter the trigger or not to the same schema. And if no privilege is there, then please let me know what is the command to give the PRIVILEGE for ALTER TRIGGER.
    Thanks in advance

    Check your system privileges with:
    select * from session_privs;See ALTER TRIGGER in SQL Reference http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_4001.htm#SQLRF01101:
    >
    The trigger must be in your own schema or you must have ALTER ANY TRIGGER system privilege.
    In addition, to alter a trigger on DATABASE, you must have the ADMINISTER database events system privilege.
    >
    Trigger schema owner or DBA like account must run:
    grant alter any trigger to <your account>;Edited by: P. Forstmann on 22 nov. 2010 13:40

  • ALTER TRIGGER

    Dear Sir,
    When I execute Alter Trigger MyDB.Trigger_XXX,
    I get the following error:
    ORA-00604: error occurred at recursive SQL level 1
    ORA-10405:fetched column value is NULL
    MyDB.Trigger_XXX is pasted bellow:
    DECLARE hash_id_count integer;
    hash_id_num NUMBER(38);
    BEGIN
    . .IF DBMS_REPUTIL.FROM_REMOTE = FALSE THEN
    . .. .IF :new.REASON_CODE != 6 THEN
    . .. .. .SELECT HASH_ID INTO hash_id_num
    . .. .. .. .FROM DNAME_REUSE_TBL
    . .. .. .. .WHERE
    . .. .. .. .. .CERT_SERIAL_NUM = :new.CERT_SERIAL_NUM AND
    . .. .. .. .. .CA_DN_ID = :new.CA_DN_ID;
    . .. .. .DELETE
    . .. .. .. .FROM DNAME_REUSE_TBL
    . .. .. .. .WHERE
    . .. .. .. .. .CERT_SERIAL_NUM = :new.CERT_SERIAL_NUM AND
    . .. .. .. .. .CA_DN_ID = :new.CA_DN_ID;
    . .. .. .SELECT COUNT(HASH_ID) INTO hash_id_count
    . .. .. .. .FROM DNAME_REUSE_TBL
    . .. .. .. .WHERE HASH_ID = hash_id_num;
    . .. .. .IF hash_id_count = 0 THEN
    . .. .. .. .DELETE
    . .. .. .. .. .FROM UNIQUE_DNAME_CHECK_TBL
    . .. .. .. .. .WHERE DNAME_HASH_ID = hash_id_num;
    . .. .. .END IF;
    . .. .END IF;
    . .END IF;
    END;
    Many Thanks
    Xueliang
    Message was edited by:
    Xueliang

    Hi,
    >>When I execute Alter Trigger MyDB.Trigger_XXX,
    Clarify, alter trigger ... compile ??
    Did you try put on your SQL select "where" clause "AND HASH_ID IS NOT NULL" ?
    Cheers

  • Diff btw "recover datafile file#" & "alter database recover datafile file#"

    What is the difference between
    "recover datafile file#"
    "alter database recover datafile file#"
    Thanks
    Naveen

    I don't mean to be rude, but the statement that "There is no difference in both the commands" is facile in the extreme. Sounds like more off-the-cuff instant advice than the considered thoughts of someone who's actually bothered to try both commands out.
    The "alter database recover..." command is a disaster waiting to happen and should never be used by anyone who actually wants to achieve a successful database recovery. It has the effect of suppressing most of the interactive dialogue you get when you submit the shorter "recover..." command, and indeed causes spurious errors to be displayed because the non-interactive recovery process gets it wrong.
    For example, here's me recovering my database using the "alter database" syntax:
    SQL> alter database open;
    alter database open
    ERROR at line 1:
    ORA-01157: cannot identify/lock data file 4 - see DBWR trace file
    ORA-01110: data file 4: 'C:\ORACLE\PRODUCT\10.2.0\ORADATA\WIN10\USERS01.DBF'
    SQL> alter database recover datafile 4;
    alter database recover datafile 4
    ERROR at line 1:
    ORA-00279: change 642359 generated at 07/04/2008 09:03:18 needed for thread 1
    ORA-00289: suggestion :
    C:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\WIN10\ARCHIVELOG\2008_07_04\O1_MF_1_9_%U_.ARC
    ORA-00280: change 642359 for thread 1 is in sequence #9Note the slightly alarming report of an 'error at line 1'. What's difficult to convey in mere text, however, is that at the end of that output, the thing just sits there, and you've no idea what on Earth is happening on the database. The text tells you it's making a suggestion, but there's no indication of how you accept the suggestion, of what's happening when you do accept it or where anything is up to.
    I've interrupted one of those once (fortunately only in a training room) and lost the entire database as a result (because a half-complete, interrupted recovery is worse than no recovery at all).
    Compare that with the plain "recover..." syntax example:
    SQL> recover datafile 4;
    ORA-00279: change 642359 generated at 07/04/2008 09:03:18 needed for thread 1
    ORA-00289: suggestion :
    C:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\WIN10\ARCHIVELOG\2008_07_04\O1_MF_1_9_%U_.ARC
    ORA-00280: change 642359 for thread 1 is in sequence #9
    Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
    ORA-00279: change 642571 generated at 07/04/2008 09:06:26 needed for thread 1
    ORA-00289: suggestion :
    C:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\WIN10\ARCHIVELOG\2008_07_04\O1_MF_1_10_%U_.ARC
    ORA-00280: change 642571 for thread 1 is in sequence #10
    ORA-00278: log file
    'C:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\WIN10\ARCHIVELOG\2008_07_04\O1_MF_1_9_46TPVL2G_.ARC' no longer needed for this recovery
    Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
    ORA-00279: change 642576 generated at 07/04/2008 09:06:32 needed for thread 1
    ORA-00289: suggestion :
    C:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\WIN10\ARCHIVELOG\2008_07_04\O1_MF_1_12_%U_.ARC
    ORA-00280: change 642576 for thread 1 is in sequence #12
    ORA-00278: log file
    'C:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\WIN10\ARCHIVELOG\2008_07_04\O1_MF_1_11_46TPVRMK_.ARC' no longer needed for this recovery
    Specify log: {<RET>=suggested | filename | AUTO | CANCEL}
    Log applied.
    Media recovery complete.There are no weird error messages reported here. The suggestion is accompanied by a prompt that tells you how to accept it. Every time a new log is required, a new prompt is given. You can cleanly cancel at any time by typing 'cancel'. You are kept informed throughout and are in charge throughout.
    Anyone that uses "alter database" syntax during a recovery is, therefore, either brave or foolhardy. In either case, there is a very profound difference between the two.
    Your parting shot that 'alter database' is a SQL command and 'recover' can be an RMAN command misses the point by a wide mile, too. RMAN can issue pretty much any piece of SQL you like, so long as you wrap it in the SQL command:
    RMAN> sql 'alter database recover datafile 4';
    using target database control file instead of recovery catalog
    sql statement: alter database recover datafile 4
    RMAN-00571: ===========================================================
    RMAN-00569: =============== ERROR MESSAGE STACK FOLLOWS ===============
    RMAN-00571: ===========================================================
    RMAN-03009: failure of sql command on default channel at 07/04/2008 09:23:16
    ORA-00279: change  generated at  needed for thread
    RMAN-11003: failure during parse/execution of SQL statement: alter database recover datafile 4
    ORA-00279: change 642359 generated at 07/04/2008 09:03:18 needed for thread 1
    ORA-00289: suggestion : C:\ORACLE\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\WIN10\ARCHIVELOG\2008_07_04\O1_MF_1_9_%U_.ARC
    ORA-00280: change 642359 for thread 1 is in sequence #9We don't get much further in RMAN with this dodgy form of the recovery command than we did in SQL*Plus, it's true -but that's just because it's a silly command to use in the first place, wherever you thought to use it. The distinction you seek to draw between 'SQL commands' and 'RMAN commands' is false in this case, in other words.

  • How to run DDL in a Trigger?

    I am trying to create a trigger that automatically sets the quota for any new users created in the database. However, I am running into the follow error because whenever you run DDL, Oracle automatically commits, which you can't do in a trigger. Does anyone have any ideas on how to get around this? We are on Oracle 11gR1.
    . The problem is, I am getting an ERROR at line 1:
    ORA-04092: cannot COMMIT in a trigger
    CREATE OR REPLACE TRIGGER TESTER.AUTO_QUOTA
    AFTER INSERT ON USERS FOR EACH ROW
    DECLARE
    sqlstmt     VARCHAR2(100);
    BEGIN
    sqlstmt:='ALTER USER ' || :NEW.USERNAME || ' QUOTA UNLIMITED ON ' || :NEW.TABLESPACE_NAME;
    execute IMMEDIATE SQLSTMT;
    END;
    /

    ji**** wrote:
    I am trying to create a trigger that automatically sets the quota for any new users created in the database. However, I am running into the follow error because whenever you run DDL, Oracle automatically commits, which you can't do in a trigger. Does anyone have any ideas on how to get around this? We are on Oracle 11gR1.This approach is wrong.
    What is the purpose of a trigger? The answer is protecting the integrity of the transaction - not to do "extra stuff" outside the current actual business transaction. Like sending e-mails. Or SMS's. Or issue DDL commands.
    What happens when you do "extra stuff" in that trigger and the transaction is rolled back for example? What now happens to that "extra stuff" that should not have existed/have been done in the first place?
    The correct approach is to create a procedure or package that does this "extra stuff". Then schedule a job from this trigger to call that procedure.
    When the transaction commits, so too is the job to do the "extra stuff". If the trigger is rolled back, so too the submission of the job. And the trigger does not need smelly approaches like autonomous transactions for getting "extra stuff" done.

  • Scheduling ddl in a trigger

    Hi,
    I'm trying to find a way to schedule DDL statements from Oracle triggers.
    As one example, we keep INDEX metadata in our own IndexMetadata table.
    I'm trying to create a row delete trigger on this table that will schedule a (dynamic) DROP INDEX statement when the metadata row is deleted.
    An old post by Tom Kyte suggests using the dbms_job package to this end, but it seems to have no effect for me (on 11g), and the documentation says this package has been superseded by dbms_scheduler.
    However, if I try to create a DDL job using dbms_scheduler in my trigger, it fails at runtime.
    I DO NOT want to use an autonomous transaction for this purpose, as that could result in the physical index being dropped even if the metadata delete gets rolled back.
    Suggestions for the best way(s) to handle these issues appreciated,
    Ben

    Benjamin Lewis wrote:
    I'm trying to find a way to schedule DDL statements from Oracle triggers. Triggers are event mechanisms and unrelated to scheduling. Triggers executing DDL are a horrendous idea and not supported without workarounds that make them even more horrendous.
    >
    As one example, we keep INDEX metadata in our own IndexMetadata table.
    As to why anyone would do this, one mistake does not necessitate attempting three more.
    I'm trying to create a row delete trigger on this table that will schedule a (dynamic) DROP INDEX statement when the metadata row is deleted.Ouch.
    >
    I DO NOT want to use an autonomous transaction for this purpose, as that could result in the physical index being dropped even if the metadata delete gets rolled back.
    Re: pl/sql trigger
    Some more references from Tom Kyte this time saying Do not even think about doing this
    Suggestions for the best way(s) to handle these issues appreciated,Well you would probably begin by not duplicating the data dictionary and then not making database objects dependent on data stored in tables and then not needing to execute non-transactional DDL automatically as part of DML statements.
    The last of these is thankfully impossible.

  • ALTER TRIGGER DISABLE

    Dear all,
    I have a trigger on a table in schemaA.I have grant all on table to schemaB. If I login with schemaB, I was not able to disable the trigger of schemaA. It gave the error,
    ORA-04080: trigger 'blah_blah' does not existPlease help me out. I will explain the problem in detail below.
    I'm running a flow in Informatica powercenter with a different user from the target table schema owner. I should use a batch user to run the flow which is not the owner. But I want to disable the trigger on the table before I perform the flow and that can be handled using pre SQL in Power Center Designer. But when I ran the flow, I got this error. I tried it even in SQL*Plus by logging in as schemaB and tried to disable. I got this error. Is there anyway out of this?
    If the problem gets solved by granting some permissions to schemaB, I'm ready for that. I want gurus to help me out. Is there something called
    GRANT DISABLE TRIGGER ON trigger_name TO target_userCheers
    Deepa

    You may not really want that TRIGGER disabled, as it's disabled for everyone. If you just want to bypass the functionality in the trigger, use a package spec variable (pseudocode, so there are errors I'm sure):
    create package global_variables
    as
      skip_trigger boolean := FALSE;
    end global_variables;
    create trigger my_trigger_brt
    before insert or update or delete
    on my_table
    for each row
    procedure main as
       if global_variables.skip_trigger then
         return;
       end if;
    end main;
    begin
      main; 
    end;
    create trigger my_trigger_ast
    after insert or update or delete
    on my_table
    begin
      global_variables.skip_trigger := FALSE;
    end;
    /-cf

  • ORACLE 10.2.0.4 ( ADVISOR )

    Hi Big Masters,
    I'm Brazilian DBA,
    I have a very big problem in the production of my company, when I run any commands in the DDL (eg ALTER TRIGGER DISABLE NOME_TRIGGER) the session freezes and competition increases significantly and do not know why, but suspect something advisor that blocking something , someone could give an idea of what might be happening?
    Database: 10.2.0.4 - RAC
    Regards,
    Marco Ibañez

    ALTER SESSION SET SQL_TRACE=TRUE;
    -- invoke the problem SQL here
    ALTER SESSION SET SQL_TRACE=FALSE;
    now find the trace file within ./udump folder
    tkprof <trace_file.trc> trace_results.txt explain=<username>/<password>
    post the contents of trace_results.txt back here

  • 특정 USER에서 DDL 등의 COMMAND 실행을 제한하는 방법 - DDL EVENT TRIGGER

    제품 : ORACLE SERVER
    작성날짜 :
    특정 USER에서 DDL 등의 COMMAND 실행을 제한하는 방법 - DDL EVENT TRIGGER
    =======================================================================
    Purpose
    User에 있는 table등에 DDL 문장이 실행되지 않도록 막고 싶은 경우가 있다.
    Oracle8.1.6 부터 사용가능한 system trigger에 의해 이런 기능을 구현해 보자.
    Explanation
    Oracle8.1.6 의 new feature인 DDL event trigger를 이용하여 특정 user에서
    특정 DDL(예를 들어 create, drop, truncate 등)이나 모든 DDL이 실행할 때
    에러를 발생시킨다거나 특정한 action을 하도록 설정할 수 있다.
    DML 의 경우는 기존의 trigger 대로 각 object에 대해 각각 생성하여야 한다.
    이 자료에서는 주로 DDL 이나 DML 이 실행될 때 에러를 발생하도록 하여 해당
    문장이 실행되지 않도록 하는 방법을 기술하였다.
    (system or ddl event trigger에 대한 다른 자료로 Bulletin 11903,11848 참고)
    DDL event trigger 를 이용하기 위해서는 $ORACLE_HOME/dbs/initSID.ora
    file에서 COMPATIBLE parameter의 값이 "8.1.6" 이상으로 설정되어 있어야 한다.
    DDL event trigger 는 각 DDL이 발생할 때에 실행되는 trigger로
    다음과 같은 시점에서 실행되도록 만들 수 있다.
    BEFORE ALTER, AFTER ALTER, BEFORE DROP, AFTER DROP,
    BEFORE ANALYZE, AFTER ANALYZE, BEFORE ASSOCIATE STATISTICS,
    AFTER ASSOCIATE STATISTICS, BEFORE AUDIT, AFTER AUDIT,
    BEFORE NOAUDIT, AFTER NOAUDIT, BEFORE COMMENT, AFTER COMMENT,
    BEFORE CREATE, AFTER CREATE, BEFORE DDL, AFTER DDL,
    BEFORE DISASSOCIATE STATISTICS, AFTER DISASSOCIATE STATISTICS,
    BEFORE GRANT, AFTER GRANT, BEFORE RENAME, AFTER RENAME,
    BEFORE REVOKE, AFTER REVOKE, BEFORE TRUNCATE, AFTER TRUNCATE
    Example
    * 아래의 trigger 를 system 등의 별도로 관리하는 dba user에서 생성한다.
    [예제1] EJ user에서 table과 index에 해당하는 DDL의 실행을 막는 경우
    $ sqlplus system/manager
    CREATE OR REPLACE TRIGGER ej_no_ddl
    before DDL ON ej.schema
    WHEN (ora_dict_obj_type = 'TABLE' or
    ora_dict_obj_type = 'INDEX')
    begin
    raise_application_error (-20101, 'Cannot execute any DDL !!');
    end;
    -> 위의 trigger는 ej user의 schema 에서 Table과 Index 에 대한 DDL이
    실행될 때 user-defined error ora-20101 이 발생하도록 한 것이다.
    [예제2] EJ user에서 실행되는 모든 DDL을 막는 경우
    $ sqlplus system/manager
    CREATE OR REPLACE TRIGGER ej_no_ddl
    before DDL ON ej.schema
    begin
    raise_application_error (-20101, 'Cannot execute any DDL !!');
    end;
    -> 위의 예제는 모든 DDL 이 실행될 때 에러를 발생시키게 된다.
    예제1과 2의 경우 EJ user에서 DDL 실행시 아래와 같은 에러가 발생한다.
    $ sqlplus ej/ej
    SQL> create table test ( a number );
    create table test ( a number )
    ERROR at line 1:
    ORA-00604: error occurred at recursive SQL level 1
    ORA-20101: Cannot execute any DDL !!
    ORA-06512: at line 2
    SQL> drop table dept;
    drop table dept
    ERROR at line 1:
    ORA-00604: error occurred at recursive SQL level 1
    ORA-20101: Cannot execute any DDL !!
    ORA-06512: at line 2
    [예제3] EJ user에서 실행되는 drop과 truncate 문장을 막는 경우
    $ sqlplus system/manager
    CREATE OR REPLACE TRIGGER ej_no_ddl
    before drop or truncate ON ej.schema
    begin
    raise_application_error (-20102, 'Cannot execute DROP or TRUNCATE !!');
    end;
    위와 같이 trigger를 생성한 경우 EJ user에서 table의 생성은 되지만 drop은 할 수
    없다.
    $ sqlplus ej/ej
    SQL> create table test2 ( a number );
    Table created.
    SQL> drop table test2;
    drop table test2
    ERROR at line 1:
    ORA-00604: error occurred at recursive SQL level 1
    ORA-20102: Cannot execute DROP or TRUNCATE !!
    ORA-06512: at line 2
    [예제4] EJ user의 docu2 table에 대한 dml을 막는 경우
    $ sqlplus system/manager
    CREATE OR REPLACE TRIGGER ej_no_dml_docu2
    before insert or update or delete on ej.docu2
    begin
    raise_application_error (-20103, 'Cannot execute DML');
    end;
    $ sqlplus ej/ej
    SQL> delete from docu2 where docu_id=2;
    delete from docu2 where docu_id=2
    ERROR at line 1:
    ORA-20103: Cannot execute DML
    ORA-06512: at "SYSTEM.EJ_NO_DML_DOCU2", line 2
    ORA-04088: error during execution of trigger 'SYSTEM.EJ_NO_DML_DOCU2'
    * table의 작업을 위해 일시적으로 trigger의 기능을
    disable 또는 enable시킬 수 있다.
    $ sqlplus system/manager
    SQL> alter trigger ej_no_ddl disable;
    or
    SQL> alter trigger ej_no_ddl enable;

  • Trigger to audit DML and DDL nor working

    Requirement: Application team complains that everyday within a fixed timeframe, 1 entry from a particular table is being deleted. They are unable to track it, which particular job is it doing it.
    DBA: We had 3 solutions: 1. AUDIT_TRAIL
    2. FGA
    3. Customized TRIGGER to track the DML and DDL.
    After discussion, option 3 has been implemented. Here is the code.
    DML Trigger
    =======
    CREATE OR REPLACE TRIGGER SLCPROD.STORE_TERM_ID_HST_TRG
    BEFORE INSERT OR UPDATE OR DELETE
    ON SLCPROD.STORE_TERM_ID FOR EACH ROW
    BEGIN
    IF UPDATING THEN
    INSERT INTO STORE_TERM_ID_HIST
    ( STR_NUM,
    TERM_ID,
    HOST_ENV,
    USR_TERMINAL,
    SESSION_USR,
    OS_USER,
    ACTION_DATE,
    ACTION_NAME)
    VALUES
    ( TRUNC(:OLD.STR_NUM)||','||:NEW.STR_NUM,
    TRUNC(:OLD.TERM_ID)||','||:NEW.TERM_ID,
    sys_context('USERENV', 'HOST'),
    sys_context('USERENV', 'TERMINAL'),
    sys_context('USERENV', 'SESSION_USER'),
    sys_context('USERENV', 'OS_USER'),
    SYSDATE,
    'UPDATE');
    ELSIF DELETING THEN
    INSERT INTO STORE_TERM_ID_HIST
    ( STR_NUM,
    TERM_ID,
    HOST_ENV,
    USR_TERMINAL,
    SESSION_USR,
    OS_USER,
    ACTION_DATE,
    ACTION_NAME)
    VALUES
    ( :OLD.STR_NUM,
    :OLD.TERM_ID,
    sys_context('USERENV', 'HOST'),
    sys_context('USERENV', 'TERMINAL'),
    sys_context('USERENV', 'SESSION_USER'),
    sys_context('USERENV', 'OS_USER'),
    SYSDATE,
    'DELETE');
    END IF;
    END;
    DDL Trigger
    ========
    CREATE OR REPLACE TRIGGER SLCPROD.STORE_TERM_ID_HST_TRG_TRUNC
    AFTER DDL ON DATABASE
    declare
    object_name varchar2(30);
    BEGIN
    select distinct ora_dict_obj_name into object_name from dual;
    if UPPER(object_name)= 'STORE_TERM_ID'
    then
    INSERT INTO STORE_TERM_ID_HIST
    ( STR_NUM,
    TERM_ID,
    HOST_ENV,
    USR_TERMINAL,
    SESSION_USR,
    OS_USER,
    ACTION_DATE,
    ACTION_NAME)
    VALUES
    ( 'NA',
    'NA',
    sys_context('USERENV', 'HOST'),
    sys_context('USERENV', 'TERMINAL'),
    sys_context('USERENV', 'SESSION_USER'),
    sys_context('USERENV', 'OS_USER'),
    SYSDATE,
    ora_sysevent);
    END IF;
    END;
    TABLE STORE_TERM_ID_HIST DESC
    =======================
    Name Null? Type
    STR_NUM CHAR(25)
    TERM_ID CHAR(25)
    HOST_ENV VARCHAR2(50)
    USR_TERMINAL VARCHAR2(50)
    SESSION_USR VARCHAR2(50)
    OS_USER VARCHAR2(50)
    ACTION_DATE DATE
    ACTION_NAME VARCHAR2(50)
    Though we have these triggers in place, still we can see that 1 record is getting deleted (do not know how as I haven't been able to track it) between 8 AM - 8:50 AM. We have verified it from COUNT and also know which particular record is getting deleted.
    We tried to see if any error logged due to these triggers in ALERT logs, but no error specific to it has been seen. We have tested the TRIGGERs using manuals queries, and they seem to be working fine.
    Could anyone please help what could be happening here? Or any better solution of resolving it.
    Thanks,
    Tapan
    Edited by: TapanKumar Saha on Mar 31, 2013 10:04 PM
    updated the code.

    Thank you all for all the help.
    My issue is resolved now. Here is the analysis:
    Our triggers (both for DML and DDL) were working earlier as well. However, it was not capturing the actions. We could see that last_ddl_date is being updated with the time when we are expecting the mischievous to happen. So, after having internal discussions, we concluded that "ALTER INDEX.." could also update the last_ddl_date. But it has nothing to do with the DELETE. However, to track the INDEX DDLs we added trigger on INDEX as well. Here is the modified code:
    DDL Trigger
    =======
    CREATE OR REPLACE TRIGGER SLCPROD.STORE_TERM_ID_HST_TRG_TRUNC
    AFTER DDL ON DATABASE
    declare
    object_name varchar2(30);
    BEGIN
    select distinct ora_dict_obj_name into object_name from dual;
    if UPPER(object_name)= 'STORE_TERM_ID'
    then
    INSERT INTO STORE_TERM_ID_HIST
    ( STR_NUM,
    TERM_ID,
    HOST_ENV,
    USR_TERMINAL,
    SESSION_USR,
    OS_USER,
    ACTION_DATE,
    ACTION_NAME)
    VALUES
    ( 'NA',
    'NA',
    sys_context('USERENV', 'HOST'),
    sys_context('USERENV', 'TERMINAL'),
    sys_context('USERENV', 'SESSION_USER'),
    sys_context('USERENV', 'OS_USER'),
    SYSDATE,
    ora_sysevent);
    elsif UPPER(object_name)= 'STORE_TERM_ID_PK'
    then
    INSERT INTO STORE_TERM_ID_HIST
    +( STR_NUM,+
    TERM_ID,
    HOST_ENV,
    USR_TERMINAL,
    SESSION_USR,
    OS_USER,
    ACTION_DATE,
    ACTION_NAME)
    VALUES
    +( 'NA',+
    +'NA',+
    sys_context('USERENV', 'HOST'),
    sys_context('USERENV', 'TERMINAL'),
    sys_context('USERENV', 'SESSION_USER'),
    sys_context('USERENV', 'OS_USER'),
    SYSDATE,
    ora_sysevent);
    END IF;
    END;
    It started tracking the TRUNCATE on the table.
    Also, we we increased the length of the data types for the temporary table to avoid any insertion errors. And finally put an INSERT trigger after seeing TRUNCATE DDLs. And we thus we resolved the issue.

  • Dbms_metadata and trigger ddl (db version 10g)

    Hi all,
    does anyone know if there is a parameter in procedure dbms_metadata.set_transform_param to get rid of the alter trigger enable clause that is automatically appended otherwise?
    For other objects like table there is such possibility for constraints for instance, but I don't see triggers in the list of supported objects.
    Thanks and Bye,
    Flavio

    Hi All,
    According to the support, we update the column flag in mlog$ to fix the issue due to the Bug 12849688.
    Now, DBMS_METADATA.get_dependent_ddl can return the right result.
    However, the old data in the materialized view log cannot be cleared after different kinds of refresh including fast, complete and force etc.
    Any idea?
    Thanks for your help

  • Generating Trigger DDL using OO4O (OField::GetChunk)

    WINNT 4.0SP6
    MS Visual C++ 6.0 (using MFC)
    Oracle 8.1.7
    I'm attempting to write some C++ code that will generate the DDL of a trigger using OO4O.
    Here's the code (so far):-
    strSQL.Format("SELECT DESCRIPTION, TRIGGER_BODY FROM ALL_TRIGGERS WHERE OWNER = '%s' AND TRIGGER_NAME = '%s'", strOwner, strName);
    dyn.Open(m_pDatabase->m_database, strSQL);
    int nBuffSize = 65535;
    nSize = dyn.GetFieldSize(0);
    const char *pValue = strValue.GetBuffer(nSize+1);
    dyn.GetFieldValue(0, (char*)pValue, nSize + 1);
    strValue.ReleaseBuffer();
    strText.Format("CREATE OR REPLACE %s %s", pszType, strValue);
    OField fld =      dyn.GetField(1);
    const char *pBuffer = NULL;
    unsigned short nBytesRead = 0;
    long nOffset = 0;
    CString strBuff;
    do
         if (fld.GetChunk(&pBuffer, nOffset, nBuffSize, &nBytesRead) != OSUCCESS)
              break;
         if (nBytesRead)
              char *p = strBuff.GetBuffer(nBytesRead);
              memcpy(p, pBuffer, nBytesRead);
              strBuff.ReleaseBuffer();
              strText += strBuff;
              nOffset += nBytesRead;
    while (nBytesRead);
    My problem is that the GetChunk method is failing, although it still returns OSUCCESS.
    If I call OField::GetErrorText() after the GetChunk call I get the error "ROWID must be selected ..". Looking at the documentation this does make sense. That is, to access LONG type field values the ROWID must be accessible.
    In this case there is no ROWID available because we are selecting from a dictionary view (ALL_TRIGGERS). Attempting to "SELECT ROWID FROM ALL_TRIGGERS" results in the error "ORA-01446: cannot select ROWID from view with DISTINCT, GROUP BY, etc.".
    Can anyone out there point me in the right direction to solve this one ?
    Thanks in advance.
    Adrian Capp
    LBS Limited, UK

    Thanks for that.
    Can you tell me which Dictionary Table I need to query. I've tried looking at the definition of the ALL_TRIGGERS view but was still none-the-wiser.
    I agree that it's not an ideal solution, but the application in question is only going to be used internally by development personel. I could also add a check as the app starts so it will only run if connected to a specific version of Oracle (just an idea).
    Adrian

  • ALTER DATABASE  RECOVER AUTOMATIC

    Hi,
    in 10 gR2 when applying :
    ALTER DATABASE
        RECOVER AUTOMATIC UNTIL TIME '2001-10-27:14:00:00';what should be the state of Database ? Nomount ? Mount ? Open ?
    Thank you.

    "RECOVER DATABASE" (or "ALTER DATABASE RECOVER") is in MOUNT state
    "RECOVER TABLESPACE" or "RECOVER DATAFILE" can be in OPEN state (except when Tablespace/Datafile is SYSTEM , in which case the database must be MOUNT)

  • Can't import DDL file that has alter table rename constraint

    Hi:
    Version 3.1.0.691 on Windows 7 Enterprise 64-bit SP1
    I'm trying to import a DDL file with syntax similar to what's below. The <name> notes that I've replaced the actual names for obfuscation purposes.; the real names are in the script.
    ALTER TABLE <name>
    RENAME CONSTRAINT SYS_C0041150
    TO <name2>_CK;
    ALTER TABLE <name>
    RENAME CONSTRAINT AVCON_1281559518_ACTIV_022
    TO <name2>_CK;
    I get the following error:
    Oracle SQL Developer Data Modeler 3.1.0.691
    Oracle SQL Developer Data Modeler Import Log
    Date and Time: 2012-01-13 16:29:05 PST
    Design Name: <name>
    RDBMS : Oracle Database 11g
              All Statements:           819
              Imported Statements:      0
              Failed Statements:           0
              Not Recognized Statements:      819
    <<<<< Not Recognized >>>>>
    ALTER TABLE <name>
    RENAME CONSTRAINT SYS_<name>
    TO <name2>_CK
    ALTER TABLE <name>
    RENAME CONSTRAINT AVCON_1281559518_QVI_A_000
    TO <name2>_CK
    Thanks for any help you can provide.
    Doc

    Hi:
    The file was indeed comprised of just alter statements. As a test, I trimmed the file down to just one alter statement:
    ALTER TABLE <name> RENAME CONSTRAINT SYS_C0041413 TO <name2>_CK;
    The output file contained exactly the following, where the <<BEGIN OF FILE>> and <<END OF FILE>> were simply added here for clarity. There was no section called
    <<<<< ERRORS >>>>> and the ddl file contained no create table statements.
    <<BEGIN OF FILE>>
    Oracle SQL Developer Data Modeler 3.1.0.691
    Oracle SQL Developer Data Modeler Import Log
    Date and Time: 2012-01-16 10:16:42 PST
    Design Name: <name>
    RDBMS : Oracle Database 11g
              All Statements:           1
              Imported Statements:      0
              Failed Statements:           0
              Not Recognized Statements:      1
    <<<<< Not Recognized >>>>>
    ALTER TABLE <name> RENAME CONSTRAINT SYS_C0041413 TO <name2>_CK
    <<END OF FILE>>
    Other info.
    When I do an model import, none of the existing check constraint names get captured. Also, if I add names afterwards to two separates models via DM and then compare them. The output DDL shows a drop of the target constraint referencing its name, but the recreation of the not null constraint doesnt reference the source constraint name set for it manually in DM. Here's the example I did and the output ddl.
    ALTER TABLE <name>
    DROP CONSTRAINT SYS_C0041413
    ALTER TABLE <name>
    MODIFY ( <column_name> NOT NULL )
    That last line should have read as follows due to the constraint_name I added for it in DM.
    ALTER TABLE <name>
    MODIFY (<column_name> CONSTRAINT <name2>_CK NOT NULL);
    In the example directly above, <name2>_CK is the name I explicity set via DM and would have expected the compare to have used to recreated the constraint since it referenced the target constraint name when it constructed the drop constraint syntax.
    I believe at least one bug is involved here, most likely two.
    The first bug is that model imports are not capturing not null check constraint names.
    The second bug is that the source constraint name is not being used when generating the ddl necessary to change the not null constraint name in the target model.
    All of this is assuming that I haven't just goofed and forgotten to check a box somewhere telling it to do what I've been talking about here. :-)
    Doc

  • Trigger/Sequence not in ddl preview when comparing models

    Hi,
    I've a problem with incremental DDL generation and trigger/sequence (auto-increment).
    First case :
    I've created a table and generated it in my Oracle database.
    Then, I've defined on my primary key column the "Auto-increment" and "Identity column" to Yes (and of course sequence and trigger names filled).
    If I generate DDL (File/Export or Generate DDL button), no problem. The DDL script contains the sequence and trigger defined in auto-increment properties.
    But if I compare my model and the database (Import data dictionnary, swap target...), the sequence and the trigger are not in the DDL preview.
    Second case :
    If I create a new table in my relational model, with filled auto-increment properties, and then I compare model and db, the new table is created, with associated sequence and trigger. This is completely normal.
    Last case :
    A trigger manually defined in physical model is not in DDL preview if the table already exists in database. If the table doesn't already exist in db, all statements (table, sequence, trigger) are generated.
    my conclusion : auto-increment properties are not taken into account in the incremental DDL generation if the table already exists.
    Can you confirm this ?
    thanks
    regards
    Fabrice
    (Data modeler 3.1.4)

    Hi Fabrice,
    A trigger manually defined in physical model is not in DDL preview if the table already exists in database.Yes. This is true.
    my conclusion : auto-increment properties are not taken into account in the incremental DDL generation if the table already exists.The actual situation is that auto-increment properties are not taken into account in the incremental DDL generation if the column already exists.
    David

Maybe you are looking for