Getting all_tab_columns.data_default in a ddl trigger

Under 10.1.0.3 I'm working on an AFTER CREATE or ALTER on DATABASE system trigger, and I'm querying all_tab_columns in the trigger body. It seems that if the trigger fires in response to DDL that modifies a column's default value, then all_tab_columns.data_default is giving me the column's old default. I want to get the current default value. If I create the table or add a column, then, in the resulting fire of the system trigger, all_tab_columns.data_default seems to be correct.
Is this documented behavior? Should I be looking somewhere (or somewhen) else for the column default?

Thanks.
I tried working around this by putting my code into a procedure, and then using the DDL trigger to create a job that runs the code. My idea was to defer the all_tab_columns query until after the DDL trigger was done, and thus get a clean look at the data dictionary.
I put what looks like the appropriate dbms_scheduler calls into the trigger, but when I then execute DDL to fire the trigger I get "ORA-04092: cannot in a trigger"
The doc for this error number says that I am trying to commit or rollback in a trigger, but I'm not explicitly doing that. Also, the error message is supposed to have either the word "commit" or the word "rollback" in the message to tell me what I am doing. Instead, though, the error message just has a space there.
Maybe I'll start a TAR and see if 10.1.0.3 can get appended to the growing list of versions tied to this bug.

Similar Messages

  • How to get added columns in the after DDL trigger?

    As title, I want to get information, like name/type/.., about the added columns by sql statement "alter table *** add (***)" in the after ddl trigger. But looks like dba_tab_columns view doesn't include the added columns.
    Thanks

    Hi
    Hi try other versions of the trigger like
    create or replace trigger addl_trigger
    after alter on schema
    declare
    TYPE attrs_cur IS REF CURSOR;
    m_cur attrs_cur;
    m_event varchar2(50);
    m_user varchar2(50);
    m_owner varchar2(50);
    m_user1 varchar2(50);
    m_type varchar2(50);
    m_name varchar2(50);
    m_column varchar2(50);
    m_cnt NUMBER;
    m_stmt varchar2(512);
    number_of_modified_objects BINARY_INTEGER;
    t ora_name_list_t;
    begin
    m_event:=ora_sysevent;
    m_user:=SYS_CONTEXT('USERENV','SESSION_USER');
    m_user1:=ora_login_user;
    m_owner:=ora_dict_obj_owner;
    m_type:=ora_dict_obj_type;
    m_name:=ora_dict_obj_name;
    if (m_type='TABLE' and m_event='ALTER')
    then
              execute immediate 'select count(*) from dba_tab_columns where owner=:1 and table_name=:2' into m_cnt
              using m_owner,m_name;
              insert into log values (m_cnt);
              dbms_output.put_line('->'||m_cnt);
              OPEN m_cur FOR 'select c.name from sys.col$ c, sys.obj$ o, sys.user$ u where o.obj# = c.obj# and o.owner# = u.user# and u.name=:1 and o.name=:2' using m_owner,m_name;
              LOOP
                        FETCH m_cur INTO m_stmt;
                        EXIT WHEN m_cur%NOTFOUND;
                        insert into log values (m_stmt);
                        --dbms_output.put_line(m_stmt||'**************');
                        END LOOP;
    end if;
    but all versions continue to insert only the already existing columns. I think that Oracle actualize the dictionary first after this system event.
    Bye, Aron

  • DDL-trigger can't use select on table affected by DLL-statement?

    Hi all,
    my situation
    I have a DDL-trigger that gets executed after every alter-statement. The trigger reads some information from the table CHNGHIS_TAB. The trigger works fine for all the tables except for CHNGHIS_TAB. When I try to add a column to this table, I get the following error (translated from german, I don't know, if the message is exactly the same in english):
    SQL> alter table chnghis_tab add (test varchar2(254));
    alter table chnghis_tab add (test varchar2(254))
    ERROR in Row 1:
    ORA-00604: error occurred at recursive SQL level 1
    ORA-06550: Row 12, Column 45:
    PL/SQL: ORA-00600: internal error code, arguments: [12830], [NTSDEV6],
    [CHNGHIS_TAB], [], [], [], [], []
    ORA-06550: Row 12, Column 5:
    PL/SQL: SQL Statement ignoredmy trigger
    create or replace trigger chnghis_ddl_trigger after alter on schema
    declare
        counter number := 0;
        tablename varchar2(30) := dictionary_obj_name;
    begin
        /* leave if the altered table is CHNGHIS_TAB */
        if upper(tablename) like 'CHNGHIS_TAB' then
            return;
        end if;
        /* look if the changed object is a table that should be logged*/
        select count(tabname) into counter from chnghis_tab where upper(tabname) = tablename;
        if counter = 0 then
            return;
        end if;
        /* call the procedure to generate the logging trigger */
        generateLogTrigger(tablename);
    end;Thanks for your help =)

    It looks like you are getting an ORA-00600 error. You should contact Oracle support.

  • How can I get Launching report directory in report trigger??

    how can I get Launching report directory in report trigger??
    pls help me :'<
    I can run this function in forms.
    "how can I get Launching report directory in report trigger??"
    does reports have same function???

    Click the little down arrow/+ symbol  next the + - in the folders bar.

  • Ddl trigger to track permission change in database

    Hi,
    How can I create a DDL trigger to log any permission change in a database?
    thanks
    oldmandba

    Your best approach is Event Notification.
    Event Notification vs DDL triggers:
    http://technet.microsoft.com/en-us/library/ms189855(v=sql.105).aspx
    BOL links on Event Notification:
    http://technet.microsoft.com/en-us/library/ms187476(v=sql.105).aspx
    http://technet.microsoft.com/en-us/library/ms182602(v=sql.105).aspx
    http://technet.microsoft.com/en-us/library/ms189453.aspx
    DDL Trigger solution:
    http://www.mssqltips.com/sqlservertip/2085/sql-server-ddl-triggers-to-track-all-database-changes/
    Kalman Toth Database & OLAP Architect
    IPAD SELECT Query Video Tutorial 3.5 Hours
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Getting iteration number in row level trigger

    Hi. Is there a way to get iteration number in row level trigger? Or to access data inserted in statement level trigger from row level trigger (statement level trigger are supposed to be executed before row level triggers but I cannot access them).
    I'm using Oracle 10g.

    My oracle version:
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE 10.2.0.4.0 Production
    TNS for 64-bit Windows: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    And business problem is like this:
    I need to have two log tables for some tables in my database:
    First log table is a statement level log. After insert or update or delete it should get one new row with mentioning date, time, sid, query type and some additional information.
    Second table should include all columns from table logged, date, time, sid and operation type.
    The problem is, I need exact the same date and time for each row in both log tables.
    Someone said that sysdate should return same value for query execution time. But it have nothing to do with triggers fired on this query.
    So you may say that I'm curious about getting exact same date and time for one statement level trigger and for each execution of row level trigger.

  • DBMS_JOBS fails inside a DDL trigger when granting permissions to roles

    Hi,
    I have a DDL Trigger through which I am granting SELECT on newly created tables to existing read-only roles
    CREATE OR REPLACE TRIGGER DBADMIN.grant_permission_trigger
    AFTER CREATE
    ON DATABASE
    DECLARE
    v_owner dba_tables.owner%TYPE;
    v_role dba_roles.role%TYPE;
    v_object dba_tables.table_name%TYPE;
    v_object_type dba_objects.object_type%TYPE;
    n_temp_int INTEGER DEFAULT 0 ;
    l_job NUMBER;
    n_temp dba_tables.temporary%TYPE;
    BEGIN
    --selecting owner
    SELECT ora_dict_obj_owner INTO v_owner FROM DUAL;
    v_role := v_owner || '_S';
    --selecting table name
    SELECT ora_dict_obj_name INTO v_object FROM DUAL;
    SELECT ORA_DICT_OBJ_TYPE INTO v_object_type FROM DUAL;
    IF (v_object_type = 'TABLE')
    THEN
    SELECT COUNT (1)
    INTO n_temp_int
    FROM dba_roles
    WHERE role = v_role;
    -- if a role does not exist already, then create a role
    IF n_temp_int != 0
    THEN
    SELECT temporary
    INTO n_temp
    FROM dba_tables
    WHERE table_name = v_object;
    IF (n_temp = 'N')
    THEN
    DBMS_JOB.submit (
    job => l_job,
    what => 'BEGIN EXECUTE IMMEDIATE ''GRANT SELECT ON '
    || v_owner
    || '.'
    || v_object
    || ' TO '
    || v_role
    || '''; END;'
    END IF;
    END IF;
    END IF;
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    NULL;
    END;
    I am executing this trigger as DBADMIN having the following explicit grants
    grant any object privilege
    SELECT ANY DICTIONARY
    The problem happens when someone creates a table in their procedure and drops it off at the end of the procedure, the JOB which is in the queue when it executes, it cannot find the table and the jobs are failing.
    I have given a check to see if its temporary. But still the jobs are failing. I am missing someting
    Can someone let me know what should be done? I have production issues which should be resolved.

    Hi,
    The problem happens when someone creates a table in their procedure and drops it off at the end of the procedure, the JOB which is in the queue when it executes, it cannot find the table and the jobs are failing.Seems more like this is the problem:
    SELECT temporary
    INTO n_temp
    FROM dba_tables
    WHERE table_name = v_object;If that would not throw NO_DATA_FOUND, there would be no need for the dbms_job.
    Seems safe to remove, you are not using n_temp and if it raises no_data_found you are doing nothing.
    Also, these are not necessary
    SELECT ora_dict_obj_owner INTO v_owner FROM DUAL;
    SELECT ora_dict_obj_name INTO v_object FROM DUAL;
    SELECT ORA_DICT_OBJ_TYPE INTO v_object_type FROM DUAL;You can use System Events in PL/SQL
    Why this comment?
    -- if a role does not exist already, then create a roleYou aren't trying to create a role.
    Regards
    Peter

  • DDL trigger to Capture the DDL changes on one database and applies to child level databases in same server.

    Hi friends,
            I need to create one DDL trigger to Capture the all DDL modification on parent database and applies those changes to the underlying (child) databases  in my project.
            Can anyone help me out in this,how to track the changes and applies to the child level databases?
    Thanks in Advance.

    Use Visual Studio Data Tools or
    Red Gate Compare.

  • How do you get a list of all the trigger DDLs?

    I want to get a list of all the DB trigger DDLs of owner 'ABS'. I want to do it using 1 SQL statement.
    This is what I ran:
    SELECT
    TO_CHAR(DBMS_METADATA.GET_DDL('TRIGGER', TRIGGER_NAME, 'ABS'))
    FROM
    ALL_TRIGGERS
    WHERE
    OWNER = 'ABS';
    I get this error: [1]:
    (Error): ORA-22835: Buffer too small for CLOB to CHAR or BLOB to RAW conversion (actual: 4414, maximum: 4000)
    Then I looked up in the web and they ask to use DBMS_LOB.SUBSTR instead. So I do that:
    SELECT
    DBMS_LOB.SUBSTR(DBMS_METADATA.GET_DDL('TRIGGER', TRIGGER_NAME, 'ABS'), 32767, 1)
    FROM
    ALL_TRIGGERS
    WHERE
    OWNER = 'ABS';
    Now I get this error:
    [1]: (Error): ORA-06502: PL/SQL: numeric or value error: character string buffer too small ORA-06512: at line 1
    Looks like you cannot show more than *4000* chars. There are 43 triggers whose DDL is more than 4000 chars long.
    Why is this?
    How can I solve my problem?
    Edited by: Channa on Feb 16, 2010 9:45 PM

    Herald, fantastic news. SET LONG did the trick.
    But I had to put a very big value. 32000 was not enough. Otherwise some of the triggers (big ones) got cut off.
    This is my complete code which did it.
    SPOOL F:\Channa\zz_zzTemp\Binuka\OutPut.txt
    set trimspool on
    set pages 0
    set long *1000000000*
    set linesize 32767
    SET TERMOUT OFF
    SELECT DBMS_METADATA.GET_DDL('TRIGGER', TRIGGER_NAME, 'ABS')
    FROM ALL_TRIGGERS
    WHERE OWNER = 'ABS' AND trigger_name NOT LIKE 'BIN$%'
    SPOOL OUT
    THANKS A LOT. REALLY APPRECIATE IT.
    P.S: I had to include the NOT LIKE 'BIN$%' in the where clause because otherwise I got this error:
    ERROR:
    ORA-31603: object *"BIN$cqXDSqghrFngQKjAJAovgw==$0"* of type TRIGGER not found in
    schema "ABS"
    ORA-06512: at "SYS.DBMS_SYS_ERROR", line 105
    ORA-06512: at "SYS.DBMS_METADATA", line 2805
    ORA-06512: at "SYS.DBMS_METADATA", line 4333
    ORA-06512: at line 1
    no rows selected
    I THINK BIN$... triggers are dropped triggers in the DB recycle bin???
    Edited by: Channa on Feb 17, 2010 2:58 AM
    Edited by: Channa on Feb 17, 2010 3:01 AM

  • Get old and new text of a VIEW at DDL trigger

    Is it possible to get the old and the new text of a view at the DDL triggers

    Hi,
    Don't know regarding later Oracle versions but with 8.1.7.3.0 you cannot base system triggers on tables or views: Ora-30506.
    Regards,
    Andrew Velitchko
    BrainBench MVP for Developer/2000
    http://www.brainbench.com

  • How to get the table name in the trigger definition without hard coding.

    CREATE  TRIGGER db.mytablename
    AFTER UPDATE,INSERT
    AS
        INSERT INTO table1(col1)
        SELECT InsRec.col1   
        FROM
        INSERTED Ins
       --Below i am calling one sp for which i have to pass the table name
       EXEC myspname 'tablename'
      In the above trigger,presently i am hard coding the tablename
      but is it possible to get the table name dynamically on which the trigger is defined in order to avoid hard coding the table name

    I really liked your audit table concept.  You inspired me to modify it so that, the entire recordset gets captured and added a couple of other fields.  Wanted to share my end result.
    USE [YourDB]
    GO
    /****** Object: Trigger [dbo].[iudt_AutoAuditChanges] Script Date: 10/18/2013 12:49:55 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER TRIGGER [dbo].[iudt_AutoAuditChanges]
    ON [dbo].[YourTable]
    AFTER INSERT,DELETE,UPDATE
    AS
    BEGIN
    SET NOCOUNT ON;
    Declare @v_AuditID bigint
    IF OBJECT_ID('dbo.AutoAudit','U') IS NULL BEGIN
    CREATE TABLE [dbo].[AutoAudit]
    ( [AuditID] bigint identity,
    [AuditDate] DateTime,
    [AuditUserName] varchar(128),
    [TableName] varchar(128) NULL,
    [OldContent] XML NULL,
    [NewContent] XML NULL
    ALTER TABLE dbo.AutoAudit ADD CONSTRAINT
    PK_AutoAudit PRIMARY KEY CLUSTERED
    [AuditID]
    ) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    CREATE NONCLUSTERED INDEX [idx_AutoAudit_TableName_AuditDate] ON [dbo].[AutoAudit]
    ( [TableName] ASC,
    [AuditDate] ASC
    )WITH (STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    END
    Select * Into #AuditDeleted from deleted
    Select * Into #AuditInserted from inserted
    While (Select COUNT(*) from #AuditDeleted) > 0 OR (Select COUNT(*) from #AuditInserted) > 0
    Begin
    INSERT INTO [dbo].[AutoAudit]
    ( [AuditDate], [AuditUserName], [TableName], [OldContent], [NewContent])
    SELECT
    GETDATE(),
    SUSER_NAME(),
    [TableName]=object_name([parent_obj]),
    [OldContent]=CAST((SELECT TOP 1 * FROM #AuditDeleted D FOR XML RAW) AS XML),
    [NewContent]=CAST((SELECT TOP 1 * FROM #AuditInserted I FOR XML RAW) AS XML)
    FROM sysobjects
    WHERE
    [xtype] = 'tr'
    and [name] = OBJECT_NAME(@@PROCID)
    Set @v_AuditID = SCOPE_IDENTITY()
    Delete from AutoAudit
    Where AuditID = @v_AuditID
    AND Convert(varchar(max),oldContent) = Convert(varchar(max),NewContent)
    Delete top(1) from #AuditDeleted
    Delete top(1) from #AuditInserted
    End
    END

  • Get Current SQL in Before delete trigger

    Hi,
    I have created a before delete trigger to track which records are deleted from a table I need to know what statements fires the trigger. can someone please describe how I can retrieve the current SQL.
    using sys_context('userenv','CURRENT_SQL') returns null for CURRENT SQL
    Note:
    For me the easier is to enable auditing and audit delete on the table however at the moment I cant get a downtime from the business to bounce the database to enable auditing.
    CREATE OR REPLACE TRIGGER before_delete BEFORE DELETE
    ON AUDIT_TEST_TAB
    FOR EACH ROW
    DECLARE
    v_username varchar2(50);
    v_stmt varchar2(255);
    v_client_info varchar2(200);
    v_os_user varchar2(50);
    v_machine varchar2(50);
    v_program varchar2(50);
    v_module varchar2(50);
    v_auth_type varchar2(200);
    v_ip_addr varchar2(200);
    v_sql_statement VARCHAR2(4000);
    BEGIN
    SELECT sys_context ('USERENV', 'CURRENT_SQL')
    INTO v_sql_statement
    FROM dual;
    -----------insert into logging table statment ----
    end;

    A few comments.
    Lets assume you run a delete statement that deletes 550 rows from your table. If your trigger is working then the very same statement would be stored 550 times. I think an BEFORE or better an AFTER delete STATEMENT level trigger would be the better choice. Why AFTER? Because if the delete operation fails, for example because of existing child records, then everything is rolled back anyway to the implicit savepoint just before the delete.
    So to store the SQL statement the correct trigger would be an AFTER STATEMENT DELETE trigger.
    Now what to store: You want the sql statement. You could try to find the cursor/currently running SQL. It might be tricky to separate that from the SQLs that you run to find this out.
    It could even be possible to simply save all commands that are in your PGA/Cached cursor area. First find out yur session, then store the SQL_text (first 60 chars) for all the cursors in this session by using v$open_cursor or the first 1000 chars by using v$sql.
    Here are a few views that might be helpful. v$session , v$open_cursor, v$sql, v$sqltext, v$sql_bind_data, v$sql_bind_capture, dba_hist_sqltext

  • Anyone been able to get OS Image Capture to remote trigger Canon EOS DLSR?

    Hi
    I am connecting my Canon EOS 50D DLSR to a MacBook using USB.
    I am able to copy photos off the camera's memory card, however the built in OS X Image Capture software refuses to remote trigger the camera to take a picture.
    I need to try get it working as being able to remote trigger the camera using the Image Capture software is a pre-requisite to using iStopMotion animation software which apparently uses the same Quicktime framework.
    Thanks in advance.
    Chris

    iStopMotion fails to trigger the camera. I have been in contact with the developers and they say that iStopMotion uses the same Apple Quicktime framework as the OS supplied Image Capture software (which does have a Take Picture menu option)
    So essentially if I can resolve the issue and get the Apple OS Image Software to trigger the camera it is a good indication that the issue is resolved and the iStopMotion software will also work.
    I am using the Image Capture software to test the issue as my free demo license to iStopMotion has now expired and obviously I don't want to buy the software unless I believe it will work.
    Any Canon EOS 50D DLSR owners out there who can test their camera with the Mac OS Image Capture Take Picture option?

  • Getting error -200452 using DAQmx Base Trigger (Digital Edge).

    I'm trying to set up AI and counter output, and I'm using digital output as trigger for to start AI and counter at the same time. I get error 200452 "Specified property is not supported by the devise..." not consistently, but around 5 runs out of 100. Below the error description, the error box shows "This error code is undefined. No one has provided a description for this code..." If I "Retain Wire Values" in Block Diagram, the error first appears after 'Start Digital Edge' block in top counter output line.
    Using LabView 8.5 on MAC OS X and DAQmxBase 3.2
    The MAC I have is not Intel base, so I can't upgrade LabView and DAQmxBase to latest version
    Note: The file contains just a small portion of the program, but the rest of the program does not have any other DAQmxBase blocks accessing the channels used here in code attached.
    Attachments:
    Combined V 1.5.41_sm.vi ‏98 KB

    Hi Azotov,
    It looks like the DAQmx Base driver readme includes Mac OS X support for LabVIEW 8.5.  Could you specify what hardware you are using?
    I found one KnowledgeBase specifying that error code occurs when you try to use certain properties with certain devices.  Of course, this would most likely occur every time you run the task, not 5% of the time.
    Since I'm running Windows, it's a little difficult to see if you have DAQmx Base "Reset Device" functionality with that version of the driver.  You might check if you can run that functionality before using your device, though.
    National Instruments

  • How to get the SQL which invoked a trigger

    Hi,
    I have a table from which the rows are getting deleted without our knowledge.
    To track this I've put a trigger on delete of this table. I want to know which SQL is actually invoking this Delete trigger so that I can capture it inside the trigger and log it somewhere so that I can analyze from where this SQL is fired.
    Please let me know if any one can help me regarding this.
    Thanks,
    Makrand

    If possible try and explore the FGA (Fine Grained Auditing) option . You may not need to create any triggers on the table and look up V$ views.
    Instead, define a RULE on the table. FGA will track the DML operation performed based on the RULE you defined
    i.e Consider a policy/Rule defined on the table TEMP as follows.
    begin
    dbms_fga.add_policy (
    object_schema => 'SCHEMA_NAME',
    object_name => 'TEMP',
    policy_name => 'TEMP_DELETE',
    audit_column => NULL,
    audit_condition => NULL,
    statement_types => 'DELETE'
    end;
    DBA_FGA_AUDIT_TRAIL view can then give you all the information required.
    You will need to have execute privilege on DBMS_FGA package.
    FGA will help if you are on 10g. In 9i it has a limitation – It can only use SELECT and not the other DML operations. So if you are on 9i, follow what the other members have mentioned ‘cause FGA will not be of much help to you.
    I[b] have not used this feature - Maybe you can give it a try and update the forum members. The limitation using FGA is that Auditing on the table is still enabled when ROLLBACK statement is issued.
    My preference will be using this feature instead of writing triggers on the table.
    Try using Google search and get more info on the FGA.. Good Luck !
    Shailender Mehta

Maybe you are looking for

  • Icon Creation Question -- What format are custom shaped icons saved as?

    I have Adobe Photoshop CS and Adobe Illustrator CS. I am assuming that one of those are able to create custom shaped icon format images for using on Mac folders. I am able to save usable icons for folders as .psd format. However, they are always squa

  • Which gl account will be assigned

    hi in account determination EK02   main tran - 3000 down pmt                                                 sub-tran - 0051 down pmt at request, ind cust which gl account can i assign ?

  • Getting error with selectSingleNode in XML DOM

    I have some pages that utilitize the following in XML DOM: loadXML selectSingleNode getElementsByTagName I am using JavaScript. I am getting "undefined" errors. Anyone know the proper syntax/capitalization for these methods when using Safari. I had a

  • Edge Turn-In Shipping Label

    I need a shipping label to turn in my old phone used for Edge up.  The label links included in the recent order under my verizon only include links for returning the new phone.  I need a link that prints a label for a turn-in phone, not a return (pho

  • I want Page Id and Site Id inside the portlet...

    I want my site id and my page id of the page that contains my dynamic page (in form of a portlet) I tried the API portal.wwctx_api.get_query_string inside my portlet to get the same. But when i run it as portlet from the interface, it displays the qu