About database trigger

Suppose I have 2 tables A and B. There are about 40 table
columns for table A and 30 table column for table B. Table A
can insert, update and delete the record from table B. Table A
can insert, update about 15 table columns into table B. I
create database trigger on table A to insert, update and delete.
TAble B can update only 1 table columns into table A. Due to
these 2 tables A and B have update trigger. So it is mutating
when I try to update the record from table A and also update the
record in table B. Please if you have any suggestion, let me
know. I try to work around by creating the package with
variable field set to boolean. But, somehow it only allows to
update from B to A, not from A to B. Thanks in advance.
null

Long Tran (guest) wrote:
: Suppose I have 2 tables A and B. There are about 40 table
: columns for table A and 30 table column for table B. Table A
: can insert, update and delete the record from table B. Table A
: can insert, update about 15 table columns into table B. I
: create database trigger on table A to insert, update and
delete.
: TAble B can update only 1 table columns into table A. Due to
: these 2 tables A and B have update trigger. So it is mutating
: when I try to update the record from table A and also update
the
: record in table B. Please if you have any suggestion, let me
: know. I try to work around by creating the package with
: variable field set to boolean. But, somehow it only allows to
: update from B to A, not from A to B. Thanks in advance.
Hi, I've had this type of mutating table problem before ....
Here's a workaround:
1. Create temporary table to record the changes on the
database triggers (row triggers). Then on a after statement
issue the update statement.
2. Crear package variables at the package specification. Then
create procedures or functions to set this values accordingly
(in before and after trigger statement). Finally use after
statement triggers.
null

