About DDL triggers

create or replace trigger no_create
before create on database
begin
raise_application_error(-20500, 'This is a before trigger...:' || ora_dict_obj_name );
end;
create table deletemenow(one varchar2(40));object not created...great thats what i wanted
create or replace trigger no_create
after create on database
begin
raise_application_error(-20500, 'This is a after trigger...:' || ora_dict_obj_name );
end;
create table deletemenow(one varchar2(40));object not created, but doesn't this trigger fire after the object is created and so shouldn't the table be created anyway since the trigger fires too late! So how does this trigger actually work?
If i run this....
create or replace trigger no_create
before create on database
begin
raise_application_error(-20500, 'This is a before trigger...:' || ora_dict_obj_name );
end;....and then i try to run
create or replace trigger another_no_create
before create on database
begin
raise_application_error(-20500, 'This is a before trigger...:' || ora_dict_obj_name );
end;
ERROR at line 2:
ORA-00604: error occurred at recursive SQL level 1
ORA-20500: This is a before trigger...:ANOTHER_NO_CREATE
ORA-06512: at line 2...make sense. But if i execute this...
create or replace trigger no_create
before create on database
begin
raise_application_error(-20500, 'This is a before trigger...:' || ora_dict_obj_name );
end;...no problem, why is this (pretty smart of Oracle actually)?
Cheers
Gus

If the trigger throws up an exception which is successfully handled by the trigger the DML that caused the trigger will complete successfully. If not the DML within the trigger and the DML that caused the trigger will fail :)
I don't need a lesson in triggers from you Justin, all i was raising was the fact that DDL statements have an implied commit and so to write an AFTER DDL trigger seemed a bit like writing an AFTER SHUTDOWN trigger. I know thats not how its handled but you seemed to have missed the question...why, is there a reason
When the second trigger succeeds, thats becaause you
are replacing the old trigger (CREATE OR REPLACE).
It would be pretty silly if Oracle didn't allow you
to modify a particular database object.I don't see it that way (CREATE OR REPLACE) is not a MODIFY as you seem to think, its a CREATE OR REPLACE.
Gus

