Create trigger for after insert update

i have table tt (id number (10), name varchar2(20), status varchar2(1) , stage varchar2(1))
when i insert data in table tt
id name status stage
1 anil a
then trigger fire and update same value of satge to status
like
1 anil a a
pls give example

Hi,
please try this code:
CREATE OR REPLACE TRIGGER <tiggername>
AFTER INSERT OR UPDATE
ON TT
FOR EACH ROW
DECLARE
v_Status varchar2(10);
BEGIN
-- Insert record into audit table
INSERT INTO orders_audit
( id,
name,
stage)
VALUES
( :new.id,
:new.name,
:new.stage);
select stage into v_status
from tt where stage = new.stage
update tt set status = v_status where id = new.id
END;

Similar Messages

  • Bc4j bug at refresh after insert / update

    having a table and a trigger on it that fills an attribute
    in a 9i db. one can take the scott/tiger emp table and use the
    following trigger:
    create or replace trigger t_bri_emp
    before insert on emp
    for each row
    declare
    v_no number(7,2);
    begin
    select user_SEQ.nextval*100
    into v_no
         from dual;
    :new.sal := v_no;
    end;
    then creating a bc4j project with an entity object based on this table (emp)
    and a view object based on the created entity object.
    !!!! when you create the bc4j project you must set the SQL Flavor to SQL92 or OLite
    when you set the attribute settings, for the attribute the trigger is on (sal),
    to refresh after insert / update or both in the entity object you get a
    null pointer when you try to insert a new row and commit.
    java.lang.NullPointerException
         oracle.jdbc.ttc7.TTIoac oracle.jdbc.ttc7.TTCAdapter.newTTCType(oracle.jdbc.dbaccess.DBType)
         oracle.jdbc.ttc7.NonPlsqlTTCColumn[] oracle ....................
    all can be reproduced just useing the wizard and start the bc4j project with the tester
    any workaround ??

    Sven:
    I looked into your issue. It turns out your problem is caused by a bug in the system (bug #2409955).
    The bug is that for non-Oracle SQLBuilder, we are not processing refresh-on-insert and refresh-on-update attributes correctly. We end up forming an invalid SQL statement and the JDBC driver gives the obscure NullPointerException.
    Thus, until 9.0.3, you should not use refresh-on-insert/update attributes on a non-Oracle SQLBuilder.
    If you need the refresh-on-insert/update attribute, here is a possible workaround:
    1. Whenever you invoke the tester, on the first panel, click on the 'Properities' tab. In the list of properties, you should find one for 'jbo.SQLBuilder'. It will say 'SQL92'. Remove it, so that it is empty. Run test tester. Then, the tester will use Oracle SQLBuilder which will handle refresh-on-insert/update attributes correctly for you.
    2. For switching between Oracle SQLBuilder and SQL92 SQLBuilder, you can try the following:
    2a) Locate bc4j.xcfg and your Project??.jpx under your 'src' directory.
    2b) Make copies of these files.
    2c) Edit them so that you have one set for Oracle SQLBuilder and one set for SQL92 SQLBuilder. For Oracle SQLBuilder, make sure these files do NOT have entries like:
    <jbo.SQLBuilder>..</jbo.SQLBuilder> in bc4j.xcfg and
    <Attr Name="_jbo.SQLBuilder" Value="..." /> in Project??.jpx
    When there is no jbo.SQLBuilder entry, BC4J will default to Oracle.
    For SQL92, make sure you have
    <jbo.SQLBuilder>SQL92</jbo.SQLBuilder> in bc4j.xcfg and
    <Attr Name="_jbo.SQLBuilder" Value="SQL92" /> in Project??.jpx.
    Before you run, decide which SQLBuilder to use (for 9.0.2, with retrieve-on-insert/update attrs, you have no choice but to use Oracle SQLBuilder) and copy these files into your class path, e.g.,
    <jdev-install-dir>\jdev\mywork\Workspace1\Project1\classes
    When you get 9.0.3, then you should be able to switch between Oracle and SQL92 SQLBuilders freely.
    Thanks.
    Sung

  • Mutating table exception on trigger with After Insert but not with before

    Hi
    I need to maintain some constraint on the table to have only one row for values of the columns but not by primary key constraint.
    Because in case of primary key the insert would fail and the rest of the operation would be discontinued, I cannot change in the somponent that inserts the row so I have to prevent that on the table I have.
    I created a before insert trigger on the table which checks if any row exists in the table with same column values as the one being inserted. if found I delete the rows and let the insert happen (w/o raising any error). if the rows do not exist then the insert shall be continued.
    I read at place that modifying the dame table in the trigger body shall raise a mutating table exception, but I donot get the exception when the trigger is fired.
    Just when I change the trigger to after insert trigger then the nutating table exception is thrown.
    Is it the right behavior i.e. the Before insert trigger does not raise the exception and only after insert does that, since I could not find the example for before insert triggers throwing such exception so I think it is better to confirm it before finalizing the implementation.
    Thanks
    Sapan

    sapan wrote:
    Hi Tubby
    I cannot user unique constraint because that would raise an exception upon violation and the third party component that is inserting in the table would fail.
    That component does some other tasks as well after this insert and if an exception is raised then those tasks would not be performed.
    Also I cannot change the component to ignore this exception.Well then, you're in a bit of a pickle.
    I'm guessing the trigger you have been working on isn't "safe". By that i mean that it doesn't account for multi-user scenarios. You'll need to serialize access to the data elements in question and implement some sort of locking mechanism to ensure that only 1 session can work with those values.
    After you work out how to do that it sounds as though you would be better served using an INSTEAD OF trigger (you'd need to implement this on a view which is made off of your base table).
    Here's one way you can work on serializing access to your table on a relatively fine grained level (as opposed to locking the entire table).
    Re: possible to lock stored procedure so only one session may run it at a time?
    Cheers,

  • Response.write after insert/update

    Hi
    Could anyone please show me how to do a response.write message on the page after insert/update?
    Wondering especially about the placement and the syntax of the response.
    DWCS5, Access, Asp
    Christian

    I'm sorry to say I don't know how to test values in ASP, have just started to use it.
    I didn't get it to work so I threw away the code and went for an ordinary text response on a second page.
    Might as well get a book and read up on it

  • What mechanism Oracle 10g use for write (Insert/ Update) and Read (Select)?

    Hi
    What mechanism Oracle 10g use for write (Insert/ Update) and Read (Select)?
    Thank you

    Aren't the answers given in PL/SQL forum sufficient enough?Well, as the first answer in that forum directed the OP to this forum you can hardly blame them for the repost.
    There is some high-level stuff in the Concepts Guide. If that is insufficient the OP will need to tell us what more details they need to know (and perhaps why).
    Cheers, APC

  • ORA-29532 exception from after insert update trigger

    Trigger code:
    CREATE OR REPLACE TRIGGER SAMS.PERS_ALG_AIU_TRG
         AFTER INSERT OR UPDATE
              ON PERS_ALG
              FOR EACH ROW
    DECLARE
         trans_type          VARCHAR2(1);
         event_id          CONSTANT VARCHAR2(7) := 'A31_ZA1';
         data_src          CONSTANT VARCHAR2(15) := 'SI_A31_ZA1_VW';
         p_row_id          ROWID;
         select_stmt          VARCHAR2(5000);
         XMLString          CLOB;
    BEGIN
         IF INSERTING THEN
              trans_type := 'I';
         ELSE
              trans_type := 'U';
         END IF;
    SELECT ROWID
    INTO p_row_id
    FROM personnel
    WHERE pers_seq = :new.pers_seq;
    select_stmt := 'SELECT * FROM si_a31_ZA1_vw WHERE start_date = MAX(start_date) AND ROW_ID =chartorowid('''||p_row_id||''')';
         -- Produce the XML
    XMLString := si_lib.get_XML(select_stmt);
         -- Insert the transaction
         INSERT INTO si_transaction (transaction_type, event_id, status_id, timestamp, transaction_xml)
              VALUES ( trans_type, event_id, 'CR', SYSDATE, XMLString);
              EXCEPTION
                   WHEN OTHERS THEN
                   RAISE_APPLICATION_ERROR (-20040, sqlerrm);
    END;
    ... is causing ORA-29532 JAVA call terminated by uncaught java exception: java.lang.nullPointerException
    any ideas --- get_XML actually calls dbms_xmlquery.getXML

    When in doubt, break it into pieces and test the pieces. The following is not valid:
    SELECT * FROM si_a31_ZA1_vw WHERE start_date = MAX(start_date)
    Try replacing the above with:
    SELECT * FROM si_a31_ZA1_vw WHERE start_date = (SELECT MAX(start_date) FROM si_a31_ZA1_vw)

  • After insert & update trigger

    I need to write a trigger that if some columns of the master table have changed, the trigger will first insert the change to a copy table. Later on, if there are more changes to the master of the same row, it will compare the new value to the old value and delete the same row in the copy table and insert the latest change. I have wrote the following trigger. Some how when I run it, it has compilation error. Does anyone have any idea on how should I approach this?
    create or replace trigger TRITON.AFTER_INSERT_UPDATE_ITM001100after insert or update on TRITON.TTIITM001100for each rowdeclarev_reflag char(1);beginv_reflag:='0';if (:new.T$ITEM != :old.T$ITEM or :new.T$DSCA != :old.T$DSCA) then
    delete from ticcrm.ttiitm001100_copy;
    insert /*+append*/ into ticcrm.ttiitm001100_copy(T$ITEM, T$DSCA, T$DSCB, T$DSCC, T$DSCD, T$WGHT, T$SEAK, REFLAG)values(:new.T$ITEM, :new.T$DSCA, :new.T$DSCB, :new.T$DSCC, :new.T$DSCD, :new.T$WGHT, :new.T$SEAK, v_reflag);
    end if;
    end;
    /

    delete from ticcrm.ttiitm001100_copy;
    insert /*+append*/ into ticcrm.ttiitm001100_copy(T$ITEM, T$DSCA, T$DSCB, T$DSCC, T$DSCD, T$WGHT, T$SEAK, REFLAG)values(:new.T$ITEM, :new.T$DSCA, :new.T$DSCB, :new.T$DSCC, :new.T$DSCD, :new.T$WGHT, :new.T$SEAK, v_reflag);
    This is simple SQL statements, not PL/SQL.
    Use EXECUTE IMMEDIATE for executing it.
    P.S. Please do not forget to make good formatting of your code before posting it.

  • Trying to create trigger for some action to take place after a user logs on

    Hello,
    I want to create a trigger to fire after a user logs on. How to write this trigger.
    I am getting an error with syntax below. Thank you.
    create or replace trigger after_logon_xxtestuser
    after logon
    on xxtestuser.xxtestuser
    begin
    alter session set nls_territory = France;
    end;
    /

    I figured it out...
    create or replace trigger after_logon_xxtestuser
    after logon
    on xxtestuser.schema
    begin
    execute immediate 'alter session set nls_territory = France';
    end;
    /

  • Got problems with creating RTF-files after OSX update

    Hi
    I don't know if this is really a MAC OS problem, but it occurred after I updated to 10.5.2 - so it's a likely suspect.
    Since the update I can't create RTF-files any more with Final Draft, my script writing program. A file is created, but when I try to open it I get an error message that it cannot be found. But the file is there: I can see it and click on it. It just won't open.
    Only today now I got the same error message with a doc-file I downloaded some months ago.
    The only big change I lately made to my Mac was the update to 10.5.2 and I got the new Office 2008 (both are the German versions). Could the problem come from either of them? I contacted Final Draft's support - they didn't know of the problem.
    Maybe someone else in this forum has encountered similar problems?

    Have you tried to Repair Permissions using Disk Utility?
    1. Open Disk Utility in your Applications/Utility folder.
    2. Click on the icon for your boot volume.
    3. Click on the First Aid tab and select Repair Permissions
    4. Click the repair permissions button.
    This is the first thing to try whenever any program goes wonky. It's free, but takes awhile for all the files that have to be checked and changed.

  • (Automatic) Refresh of Cached object after insert/update

    Hi,
    (I am using Toplink 9.0.3 against an Oracle Database)
    I am inserting and updating records in the database through objects registered in a TopLink UnitOfWork. I happen to know that certain database columns will get a (changed) values because of Database triggers.
    Is it true that the only way to get these changed values reflected back to the TopLink cache is by explicitly executing a
    session.refreshObject();
    call for every object changed in the UnitOfWork?
    Is there no way to inform TopLink (for example through the descriptors for the relevant classes) that for certain classes after the insert/update an automatic synchronization with the database must be performed?
    I have not been able to find such a setting, but I may have overlooked it - I hope I did.
    Thanks for your help,
    Lucas Jellema (AMIS)

    In this case use a postMerge event -- it will get called after the merge of the cache and then you could update the object explicitly.
    Ultimately, the way to achieve the behavior you're looking for is events or refreshing.
    - Don

  • Refreshing the RowSetBrowser webbean after insert/update(?)

    How do I refresh the RowSetBrowser web bean after inserting or updating and committing a record thru the EditCurrentRecord web bean?
    I am unable to see the new record added in the RowSetBrowser unless I close the browser and re-enter.
    Any advice would be appreciated!
    null

    after you call to iniatialize() in the DWB, you can refresh the cache by calling
    <%
    dbw.getRowset().executeQuery();
    %>

  • JDBC usage techniques for multi insert/update operations

    Hi,<br /><br />I have a scenario wherein I have the following xml format(simplified version)<br /><br /><student><br /><examHeader><br /> <examNo>EX123</examNo><br />  <examMajor>IndustrialChemistry</examMajor><br />  <studentNo>AS221</studentNo><br />  <status>submitted</status><br /></examHeader><br /><examDetails><br /> <Questionnaire><br />     <answers><br />          <answer><br />               <questionId>12</questionId><br />               <questionVersion>1</questionVersion><br />               <requestId>refnumber</requestId><br />               <response>Y</response><br />               <comment>Default</comment><br />          </answer><br />     </answers><br /></Questionnaire><br /><br /> <br />Now I need to update the header details into 1 table and the details content into multiple table for each question/answer combination.<br /><br />What would be the best way to achieve this ? interms of performance and also reusablilty wise ?<br /><br />I can think of an SQL execute component to perform this , but it would be a series of sql inserts as the tables have foreign key relationships.<br /><br />how do we extract the repeatable data and insert into database in an efficient way ?<br /><br />Any help would be greatly appreciated.

    Hi Senthil
    You have two options:
    1. Create a counter, and a loop in your orchestration. Loop through the rows in your XML, and on each iteration, perform the SQL statement you require. This can be a bit fiddly, but does work.
    2. This pattern comes up often enough to warrant us having built a component to automate it. We have a component that does this in a single step - it's called "XML2SQL". You can download it here:
    http://www.avoka.com/apps/checkcookie?qpac=y&qpac_code=avokaESComponents&location=%2Fapps% 2Fqpacdownload
    More info here:
    http://avoka.dnsalias.com/confluence/display/Public/XML+to+SQL+DSC
    Howard
    http://www.avoka.com

  • Unable to Create Wifi Hotspot after OS update

    I have just updated the OS on my Q5 to 10.2.424.  When I now try to create a WIFI Hotspot I get the message"Regulations in this country prohibit Mobile Hotspot usage."  This is not true and how do I roll back to the previous OS to get this working again?

     Apparently do do not know quite what a WiFi hotspot is. You don't create one on your computer you can access one if there is one in the vicinity of your computer. Read this for better understanding:
    http://en.wikipedia.org/wiki/Hotspot_%28Wi-Fi%29

  • No database update after insert / update

    Dear all..
    I have created a small report for storing additional invoice text into a z-table. These invoice text could have the lenght of 2560 character and are needed for EDI transmission.
    Directly after saving - I can view them.  After some hours I am always getting empty fields wenn I try to view the data. ... for me it looks like that the table entries are buffered but nor really stored into database. Does a commit work solves this problem ?
    Thanks in advance
    Jürgen

    hi,
    you say :
    Directly after saving - I can view them.
    how? with se16 or program?
    -> try to work with offset
    A.

  • Execution time for an insert/update

    Hello!
    We are using EJB entities 3.0 and JPA configured to run on WAS and DB2. We also are using Container Managed Persistence
    We have a transactional method let's name it addA(), when executed, ultimately inserts data in 11 DB2 tables.
    In some of the 11 tables there are could be multiple rows inserted, in average, about 2 inserts.
    We are using the EntityManager.persist method to handle each entity.
    The method completes in about 11 seconds when the resources on the server (CPU,memory) are in a good state (so not overloaded).
    Is this a reasonable/decent time for the operation we are trying to do?
    If not, what would be a reasonable running time for such an operation?
    What do we need to do in order to improve the performance and decrease the execution time, other than switching to BMP and coding manual SQL inserts?

    user2617486 wrote:
    Do you have any idea how we can localize/isolate better the problem at the DB level?
    Can we programatically insert log statements to see how long it takes the processing on the WAS and how long takes the actual SQL statements execution once they hit the DB2 database?You need help from a DBA, you can't reason this problem away. You need cold hard facts from whatever tooling the database provides. Of course you could try adding log statements to see how long each database operation is taking on the Java side of things, but that only proves that it is slow, not WHY it is slow.
    The network latency can not be considered in this case since we run the test application on the same WAS where the application resides so it no networking involved.and the database runs on that machine as well? This is new information you are pulling out of your hat by the way, now all of a sudden there are two applications? And with the limited information you give I am to assume you are having performance problems from the test application and not from your "main application"? Otherwise I see no point in you making this argument.

Maybe you are looking for

  • How do I move multiple clips at once in the project rather than one a time?

    I know how to cut and then paste to move one clip within the project to a new place within the project, but how do I move a group all at once rather than one at a time?

  • [SOLVED] Openbox+Thunar, how to show usb devices in thunar?

    Hi.  I've been running a pretty standard Xfce environment for a while.  When I plug in a usb drive, I get a new item pop up in the "DEVICES" section of the left panel in thunar (note, it doesn't automount the device, it just shows that it's there and

  • PO with Order Acknowledgment

    Hi experts, Please help me with the following: I have created a PO and entered the AB confirmations for this PO. Now I want to reduce the quantity in the PO from 10 PC to 5 PC. I have previously enterd the AB confirmation for 10 PC. Now I get the err

  • App server , process scheduler , web server and DB scripts

    Team, Good Morning. I am looking for the script which will help me in doing health check-up for app server , process scheduler , web server and DB. The script should trigger a email when any one of the domain is down and when it get up. Waiting heart

  • Query is not behaving properly

    Hi All, I have 1 row in tag readings table and statuses table is empty .If I run INCR then instead of 1, 2 same rows get populated in statuses table.Below is the query: MERGE INTO MTH_EQUIP_STATUSES o USING ( SELECT r.EQUIPMENT_FK_KEY, s.SHIFT_WORKDA