Help on the DML triggers on schema

All,


We are implementing for the specific patterns of audit table:(user1 120 tables)

I was able to successfully create on the schema DDL triggers with - on SCHEMA DDL

but for the follow-up of DML operations on each table by different users user1 schema... do I have to create an individual trigger for each table...

Before INSERT OR update OR DELETE ON < table_name >

is this the only way...

Any ideas?

Kind regards
~ Ora

Hello

as you said in your first post, for DDL operations, you can use a trigger level of SCHEME, but for DLM operations, you will have to stick to a single trigger per Table.

Here is a 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 off

Hope this helps,
François

Tags: Database

Similar Questions

  • Help on the software triggers the analog output...



  • I have the table of 3 columns A, B, C. I want to store the sum of columns A B in the C column without using the DML statements. Can anyone help please how to do. ?

    I have the table of 3 columns A, B, C. I want to store the sum of columns A B in the C column without using the DML statements. Can anyone help please how to do. ?

    11.1 and especially you have virtual column

    SQL> create table t
      2  (
      3     a number
      4   , b number
      5   , c generated always as (a+b) virtual
      6  );
    
    Table created.
    
    SQL> insert into t (a, b) values (1, 2);
    
    1 row created.
    
    SQL> select * from t;
    
             A          B          C
    ---------- ---------- ----------
             1          2          3
    

    Before that, a front insert - trigger

    SQL> create table t
      2  (
      3     a number
      4   , b number
      5   , c number
      6  );
    
    Table created.
    
    SQL> create or replace trigger t_default before insert on t for each row
      2  begin
      3    :new.c := :new.a+:new.b;
      4  end;
      5  /
    
    Trigger created.
    
    SQL> insert into t (a, b) values (1, 2);
    
    1 row created.
    
    SQL> select * from t;
    
             A          B          C
    ---------- ---------- ----------
             1          2          3
    
  • How to copy all the tables, triggers, etc, from a schema from one user to another

    Hello everyone!

    I'm looking for a QUERY or a stored procedure to copy the tables of a schema of the user to a different schema.

    Should resemble the kind of: copy (select * from object where owner = 'UserIwantToCopyFrom') user = "UserIwantToCopyTO".

    I'm sure that my example is rubbish, but I tried to explain what I want to do.

    Then there is a chance to do in sql code? I have to build a model of a schema of the user with hundreds of tables, triggers, etc. and copy it into several other user patterns.

    Thanks for your advice!

    Jan

    There are many examples available.
    What you generally want to do is:

    For the export, use the job_mode-online option "SCHEMA".
    Example of export

    http://www.oracle-base.com/articles/10g/OracleDataPump10g.php
    
    DECLARE
      l_dp_handle       NUMBER;
      l_last_job_state  VARCHAR2(30) := 'UNDEFINED';
      l_job_state       VARCHAR2(30) := 'UNDEFINED';
      l_sts             KU$_STATUS;
    BEGIN
      l_dp_handle := DBMS_DATAPUMP.open(
        operation   => 'EXPORT',
        job_mode    => 'SCHEMA',
        remote_link => NULL,
        job_name    => 'EMP_EXPORT',
        version     => 'LATEST');
    
      DBMS_DATAPUMP.add_file(
        handle    => l_dp_handle,
        filename  => 'SCOTT.dmp',
        directory => 'TEST_DIR');
    
      DBMS_DATAPUMP.add_file(
        handle    => l_dp_handle,
        filename  => 'SCOTT.log',
        directory => 'TEST_DIR',
        filetype  => DBMS_DATAPUMP.KU$_FILE_TYPE_LOG_FILE);
    
      DBMS_DATAPUMP.metadata_filter(
        handle => l_dp_handle,
        name   => 'SCHEMA_EXPR',
        value  => '= ''SCOTT''');
    
      DBMS_DATAPUMP.start_job(l_dp_handle);
    
      DBMS_DATAPUMP.detach(l_dp_handle);
    END;
    /
    

    for import, you can use the remap_schema option with:

    DBMS_DATAPUMP.METADATA_REMAP (
       handle      IN NUMBER,
       name        IN VARCHAR2,
       old_value   IN VARCHAR2,
       value       IN VARCHAR2,
       object_type IN VARCHAR2 DEFAULT NULL);
    

    There are many more details in the document as provided Thierry.

  • With the help of the TYPE operator % on objects in another schema

    Suppose I have the following architecture:
    * A schema called APP_SCHEMA (for example), which contains all applications level PL/SQL packages that contain a business application logic
    * A data schema, called DATA_SCHEMA (for example), that contains the schema objects that are referenced by the PL/SQL in APP_SCHEMA
    Suppose I create a simple procedure like this in the APP_SCHEMA:
    CREATE OR REPLACE PROCEDURE test_proc(pVar IN DATA_SCHEMA.TABLENAME.TABLECOLUMN%TYPE)
    AS
    BEGIN
         DBMS_OUTPUT.PUT_LINE(pVar);
    END;
    /{code}
    For this simplified procedure I get the following error:
    {code:java}1/25     PLS-00201: identifier 'DATA_SCHEMA.TABLENAME' must be declared{code}So, my basic question is how do I use the %TYPE operator to reference objects in another schema?
    
    Other Pertinent info:
    * Windows Server 2003
    * Oracle Database 10gR2 (10.2.0.3)
    Thanks!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

    Its almost certainly a problem of privileges.

    I can create a test procedure based on the same script that compiles successfully.

    Verify that your user can access the table. Might need to have to grant access directly, rather than in a role.

    Published by: Keith Jamieson on August 25, 2008 17:51
    typo fixed

  • Play with the Windows 7 color scheme will affect my TV on different entries or overall?

    Hello, I have a Samsung LED Tv connected to my PC. Asked me to change my color scheme I did. Play with the color scheme of Windows 7 will not affect my TV in any way other than the PC itself. I want to assure you that it don't mess with any setting on my TV or other inputs for my TV, like the brightness, color, etc.

    Hello

    Thanks for posting the request in the Microsoft community forums!

    The problem description, I understand to be aware if the Windows 7 mess with any settings on Samsung LED Tv. color correct me if I'm wrong.

    We look at this, it seems that the settings on Samsung LED Tv will not get affected by the arrangement of color of computer.

    We know if you need help with the Windows operating system. We will be happy to help you. We at Microsoft, strive for excellence and provide our customers with the best support.

  • Help of the trigger

    Need help a trigger that I created.  The public synonym was created and "run" privilege has been granted on the package.

    CREATE or REPLACE PACKAGE in the BANINST1.pzhepaf


    procedure P_norroutEPAFROUT
    (epaf_trans_no, norrout.norrout_transaction_no%type,
    epaf_recipient_user_id norrout.norrout_recipient_user_id%type,
    epaf_action_user_id norrout.norrout_action_user_id%type,
    epaf_alvl_code norrout.norrout_alvl_code%type,
    epaf_action_ind norrout.norrout_action_ind%type,
    epaf_que_stat_ind norrout.norrout_queue_status_ind%type,
    epaf_appr_level_no norrout.norrout_level_no%type,
    PIDM spriden.spriden_pidm%type);

    -Definition settings:
    -Epaf_trans_no REMARKS transaction number
    -epaf_recipient_user_id REMARKS recipient identifier
    -epaf_action_user_id REMARKS action user ID
    -level approval of REMARKS epaf_alvl_code code
    -indicator epaf_action_ind of action REMARKS
    -indicator of State epaf_que_stat_ind REMARKS queue
    -Number of level epaf_appr_level_no REMARKS approvingly
    -employee pidm pidm

    END pzhepaf;

    /

    DROP TRIGGER POSNCTL. PAFROUT_UPDATE;

    CREATE OR REPLACE TRIGGER POSNCTL. PAFROUT_UPDATE
    after update to norrout_action_ind on posnctl.norrout
    for each line
    Start
    If goksyst.f_isSystemLinkEnabled ('WORKFLOW') then
    pzhepaf. () P_norroutEPAFROUT
    : new.norrout_transaction_no,.
    : new.norrout_recipient_user_id,.
    : new.norrout_alvl_code,.
    : new.norrout_action_ind,.
    : new.norrout_queue_status_ind,.
    (: new.norrout_level_no);
    end if;

    end;

    Hello

    955990 wrote:

    Sorry I'm new and have never posted anything.

    Really?  The site believe that you have been posting things for 2012.

    APEX

    This is the error I get:

    [Error] PLS-00201 (5.5): PLS-00201: identifier ' PZHEPAF. P_NORROUTEPAFROUT' must be declared

    Well, now post other information mentioned in answer #2 above.

    Answer the questions Kendenny asked in reply to #4

    What is goksyst.f_isSystemLinkEnabled?

    Is goksyst a diagram or a package name?

    If the pr is a procedure in package pa and sc is the owner of this package, then the usual way to call the procedure of other schemes is

    SC.PA. PR (args);

    There are ways to call using only 1 '.'  You use one of them?  Which?

  • Procedure with the DML statements that insert values from 1 to 100 in only one table and it is matching word equivalent in the other

    Can someone help me create a procedure with the DML statements that insert values from 1 to 100 in a table "abc" and the procedure must connect the numbers into words in another table "xyz" without doing a commit explicitly. "."

    Currently on trial...

    SQL > create table abc (num number);

    Table created.

    SQL > create table xyz (num varchar2 (100));

    Table created.

    SQL > ed
    A written file afiedt.buf

    1. insert all
    2 values of 1 = 1 then in abc (num) (l)
    3 when the values of 1 = 1 then in xyz (num) (to_char (to_date(l,'j'), 'jsp'))
    4 * Select the level from dual connect by level<=>
    SQL > /.

    200 rows created.

    And the result...

    SQL > select * from abc;

    NUM
    ----------
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    ..
    ..
    ..
    98
    99
    100

    100 selected lines.

    SQL > select * from xyz;

    NUM
    ----------------------------------------------------------------------------------------------------
    one
    two
    three
    four
    five
    six
    seven
    eight
    nine
    ten
    Eleven
    twelve
    ..
    ..
    ..
    98
    Nineteen eighty
    Cent

    100 selected lines.

  • Hello need help with the opacity mask.

    Hello need help with the opacity mask. I hope someone out there can help

    I inherited a logo that appears to use a Logo of OM has a shape with a grad. This grad at first sight is not used in the Grad scheme and there is not editable.  Looking at the transparency palette I find an OM (pic1) output option. If I choose what the grad on separates it from the page of the form, that is from there I can change/remove as required (Note2).

    However, sometimes (he did no change), I'll be back to the same original form and output option is grayed out and is no longer available. Or I go to the similar shape that has the same treatment and I can't go out OM (pic3)

    The only difference is the thumbnail in the transparency palette, which is strong in pic1 and rated on pic3. What Miss me?    I'm not clear what the advantage is simply OM using the Grad palette to apply a grad in my form, but until I can get rid of OM who is there, I can't comfortably apply to the grad I want.

    The white gradient LHS I have no problem with. I choose fortunately only and each time get the possibility of release of OM.

    Screen Shot 2015-08-06 at 12.26.48.pngScreen Shot 2015-08-06 at 12.00.10.pngScreen Shot 2015-08-06 at 12.01.16.png

    The other thing weird. When I select the white gradient. Sometimes, the exit option is in the palette without going through the drop-down list (Fig 4).

    Other times seems not that OM has already been applied, because the palette gives me the ability to mask rather than liberation (5 photos). Until I go to the drop down and then I find Release is an option after all.

    What is the difference here?   Not much of a problem, because either way I can release OM to be able to change the grad.

    The file is passed through several hands and play anywhere to try to resolve issues, and many stops and save slot, so something along the line was of course done a logo and not the other because of the difference, but I can't for the life of me see what that.

    Screen Shot 2015-08-06 at 12.44.21.pngScreen Shot 2015-08-06 at 12.44.36.png

    I hope someone can help. Very appreciated


    See you soon

    Dave

    Dave,

    I've (mis) understanding the issues, you can account for the box to the right in the main palette transparency (called thumbnail) here.

    Illustrator help | Transparency and blending modes

    represents the masking objects.

    Some of your screenshots show no object mask, so it only is not really a mask even if do the opacity mask has been clicked and there seems to be one in the layers palette, wherever you look.

    I think that it is perhaps the issue.

  • monitor the DML operation for a table, that is, monitor the type time and DML operation

    Hello expert,

    I want to follow the DML operation for a table, i.e. monitor the time to type and the DML operation. you tell please how do I get that?

    Thank you very much

    See if this can help you:

    http://Oracle-Apps-DBA.blogspot.com/2007/07/monitoring-DML-operations.html

    Kind regards

  • Access to the content of the tables of a schema into another schema

    Hello

    I have my doubts... Suppose I have a user called DEMO and it has tables. now I have another user called DEMO1

    my doubt is. How can I get the DEMO user tables in DEMO1. If updating the table DEMO1 which should reflect

    DEMO user. Help me...

    Dear friend,

    You can consult the tables of a schema in another schema using the following steps.

    (1) you must grant privileges on table demo Demo1, here's the statement to do so.

    Grant Select, update on the table table_name to Demo1

    (2) Create in Demo1 for the table_name demo, the suite is about education to do.

    SYNONYM to CREATE or REPLACE table_name for Demo.table_name;

    (3) do the Update statement on the table table_name in Demo1. Updated these results reflected in demo when you post the update statement in Demo1.

    Hope that gives you an idea.

    Kind regards
    Ravi Kumar Ankarapu.

  • reading of the objects in another schema schema

    My requirement is to create a schema and grant privileges to read all objects in another main schema, including the functions and procedures. creating a role and assigning it to the schema will read or select the tables, but she will not allow the user to see the description of a function, or a procedure. can you please tell me what are my options. Thank you.

    Hello

    Yes you can GRANT SELECT privilege to allow access to Tables / views, and GRANT EXECUTE privilege on the procedures in another schema.

    You can also CREATE SYNONYM of these Tables in order to hide their location. There is a way to ensure the transparency of the location, otherwise use views or procedures.

    These links can give you a few tracks on the transparency of the situation and manage privileges:

    http://download.Oracle.com/docs/CD/B28359_01/server.111/b28310/ds_admin006.htm

    http://download.Oracle.com/docs/CD/B28359_01/network.111/B28531/authorization.htm#DBSEG004

    Hope this helps.
    Best regards
    Jean Valentine

  • validation to a specific table only and simple a question on the dml trigger

    Hi all

    guess I am connected to a database with the user ' scott'/'tiger'@orcl and I have the fire instructions insert on 2 different tables allows say tables is
    (1) emp
    (2) Dept.

    and now I want only to commit the emp table and not the table dept, is it possible to do?

    Another question, I have... are commit simple dml triggers auto or not?

    Concerning
    Rahul

    Mac_Freak_Rahul wrote:

    and now I want only to commit the emp table and not the table dept, is it possible to do?

    No, it isn't. You post a transaction, not a table...
    So if you have handled several tables in your transaction, you agree to be all these changes (via the command commit), or any of them (via restore).

    >

    Another question, I have... are commit simple dml triggers auto or not?

    If your dml trigger manipulate data (a very bad practice by the way), then they just add to all of the changes made to the breast of your transaction, you (as mentioned above), either commit all or none.

  • The drop-down list schema lists (with the name/value pairs)

    Hello

    I'm looking for more information on creating a schema type definition that LiveCycle Designer ES will fill (fill in the name and value) of drop-down lists. For example, I have something like:

    < xsd:simpleType name = "RoleTypeCodeType" >
    < xsd:restriction base = "xsd:token" >
    < value xsd: Enumeration = 'ABC' >
    < xsd: annotation >
    < xsd: documentation >
    Aboriginal community
    < / xsd: documentation >
    < / xsd: annotation >
    < / xsd: Enumeration >
    < value xsd: Enumeration = "ADJ" >
    < xsd: annotation >
    < xsd: documentation > referee < / xsd: documentation >
    < / xsd: annotation >
    < / xsd: Enumeration >
    ...

    < xsd:minLength value = "1" > < / xsd:minLength >
    < xsd:maxLength value = "3" > < / xsd:maxLength >
    < / xsd:restriction >
    < / xsd:simpleType >

    This creates a list. I can bind this to a list field. However, of course, when I saw the pdf, my drop down list items in this area are just the three-letter code. I would get the descriptions associated with these articles (as shown on the connection tab) to be filled. The end result is that my list see 'Indigenous community', 'referee', etc. and when selected, return 'ABC', 'ADJ' in the XML during export.

    If list under the connection tab items are filled manually then this export works correctly. However, the list is generated during execution and dynamic. So nobody knows what the schema definition must be for the field in the list on the LiveCycle form to create the name-value pairs?

    Thank you

    John

    Hi John,.

    You will need to incorporate the schema, but you can reference the imported schema as they get integrated as well (there a bug in the designer when they were not integrated, but I think it crept in 8.0).

    In any case to refer to the imported schema you will need to loop though all schemas

    var

    schemas = xfa.resolveNodes('schema[*]');

    Will give it refers to all schemas, the fine loop them;

    for

    (var schemaIndex = 0; schemaIndex< schemas.length;="">

    So if these patterns have an id attribute (I don't think that you can refer to namespace attributes) test the value of the id;

    If

    (schema.@id is "whateveryourschemaidis")

    If there is no attribute ID and you cannot add a you might have to search for the type in each scheme, something like;

    var roleTypeCodeType is schema.xsd::simpleType. (@name is "roleTypeCodeType");

    If (roleTypeCodeType! == undefined)

    {

    ... load the values of the annotation.

    }

    Hope that helps but if you if you can post your schema (and it's imports), I could understand exactly the problem.

    Bruce

  • READ the TABLE of another schema

    Hello
    pls help me.

    I want to read the table of another schema that is declared in the application of the apex.

    SELECT * FROM DBA_ROLE_PRIVS;
    (SELECT * FROM sys.) DBA_ROLE_PRIVS: auch bad)

    The owner of this table is SYS.

    Error: The Table is unknown or cannot be found.

    my real schema is GCs.

    How is the select statement for this case for reading in the table (or tableview) of another schema?
    many and many thanks for your help.
    TL

    The SYS schema is a special schema in Oracle. You must explicitly grant the user rights by selecting tables and views sys.

Maybe you are looking for

  • No sound notification or screen for text

    If this problem just started today. I have an iPhone 6 and I get no sound notification for text, my husband sent me but there is sound when I receive calls from him or anyone else. Another strange thing, it's that they are not pop up on the screen of

  • Satellite A300 1lW - installation of Windows 7 - any questions?

    Good morning/afternoon! I would like to install a new internal hard drive on my laptop and I want to put windows 7 on it. The problem is that it is the first time that I'm going to do this and I Don t really know what kind of functionality will be in

  • Cannot see or download photos from my iphone to my MacBook

    When I plug my iPhone into my MacBook I can't put new photos on my Mac because he doesn't 'see' it in Photos.  He used to see and I would like to transfer photos.  It's not just my phone but all my other phones and iTouch.  She also does not come to

  • Want 4500 All in 1: replace the cartridge when its brand new

    Replace the black cartridge that came with it initially with a 61 new Staples Black.  Now the display shows "the following ink cartridge needs to be replaced" and there the symbol for black. I've sat down and reinstall the cartridges, cleaned the con

  • Is Stopzilla a reliable anti-virus product?

    I have Microsoft Security Essentials and Windows Defender on my computer. Should I still have an anti-virus program. I StopZilla but I can't install it if I don't. Thank you