Similar Messages

  • DDL Triggers and Detecting sp_rename

    I am trying to use DDL triggers to detect all changes to a table.
    Sometimes a user directly or (more likely) through the SQL Server Management Studio GUI renames a column via sp_rename.
    I can't seem to figure out how to detect such renames using a DDL trigger.  Is there any way or is this a limitation of the DDL trigger system?

    You can call it a limitation
    https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=124493&wa=wsignin1.0
    Madhu

  • Q? Determining event in DDL Triggers

    Hi All,
    I've noticed references in the 8i documentation to DDL triggers. In the SQL reference there is mention that you can:
    CREATE TRIGGER xyz AFTER DDL
    pl/sql block
    (or something similar, I typed this my memory)
    Which is all great except that it doesn't explain how you find out what caused you to fire.
    In a DML trigger, which I am familiar with,
    you can do useful things because you have :new and :old values. Is there a :ddl that lists the statement that fired?
    Does anyone have sample code of a ddl trigger?
    Thanks in advance,
    Steven Ensslen

    AFTER DDL is just one of the possible clause that can be used. There are may ddl where you can specify the excat ddl action. When you have specified the ddl, ofcorse you know how did the tirgger fired! I am including the documentation section on ddl clause.
    Let me know if this solved your problem.
    ---Doc section---
    Specify one or more types of DDL statements that can cause the trigger to fire. You
    can create triggers for these events on DATABASE or SCHEMA unless otherwise
    noted. You can create BEFORE and AFTER triggers for these events. Oracle fires the
    trigger in the existing user transaction. The following values are valid:
    ALTER Specify ALTER to fire the trigger whenever an ALTER statement
    modifies a database object in the data dictionary.
    Restriction: The trigger will not be fired by an ALTER DATABASE
    statement.
    ANALYZE Specify ANALYZE to fire the trigger whenever Oracle collects or
    deletes statistics or validates the structure of a database object.
    ASSOCIATE
    STATISTICS
    Specify ASSOCIATE STATISTICS to fire the trigger whenever
    Oracle associates a statistics type with a database object.
    AUDIT Specify AUDIT to fire the trigger whenever Oracle tracks the
    occurrence of a SQL statement or tracks operations on a schema
    object.
    COMMENT Specify COMMENT to fire the trigger whenever a comment on a
    database object is added to the data dictionary.
    CREATE TRIGGER
    CREATE Specify CREATE to fire the trigger whenever a CREATE statement
    adds a new database object to the data dictionary.
    Restriction: The trigger will not be fired by a CREATE DATABASE
    or CREATE CONTROLFILE statement.
    DISASSOCIATE
    STATISTICS
    Specify DISASSOCIATE STATISTICS to fire the trigger whenever
    Oracle disassociates a statistics type from a database object.
    DROP Specify DROP to fire the trigger whenever a DROP statement
    removes a database object from the data dictionary.
    GRANT Specify GRANT to fire the trigger whenever a user grants system
    privileges or roles or object privileges to another user or to a role.
    NOAUDIT Specify NOAUDIT to fire the trigger whenever a NOAUDIT
    statement instructs Oracle to stop tracking a SQL statement or
    operations on a schema object.
    RENAME Specify RENAME to fire the trigger whenever a RENAME statement
    change the name of a database object.
    REVOKE Specify REVOKE to fire the trigger whenever a REVOKE statement
    removes system privileges or roles or object privileges from a user
    or role.
    TRUNCATE Specify TRUNCATE to fire the trigger whenever a TRUNCATE
    statement removes the rows from a table or cluster and resets its
    storage characteristics.
    DDL Specify DDL to fire the trigger whenever any of the preceding DDL
    statements is issued.
    Restriction: You cannot specify as a triggering event any DDL operation performed
    through a PL/SQL procedure.

  • Doubts about applet triggering

    Hello guys,
    I was wondering, when I have my applet assigned to be triggered by a EVENT_UNFORMATTED_SMS_PP_ENV or even a EVENT_FORMATTED_SMS_PP_ENV, I mean, the applet being triggered by a SMS-PP message, what happens when I send two consecutive messages, i.e., when I send the second message and the applet is still processing the first one, what happens to the second message? is it lost by the ME or it is kept in some sort of buffer and re-sent to the applet when the applet finishes the process?
    As there are no threads on Java Card so both messages can't be processed at the same time...
    Thank you,
    Helri

    This is too broad a question.
    Toad can fire random sql.
    sql*plus can fire random sql.
    Why would Toad be the problem?
    You would need to gather statspack data to demonstrate this.
    Sybrand,
    Agreed on it and its a relevant point.But I guess he is not worried about the db performance.Anyways lets see what OP says.
    Inner join and left join will always use CBO (Cost Based Optimizer) instead of RBO.
    I am not sure that I have read that anywhere. They came into Oracle in 9i where optimizer mode was choose as the default one. Just by the syntax, oracle would push them to use CBO as the default one,I am not sure about this. Even if we are having + symbol and have the stats,Oracle wold go for CBO right?Can you please point me to some where in the docs where it is mentioned that using this keywords,Oracle would use only CBO?
    Aman....

  • Ddl triggers froma dump file

    I have a dump file made with exp command. It is a schema dump.
    I would like to extract the ddl of the trigger. how can I do this?
    I tried with imp + indexfile
    but I the file created there are no triggers.

    Why not use dbms_metadata.get_ddl('TRIGGER','<TRIGGER_NAME') to generate the ddl and create.

  • Worried about _blank triggering a popup blocker

    Im thinking about building an HTML/CSS page that would rely on _blank quite a bit.
    Clicking on the pagelinks and opening new pages... but all within the same domain.
    Do popup blockers only target javascript popups? Or popups that take you to other domains?
    Im just wondering if there are any rules or guidelines for popup blockers from a design/developer side of things.

    Anything scripted to an on page load action will be blocked.... or on click or anything of that nature...
    Automatic pop-up ads (on page load) will be defeated.  If user initiates them with onClick event, they will appear as expected.
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    http://alt-web.com/
    http://twitter.com/altweb

  • About DDl and Dml Operations On B1

    Hi ,
    I had Created A form In SDk Using UiAPI, It Contains Five Text Fields And One Button. And I had Created An EMP Table.It Contains Five Fileds. My Question Is:----
    >
    When I clicked Button , The data Entered In TextFields(EditText) Need To stored in Database.  Similirly All The Operation Need To Do. How Can we Do In sdk. Please tell Me code
    Regards
    Srinivas

    Srinivas,
    Please look at the subject of "Binding Items to Data SourcesBinding Items to Data Sources" in the SAP Business One SDK Help Center Documentation.  This should assist you and show you code samples.
    Eddy

  • About transactional Triggers

    Hai All,
    Can any one tell me what is transactional trigger and when to use it???
    Thanks
    Sriram.

    Is it possible for you to start with an Oracle Forms 10g Starters-Course at Oracle University? 5 days and after that you know Forms very good. If you do the course here in cologne - then I'm your trainer :-)
    if it's not possible we well help you as good as we can...
    have fun
    Gerd

  • How to get information about time of triggering and entire time waveform

    I have been trying to capture a certain portion of waveform from Textronix DPO2024 using triggering in Labview. Further, I want to save the the entire triggered waveform (triggered time as one array and triggered signal amplitude as second array)  in .xlxs format.
    With the present setup (screenshot, and output of program attached). I only get the triggered portion of signal, I get time stamp (that I do not want) but require the time array, instead.
    I know there are methods to convert the timestamp to time array. I do not want to use this, as I need to capture the data every 10 ms  or even faster, and this slows the acquisition process.
    Any help will be much appreciated.
    Thanks

    Hi Dennis,
    Thank you for the response.
    Please find the .vi attached. In the case - without triggered, with the information of dt and length of Y, we can determine the time waveform (as calculated using matlab script on right). But in the presence of triggering, neither  the length of waveform nor the start time of triggering is known, so calculating the time waveform is tricky. In addition, since the waveform is continuously changing, and keeping trigger fixed at a particular level,  the length of waveform is also changing in some of the acquisition. So I wanted  a 'simple' method where I can get the time information about the triggered waveform in each acquisition.
    More specifically, I wanted help in regard to getting time array of the triggered signal and save it as a column in excel file.
    Thanks

  • How to find the user whom you made any DDL changes in my pl/sql objects

    Hi,
    I am having oracle 10G set up in my server.Somebody did some DDL activities in my PL/SQL objects and it become invalidated, I want to find which oracle user did a modification.
    Any one can help me regarding this..
    Thanks in advance
    Karthik...

    Unless you had auditing turned on or DDL triggers in place, you will not be able to tell after the fact.

  • Triggers to insert the record in a table

    I have two table 1. Holiday 2. Attendance.
    When I insert the record    in holiday table for his
     advance holiday   with empid, the same time I want to insert it attendance table
     automatically for the same date using a trigger
    Insert into attendance (empid,date,holiday) values (20078,07/10/2014,1). If holiday column value 1 represent holiday marked,
     0 represent  holiday not marked. The same thing can happen vice versa
    If employee mark his current attendance as  holiday through attendance,
     it should   be  inserted into holiday table 
    automatically using triggers.
    Insert into  Holiday (empid,date,holiday) values (20078,06/08/2014,1). If holiday column value 1 represent holiday marked,
     0 represent  holiday not marked. The same thing can happen vice versa
    Please I am looking for your help , how I can make it using triggers 
    to insert both table  in two different ways of options.
    Regards
    Pol
    polachan

    Hi polachan,
    According to your description, if you want to synchronize the data between the holiday table and the attendance table while inserting records into holiday table, you need to create a trigger on the holiday table, please try the following syntax.
    use <databasename>
    go
    create trigger Tr_holiday
    on holiday
    for insert
    as
    declare @empid varchar(20),
    @date datetime,
    @holiday int
    select @empid = empid, @date=date, @holiday=holiday from inserted
    declare @qty int
    select @qty =count(*) from attendance where empid=@empid and date=@date and holiday=@holiday
    if @qty<1
    begin
    insert into attendance
    select i.empid,
    i.date,
    i.holiday
    from inserted i
    end
    Meanwhile, if you want to insert the record into the holiday table when holiday is updated to 1 in the attendance table, you need to create another trigger on the attendance table, please try the following syntax.
    use <databasename>
    go
    create trigger Tr_attendance
    on attendance
    for update
    as
    declare @holiday int
    if update (holiday)
    begin
    select @holiday=holiday from inserted
    if @holiday=1
    begin
    insert into dbo.holiday
    select empid,
    date,
    holiday
    from inserted
    end
    end
    For more details about creating triggers in SQL Server, please review this article:
    CREATE TRIGGER (Transact-SQL).
    Thanks,
    Lydia Zhang

  • How to restrict the developers to do DDl Operations on the tables

    Dear All,
    Even i restricted the developers to do DDL operations by updating CHAR_VALUE=disabled in the table SQLPLUS_PRODUCT_PROFILE table in system/manager schema.
    So, now the users are unable to do DDL operations from PLSQL Developer, iSQLPLUS and command prompt.
    But they are doing their DDL Operations from the Java application, i don't know how they are doing this.
    But how can i restrict them
    Thanks
    Mahipal Reddy

    It does not make sense to attempt to restrict users by using security in a tool - like using SQLPLUS_PRODUCT_PROFILE for SQL*Plus. Whoever the person who designed this at Oracle was, needs to be introduced the wrong end of a lead pipe. It is nonsensical to approach security in that fashion.
    As for restricting DLL, there are numerous levels that this can be dealt with inside Oracle. From simply not granting a CREATE TABLE statement, to using schema/DDL triggers.
    But seeing that you have this problem, I'm betting that it's as a result of a flawed open door Oracle security policy.
    You should start at beginning. Determine what the security requirements and access levels are, and then implement these properly in Oracle. Using a DLL trigger for example, is often an exception when it comes to a proper security model implementation in Oracle.

  • Don't know which triggers to use, please help.

    Hi,
    I'm a newbie to forms. I have a question about what triggers to use for my situation. I can't seem to find many examples for what I want to accomplish. I have tried using the online help (within forms) but sometimes they don't always have examples for their triggers).
    Here's my scenario:
    I have six items, five of which are text database items and one is a non-database display item (TOTAL). Each of the first 5 items holds a numeric value and the TOTAL item will store the sum of the previous 5. Of first 5 items, only the 4th item (POINTS) can be updated within the form (and I have set the Enabled propety to 'No' for the first 3 items). I have a function, TOTAL_COUNT, that will do the sum calculation and it works fine in a POST-QUERY trigger populating the value into TOTAL. However, what I'd like to do is anytime a user enters a new value in POINTS and then tabs or mouse clicks into the next item TOTAL, I'd like to call my function to update and display the new total value in TOTAL.
    Does anyone know which triggers and/or code I can use to accomplish this? The code I use to call a function is:
    :block_name.item := function_name(:parameter)
    For your recommed triggers, can I just use that code to call my function or will I need any other syntax i.e. BEGIN...END, etc within the trigger body?
    Any quidence would be greatly appreciated.
    Thank you,
    Eric

    Hi!
    1. Set Calculation Mode property of ITEM_5 to Formula.
    Formula property:
    nvl(:Block_Name.ITEM_1, 0) + nvl(:Block_Name.ITEM_2, 0) + nvl(:Block_Name.ITEM_3, 0) + nvl(:Block_Name.ITEM_4, 0)
    OR
    Function_Name(Param_1,... Param_N);
    Have in view of, that the ITEM_5 data will not be saved in DataBase.
    2. When-Validate-Item trigger is usfull when is necessary to store calculated item data in DataBase.
    Rename you Post-Query trigger to When-Validate-Item.
    Modify trigger: Store calculation result in the variable.
    (Don't forget to round variable value!)
    Then compare it with ITEM_5. If they are different - :ITEM_5 := var_name.
    I prefer the first method.

  • Help on DML Triggers On Schema

    All,
    We are in the process of implementing audit table for specific schemas:(user1 120 tables)
    I was successfully able to create DDL Triggers on the Schema with ----- DDL ON SCHEMA
    but for tracking DML operations on each table by different users in user1 schema... do i need to create individual trigger for each table...
    BEFORE INSERT OR UPDATE OR DELETE ON <TABLE_NAME>
    is this the only way...
    Any Ideas?
    Regards,
    ~Ora

    Hi,
    as you said in your first post, for DDL operations you can use SCHEMA a level trigger, but for DLM operations you will have to stick with one trigger per Table.
    Here is some piece of code to generate the triggers for you.
    drop type line_tt;
    create or replace type line_t as object (x varchar2(4000));
    create or replace type line_tt as table of line_t;
    create or replace function generate_audit_triggers return line_tt pipelined
    is
           cursor my_tables is
                  select user as owner, table_name from user_tables where temporary = 'N';
           cursor my_table_cols(tablename in varchar2) is
                  select column_name from user_tab_columns where table_name = tablename order by column_name;
           sqlstatement varchar2(4000);      
           wherestatement varchar2(4000);
    begin
         for r_table in my_tables loop
             -- generate code for insert trigger
             pipe row(line_t('create or replace trigger ' || r_table.owner || '.' || substr('SPYI_' || r_table.table_name, 1, 30)));
             pipe row(line_t('before insert on ' || r_table.owner || '.' || r_table.table_name));
             pipe row(line_t('for each row'));
             pipe row(line_t('begin'));
             pipe row(line_t('insert into AUDIT_DATA(sqlstatement) values('));
             sqlstatement := '''insert into ' || r_table.owner || '.' || r_table.table_name || '(';
             for r_column in my_table_cols(r_table.table_name) loop
                 sqlstatement := sqlstatement || r_column.column_name;
                 sqlstatement := sqlstatement || ',';
             end loop;
             sqlstatement := substr(sqlstatement, 1, length(sqlstatement) - 1);
             sqlstatement := sqlstatement || ') values ('''''' || ';
             for r_column in my_table_cols(r_table.table_name) loop
                 sqlstatement := sqlstatement || ':new.' || r_column.column_name;
                 sqlstatement := sqlstatement || ' || '''''','''''' || ';
             end loop;
             sqlstatement := substr(sqlstatement, 1, length(sqlstatement) - 10);
             sqlstatement := sqlstatement || ''''');''';
             pipe row(line_t(sqlstatement));
             pipe row(line_t(');'));
             pipe row(line_t('end;'));
             pipe row(line_t('/'));
             -- generate code for update trigger
             pipe row(line_t('create or replace trigger ' || r_table.owner || '.' || substr('SPYU_' || r_table.table_name, 1, 30)));
             pipe row(line_t('before update on ' || r_table.owner || '.' || r_table.table_name));
             pipe row(line_t('for each row'));
             pipe row(line_t('begin'));
             sqlstatement := 'if (';
             for r_column in my_table_cols(r_table.table_name) loop
                 sqlstatement := sqlstatement || '''a''|| ' || ':old.' || r_column.column_name || ' <> ''a''|| :new.' || r_column.column_name || ' or ';
             end loop;
             sqlstatement := substr(sqlstatement, 1, length(sqlstatement) - 4);
             sqlstatement := sqlstatement || ') then';
             pipe row(line_t(sqlstatement));
             pipe row(line_t('insert into AUDIT_DATA(sqlstatement) values('));
             sqlstatement := '''update ' || r_table.owner || '.' || r_table.table_name || ' set ';           
             wherestatement := ' where ';
             for r_column in my_table_cols(r_table.table_name) loop
                 sqlstatement := sqlstatement || r_column.column_name || '=''''' || ''' || :new.' || r_column.column_name || ' || '''''',';
                 wherestatement := wherestatement || '''''a''''||' || r_column.column_name || '=''''a''''||''''' || ''' || :old.' || r_column.column_name || ' || '''''' and ';
             end loop;
             sqlstatement := substr(sqlstatement, 1, length(sqlstatement) - 1);
             wherestatement := substr(wherestatement, 1, length(wherestatement) - 5);
             sqlstatement := sqlstatement || wherestatement || ';''';
             pipe row(line_t(sqlstatement));
             pipe row(line_t(');'));
             pipe row(line_t('end if;'));
             pipe row(line_t('end;'));
             pipe row(line_t('/'));
         end loop;
    end;
    show err
    drop table audit_data;
    create table audit_data (
           sqlstatement varchar2(4000)
    spool tmp.sql
    set head off
    set linesize 500
    set echo off
    select x from table(generate_audit_triggers);
    spool offHope this helps,
    Francois

  • What is triggering

    hai,
    tell me about the triggering of clients in jms..
    thanking u..

    hai,
    tell me about the triggering of clients in jms..
    thanking u..What do you mean?
    If a client is connected to jms and listening to it, client can be triggered if message is inserted in jms.
    Depending upon the type of jms, how you do it depends.

Maybe you are looking for