Similar Messages

  • How can I create a pdf-report in a database trigger

    Hi,
    how can I create a pdf-file with Reports 9i in a database trigger ?
    Where can I find informations about it?
    Thanks
    Friedhold

    Here would be the place to start.
    If you have existing reports to call, take a look at the JRC

  • Use Host command in Oracle Database Trigger

    I need to run Host command from a database trigger in order to execute a sh file in a Solaris, Unix, environment. How can I do it? The database environment is in Solaris and the database is 10g.
    Please let me know as soon as possible.

    Hi,
    read this <http://devtrigger.blogspot.com.br/2012/08/svn-backup-on-unix-or-solaris.html>
    Or
    you can to run in nohup. For example
    You can a script with the command vi about your trigger and run with the sintaxe bellow:
    nohup sqlplus "/as sysdba" @script.sql &
    Where "script.sql" is the name of the your file.
    Kind regards,
    Bruno Reis.
    www.brunors.com

  • Forms update vs. database trigger

    Hi,
    I learn oracle forms using sample schema HR.
    This schema has a trigger "update_job_history" that fires AFTER UPDATE OF "job_id", "department_id" ON "employees"....
    Now,( in forms) when I want to update just employee's salary trigger fires.
    Forms obviously take all items as being updated as I read from the beginning of error message:
    UPDATE EMPLOYEES SET EMPLOYEE_ID=:1,FIRST_NAME=:2,LAST_NAME=:3,EMAIL=:4,PHONE_NUMBER=:5,HIRE_DATE=:6,JOB_ID=:7,SALARY=:8,COMMISSION_PCT=:9,MANAGER_ID=:10,DEPARTMENT_ID=:11 WHERE ROWID=:12 etc.
    (This error appears only If I update the same employee the second time - that's when a unique key in job_history table gets violated...)
    My question is How can I update only certain items so the triggers fires only when I do update "job_id" or "department_id"
    Is it an issue I should take care of in -pre/on-update triggers?
    Thanks in advance for any suggestion on how to go about this.

    Hello,
    Yah, this will surely help. Sorry for my previous post. I was thinking in terms of PL/SQL, but just consults the forms and it a should work fine.
    Set Update Changed Columns Only to Yes in the following circumstances:
    To save on network traffic, if you know an operator will primarily update only one or two columns.
    To avoid re-sending large items that are not updated, such as images or LONGs.
    To fire database triggers on changed columns only. For example, if you implement a security scheme with a database trigger that fires when a column has been updated and writes the userid of the person performing the update to a table.

  • Multiple Rows Update / Refresh Toplink Query when database trigger involved

    Hi everybody!
    I have two easy troubles for you; the platform is the same as the SRDemo Toplink version.
    1.     Multiple Rows Update: I want to update with mergeEntity method, multiple rows for an isolated table; that method receives a parameter that I try to bind with the iterator "dataProvider" but it only merges the first row, not all, any other combination returns an error.
    What I want to do is to have a form (like tabular forms in Apex) that lets me update multiple rows in a single page. ¿May anyone tell me how to do it?
    2.     Refresh Toplink Named Query: I have a list on a page with two columns. From another page, a button does an action that fires a database trigger that updates one of the columns on the list´s page. When I go back to the list, it is not updated; however, the CacheResults´s property is set to false on the iterator.
    Thanks in advance,
    Alejandro T

    I didn't use it (yet), but - you might take a look. You'll find a [url http://www.oracle.com/technetwork/developer-tools/apex/application-express/apex-plug-ins-182042.html]Timer plug-in on this page. It is a dynamic action which allows you to periodically fire other dynamic actions in the browser. For example use the timer to refresh a region every five minutes. You can perform any dynamic action you want using this infrastructure.So I was thinking: you might use it to run a dynamic action which would check whether something changed in that table (I suppose you'll know the way) (for example, a database trigger might set a flag in some table, timestamp or similar), and - if you find that something really changed - refresh the page.
    As I said, I never used it so that's pure theory. Someone else might know better, though.

  • How to Get  the SSO Logged user information in database trigger

    I need to track which SSO user is inserting data into a table , so how can i get the information of that user in a database trigger on that table
    thanks

    Try using portal30.wwctx_api.get_user returns a varchar2 (PUBLIC) or the Username that is logged in
    I need to track which SSO user is inserting data into a table , so how can i get the information of that user in a database trigger on that table
    thanks

  • How to get SSO logged user information in a database trigger

    my database is 9i
    my application server is 9i too
    I need to track which SSO user is inserting data into a table , so how can i get the information of that user in a database trigger on that table
    thanks

    Hi,
    The only way I could figure out how to get it was to import the com.sap.security.api.
    1. From Window>Preferences>Java-->Classpath Variables, set up a variable called WEBAS_HOME pointing to:
    <drive>/usr/sap/<SID>/jc00/j2ee/cluster/server0/
    2. Right click on properties of your Dynpro Project->Properties->Java Build Path->Libraries and click "Add Variable." 
    3. Select WEBAS_HOME and click "Extend"
    4. Select /bin/ext/com.sap.api.sda/com.sap.security.api.jar and click OK.
    If you don't have access to a portal directory, you will have to get this jar file and copy it to your workspace to add to your build path instead of the above steps.
    Then in your code:
    import com.sap.security.api.IUser;
    import com.sap.security.api.IUserAccount;
      public void GetLogonID( )
         String LogonID;
         try {
              /*     create an user object from the current user */
              IWDClientUser wdUser = WDClientUser.getCurrentUser();
              IUser user = wdUser.getSAPUser();
              if (user != null) {
                   IUserAccount acct = user.getUserAccounts()[0];
                   if (acct != null) {
                        LogonID = acct.getLogonUid();
                   } else
                        LogonID = "acct null";
              } else {
                   LogonID = "user null";
              wdContext.currentContextElement().setDisplayName(user.getFirstName() + " " + user.getLastName());
              wdContext.currentContextElement().setLogonID(LogonID.toUpperCase());
         } catch (Exception e) {
              e.printStackTrace();
    Hope this helps...  I had to search several places before I found all the necessary stuff.  Maybe I can get my first points!
    Thanks,
    Andrew

  • Report in PDF format and email it to some clients, using  Database Trigger

    Hi
    Is it possible to run a report in PDF format ad email it to some clients after a specific event through Database Trigger. For example whenever a client makes an entry into order entry table (through entry form), a trigger should execute on Orders table, this trigger should execute or generate a PDF formatted report and finally mail it to Sales team?
    I have
    ORAS 10g(10.1.2.0.2)
    utl_mail configured.

    In Reportsconfig.properties file the http port is 7778,
    now the output is like this...
    SQL> /
    * WELCOME TO EVENT-BASED-REPORTING API *
    * API-Version : 9i *
    * (C) Oracle Corporation, 2000 - 2002 *
    * Debugging turned ON **************************
    *** Length of Paramlist : 1
    OK : Parameter added : GATEWAY=http://myserver.com:7778/reports/rwservlet
    *** Length of Paramlist : 2
    OK : Parameter added : SERVER=rep_myserver_oracleas2
    *** Length of Paramlist : 3
    OK : Parameter added : REPORT=D:\Reports\emp.rdf
    *** Length of Paramlist : 4
    OK : Parameter added : USERID=abc/xyz@mydb
    *** Length of Paramlist : 5
    OK : Parameter added : DESTYPE=mail
    *** Length of Paramlist : 6
    OK : Parameter added : DESFORMAT=PDF
    *** Length of Paramlist : 7
    OK : Parameter added : [email protected]
    Starting run_report: building url
    *** Building URL (RUN_REPORT)
    OK : URL built :
    http://myserver.com:7778/reports/rwservlet?SERVER=rep_myserver_oracleas2&REPO
    RT=D%3A%CReports%5Cemp.rdf&USERID=abc%2Fxyz%40mydb&DESTYPE=mail&D
    ESFORMAT=PDF&DESNAME=khan.emran84%40gmail.com&statusformat=xml
    *** Submitting HTTP Request
    *** using URL
    :http://myserver.com:7778/reports/rwservlet?SERVER=rep_myserver_oracleas2&REP
    ORT=D%3A%5CReports%5Cemp.rdf&USERID=abc%2Fxyz%40mydb&DESTYPE=mail&
    DESFORMAT=PDF&DESNAME=khan.emran84%40gmail.com&statusformat=xml
    OK : Request submitted - Return stream : <?xml version = '1.0' encoding =
    'ISO-8859-1' standalone = 'yes'?>
    <serverQueues>
    <error code="50159"
    component="REP" message="Executed successfully but there were some errors when
    distribute the output"/>
    <
    OK : Request submitted - Length of stream : 229
    *** XML-Parsed - Following Structure discovered :
    *** Checking elements!
    serverQueues ()
    *** Checking attributes!
    error
    *** Checking attributes!
    __code = 50159
    __component = REP
    __message = Executed successfully but there were some errors when distribute the
    output
    *** Finished Parsing XML
    Getting value for element: job
    Getting value for element: error
    *** Requesting value for Attribute error.component [REP]
    Getting value for element: error
    *** Requesting value for Attribute error.code [50159]
    Getting value for element: error
    *** Requesting value for Attribute error.message [Executed successfully but    
    there were some errors when distribute the output]
    REP-50159:Executed successfully but there were some errors when distribute the
    output
    declare
    ERROR at line 1:
    ORA-20999:
    ORA-06512: at "NRSP.SRW", line 264
    ORA-06512: at "NRSP.SRW", line 799
    ORA-06512: at line 15

  • How can I obtain an specific message raised by a database trigger

    Dear friends,
    if I have a database trigger and I want to show an error message which was raised from a database trigger to a form, I can do it by raising an application error inside database trigger, and by showing DBMS_ERROR_TEXT inside ON-ERROR trigger. This is ok for me.
    But how can I do if I want to show a specific message? Let's say I have a BEFORE INSERT table trigger, and I want to verify whether data was correctly informed (for example, "user name must be entered"). If I raise an application error, I see a very big error message which includes both my personal error message and database message.
    Surely I can do a SUBSTR in this message, but can't I do something easier? Let's say I put all error messages in a variable:
    (Let's suppose it's a BEFORE INSERT trigger code, which is related to my table)
    if :NEW.user_name is null then
    p_error_message := 'User name must be entered.';
    end if;
    if p_error_message is not null then
    raise_application_error (-20000, p_error_message);
    end if;
    ... with this p_error_message being shown to final user, with no need to edit it via PL/SQL instructions like SUBSTR. Is this possible? If not, I'll be quite satisfied with SUBSTR because it fits my needs somehow.
    Best regards,

    raise_application_error will be used for raise errors on form.here i'm providing u the example
    CREATE TRIGGER at AFTER UPDATE OR DELETE OR INSERT ON emp
    for each row
    declare
    v_1 number
    begin
    select empno into v_1 from emp where empno=7369 ;
    exception when no_data_found then
    RAISE_APPLICATION_ERROR(-20001,'No data found'||sqlerrm);
    END;
    now when you insert data on emp table through form. if value does not found of selected empno then No data found will be shown on form
    Edited by: SKYNIAZI on Mar 20, 2009 12:19 PM
    Edited by: SKYNIAZI on Mar 20, 2009 12:56 PM

  • How to specify when clause in a database trigger

    I would like to create a database trigger that only fires on database create statements. In particular, it only needs to fire when tables with a specific prefix fire.
    I'd like to be able to specify something in the when clause along the lines of :
    CREATE OR REPLACE
    TRIGGER CAPTURE_STATS
         after CREATE ON rtrei.schema
         WHEN ( NEW.table_name like 'RT_FOO%' )
    begin
    add_stats_capture( :new.min_range, :new.max_range);
    end;
    It looks like I should be able to use a when as part of a database trigger, but I have no idea what new would be defined to be so that I could use it... perhaps it is an object and the clause would look something like
    when (new.objecttype = 'TABLE' and new.name like 'RT_FOO%')?
    Any ideas? I've searched through the docs, but have not been able to find anything relevant.
    thanks very much,
    Robin

    You can use the WHEN clause with DDL triggers. You can move Todd's IF-THEN clause up into the WHEN clause.
    See http://download-west.oracle.com/docs/cd/B14117_01/appdev.101/b10795/adfns_ev.htm for all of the System-Defined Event Attributes.
    CREATE OR REPLACE TRIGGER capture_stats
    AFTER CREATE ON SCHEMA
    WHEN (ora_dict_obj_type = 'TABLE' AND ora_dict_obj_name LIKE 'RT_FOO%')
    BEGIN
            --Do whatever here.
    END capture_stats;

  • Is there an AUDIT option like AFTER SERVERERROR database trigger?

    I want to log any and every error-exception in a test database for a period.
    I have seen DBMS_UTILITY.FORMAT_ERROR_BACKTRACE article published on Oracle Magazine;
    http://www.oracle.com/technology/oramag/oracle/05-mar/o25plsql.html
    But before trying to build a custom application like this one;
    http://apex.oracle.com/pls/otn/f?p=2853:4:1160653345033883::NO::P4_QA_ID:5922
    1- I wanted to be sure if there is a specific WHENEVER NOT SUCCESSFUL Audit option for this need?
    2- Also is there a way to capture NO_DATA_FOUND exception with AFTER SERVERERROR database trigger?
    Thank you,
    Best regards.

    some stuff like following;
    1)
    -- the right one is conn hr/hr
    conn hr/eychar
    2)
    -- the right one is grant select on employees to public;
    grant select onnnn employees to public;
    3)
    create or replace procedure p1 as
    begin
    raise_Application_error(-20001, 'catch me if you can');
    end;
    exec p1;
    again thank you for your interest Michaels.

  • Primary Key - Generated by database TRIGGER

    Hi,
    I have a form with a block that is attached to a table. So far, nothing fancy :-)
    The Primary is generated with an ORACLE SEQUENCE. That is done at the TABLE level with a DATABASE trigger.
    So in the form, the primary field is not populated.
    Works fine. But if the user wants to UPDATE the forms content, right after they did an INITIAL commit, THEY CAN'T !!!!!!!!!!!
    How can I code this in the form?
    Is there a way to syncronize (populate) the primary key in the form with it's table content?
    If so, how do I query the table if I don't have the primary key value ?
    Thanks for ANY advise,
    Marc.

    Another solution is to use both a database trigger and a PRE-INSERT trigger in Forms.
    The database trigger should be something like
    CREATE TRIGGER INS_TABLENAME BEFORE INSERT ON TABLENAME
    FOR EACH ROW WHEN (new.ID IS NULL)
    BEGIN
    SELECT TABLENAME_SEQ.nextval INTO :new.ID FROM DUAL;
    END;
    and the PRE-INSERT trigger should be something like:
    SELECT TABLENAME_SEQ.nextval INTO :blockname.ID FROM DUAL;
    This way one solves the problem of DML RETURNING VALUE not working in Forms with Oracle version > 8 (does it work on version 8 as it is said to be? - i have not tested it anyway) and the use of other applications (SQL*Plus, JAVA, etc) without writing any code.

  • How to create a database trigger for automatic run statspack.snap

    Hi,
    I want to create a database trigger to run statspack.snap at startup.
    connect /as sysdba
    grant create any trigger to perfstat;
    connect perfstat/perfstat
    create or replace trigger auto_snap
    after startup on database
    begin
    statspack.snap;
    end;
    after startup on database
    error at line 2:
    ora-01031: insufficient privileges
    connect /as sysdba
    create or replace trigger perfstat.auto_snap
    after startup on database
    begin
    statspack.snap;
    end;
    Trigger created.
    after shutdown and startup the database, the trigger has not been run. (no statspack snapshot)
    What I have done wrong?

    981145 wrote:
    hi... I have created a database link but it is showing some error. Can you please tell me, do we have to update the details in TNSNAMES.ora file regarding the database which i am creating now before creating database link?????
    awaiting for your response,
    Thanks in advanceI'm sorry, but "showing some error" is NOT an actionable error message. Why do you think we can solve your error if you don't tell us what the error is?
    Yes you will need to adjust your tnsnames. When a process in a database_A accesses database_B via a dblink in database_A, the database_A is acting as a client to database_B. At that point database_A is just like sqlplus or sqldeveloper, and all tns considerations are the same.

  • Column name as a variable in a database trigger

    I am trying to code a pre-insert database trigger to format all varchar2 columns entered into the triggering table. I am using a cursor to get all the relevant column names from all_tab_columns, but do not know how to refer to these values in combination with the ":new" construct within my code. The example below is a very simplified version of what I am trying to do ( it obviously will not work as it is):
    declare
    cursor column_cur is
    select column_name cn
    from all_tab_columns
    where table_name = 'TEMP_ASSESSMENT'
    and data_type = 'VARCHAR2';
    v_columnname varchar2(30);
    begin
    for column_rec in column_cur loop
    v_columnname := column_rec.cn;
    :new.v_columnname := upper(:new.v_columnname); declare
    cursor column_cur is
    select column_name cn
    from all_tab_columns
    where table_name = 'TABLE_X'
    and data_type = 'VARCHAR2';
    v_columnname varchar2(30);
    begin
    for column_rec in column_cur loop
    v_columnname := column_rec.cn;
    :new.v_columnname := upper(:new.v_columnname);
    end loop;
    end;

    Seems to me like the problem in this thread:
    http://asktom.oracle.com/pls/ask/f?p=4950:8:::::F4950_P8_DISPLAYID:59412348055
    C.

  • Issue in Database trigger for HZ_CUSTOMER_PROFILES PL/SQL: ORA-00936: miss

    Hi
    We are trying to create database trigger on update of table HZ_CUSTOMER_PROFILES when CREDIT_HOLD='Y'
    If this update is done from certain operating unit we are inserting into another custom table when compiling trigger we are getting error as given below
    LINE/COL ERROR
    5/2 PL/SQL: SQL Statement ignored
    17/2 PL/SQL: ORA-00936: missing expression
    SQL> l 5
    5*
    SQL> l 17
    17* COUNTRY,
    Copying code used for creating trigger
    CREATE OR REPLACE TRIGGER "APPS"."SDS_CREDIT_HOLD_ROW"
    BEFORE UPDATE ON HZ_CUSTOMER_PROFILES
    FOR EACH ROW
    WHEN ( new.CREDIT_HOLD='Y')
    BEGIN
    IF FND_PROFILE.VALUE('ORG_ID')=3217 THEN
    INSERT INTO SDS.SDS_CREDIT_HOLD
    (CUSTOMER_NAME,
    CUSTOMER_NUMBER,
    ADDRESS,
    CITY,
    COUNTRY,
    HOLD_BY,
    MAIL_LIST1,
    RESP_VALUE,
    ORG_ID,
    MAIL_LIST2)
    VALUES
    (select rc.customer_name,
    rc.customer_number,
    ra.address1,
    ra.city,
    ra.country,
    fu.user_name,
    fu.email_address,
    TO_NUMBER(FND_GLOBAL.RESP_ID),
    TO_NUMBER(fnd_profile.value('ORG_ID')),
    SDS_EMAIL_ADD_FNC('KAMALAKAR.GUDAPAREDDI,BRIAN.MILLER')
    from HZ_CUSTOMER_PROFILES hcp, ra_site_uses rsa,
    ra_addresses ra, ra_customers rc, fnd_user fu,
    (select distinct site_use_id from HZ_CUST_SITE_USES where site_use_code='BILL_TO'
    and status='A') site_acct
    where hcp.status='A'
    and cust_account_id in (select distinct cust_account_id from HZ_CUSTOMER_PROFILES
    where credit_hold='Y'
    and status='A')
    and hcp.site_use_id=rsa.site_use_id (+)
    and rsa.address_id=ra.address_id (+)
    and rsa.site_use_id= site_acct.site_use_id (+)
    and hcp.cust_Account_id=rc.customer_id
    and hcp.credit_hold='Y'
    and hcp.last_updated_by=fu.user_id
    and hcp.CUST_ACCOUNT_PROFILE_ID=:new.CUST_ACCOUNT_PROFILE_ID
    and hcp.ROWID=:new.ROWID);
    END IF;
    -- commit;
    END SDS_CREDIT_HOLD_ROW;
    tried to search for fix in forums checked all columns in select clause and insert they appear to be fine attaching table structure also for reference
    CREATE TABLE SDS_CREDIT_HOLD
    (CUSTOMER_NAME VARCHAR(50),
    CUSTOMER_NUMBER VARCHAR2(30),
    ADDRESS VARCHAR2(240),
    CITY VARCHAR2(60),
    COUNTRY VARCHAR2(60),
    HOLD_BY VARCHAR2(100),
    MAIL_LIST1 VARCHAR2(240),
    RESP_VALUE NUMBER,
    ORG_ID NUMBER,
    MAIL_LIST2 VARCHAR2(240))
    if any hint for fixing this issue it will be highly appreciated
    Thanks
    Kamalakar.G

    Problem is here:
    WHEN ( new.CREDIT_HOLD='Y')
    Should be using a colon in front of any new or old columns in your PL/SQL and SQL, thus try this:
    WHEN ( :new.CREDIT_HOLD='Y')
    FYI: when using triggers (unless you specify otherwise in the trigger definition itself):
    old values are referenced via :old.column and new values via :new.column

Maybe you are looking for

  • How to pass a parameter into a sql expression?

    How to pass a report parameter into a sql expression?

  • Corrupted Music?

    I was just trying to play some music that I had in my iTunes library when the error message saying the file or directory was corrupt. I had to delete the entire CD from the library because the same message appeared if I tried to play any of the track

  • Find/Replace Missing With New Monitor

    Hi, I've been happily using DW CS4 for about a year now with 2 19" monitors. I recently am stuck using a single 22" monitor which is generally fine, but my Find/Replace window is now missing. I'm assuming it is off somewhere in the 'virtual' screen.

  • Unreliable Internet Sharing in Leopard

    I am having a lot of trouble when attempting to share an Ethernet based Internet connection via the AirPort on my Mac Book Pro. The connection does in fact work, but is very, very slow and unreliable -- especially for email. Web browsing is sort of O

  • PSE 12 freezing

    I have been having some trouble with PSE 12 recently.  I have been using the program for 10 months or so, successfully.   But in recent 2-3 weeks it has been freezing up during photo processing - often when I am using the cloning or spot healing tool