Update happens in trigger

Hi
If the update happens on the (suppose emp table ) first time of the day
(first time of every day)
insert the records into emp_tar table
if it is second time need to update
Pls let me know.
Regards,

Hi
I am getting the error while updating (featch returns more than one row) in the trigger.
so i impliment cursor.
pls sugget the way is right
CREATE OR REPLACE TRIGGER tri_name
AFTER INSERT OR UPDATE
ON emp_dept REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
v_emp_dept_hist NUMBER(5);
v_Day_DIM_FROM_ID date;
cursor c1 is SELECT Day_DIM_FROM_ID FROM emp_dept;
BEGIN
IF INSERTING THEN
INSERT INTO emp_dept
VALUES (:NEW.EMP_NO,:NEW.DEPT_NO,to_date('1/1/1900','MM/DD/YYYY'),to_date('12/31/9999','MM/DD/YYYY'),SYSDATE);
ELSIF
open c1;
loop
fetch c1 into v_Day_DIM_FROM_ID;
EXIT when C1%NOTFOUND;
v_Day_DIM_FROM_ID = to_date('1/1/1900','MM/DD/YYYY') THEN
Update emp_dept --here i am getting the error so i use cursor
Set
Day_DIM_TO_ID = trunc(sysdate) - 1;
INSERT INTO emp_dept
VALUES (:NEW.EMP_NO,:NEW.DEPT_NO,sysdate,to_date('12/31/9999','MM/DD/YYYY'),SYSDATE);
end loop; -- can i use end loop here
else
INSERT INTO emp_dept VALUES (:NEW.EMP_NO,:NEW.DEPT_NO,SYSDATE,to_date('12/31/9999','MM/DD/YYYY'),SYSDATE);
END IF;
Thanks in advance
END;

Similar Messages

  • After update row level trigger help

    Hello,
    I have to update some data on a table. I need to be able to undo the update just in case something goes wrong after update is comitted. I decided to keep track of updated rows by inserting new and old values on a audit table using UPDATE ROW LEVEL trigger. Everything working fine as I wished, but here is what I am having a problem in separating each bulk of update by a unique ID... I am not talking about any primary key or autogenerated sequence key here.
    Audit table inserts values: primary key of table, old value before update, new value after update, and time stamp. Now, I want add one more field on the audit table that indentifies each bulk of UPDATE operation... I tried to use session ID, it works fine, but sometimes I may update two or three times, maybe around same time, on the same day from the same session (timestamp doesn't help me). In that case, each UPDATE operation inserts the same session ID on Audit table. I won't know which update operation populated which row of the audit table.
    Can somebody give me how I can resolve this situation. Again, this has to be inside the trigger. Is there any other IDs that I can use? I would appreciate your help. Thanks,

    Can you add a table level trigger in addition to your row level trigger? If so, you could do what you want in there. In the new trigger, formulate a unique value (such as session id || sysdate) and store it using dbms_application_info.set_module and set the MODULE to that value. Then, in your row level trigger code, execute dbms_application_info.read_module and pull the MODULE value and insert it into your audit table.
    The use of session id || sysdate should be fine (and unique) in this context. You'd just have to know at what time the UPDATE batch occurred that you wanted to undo.
    By the way, you could use LogMiner to do what I think you're trying to create with the use of your trigger code and table entries. Recall the Oracle keeps the undo and redo data for every row that is updated in the redo/archive logs. Using LogMiner, you could find and undo any change from any time. Just like your method, you'd have to know when the "bad" thing occurred in order to find the correct log and "mine" it, but all the functionality is there. There's a kinda old, but very good, article by Arup Nanda at http://www.oracle.com/technology/oramag/oracle/05-jul/o45dba.html that reviews how it all works. You may want to look at it to see if you can avoid re-inventing the wheel to meet your needs. Just a thought....
    Karen

  • Using an on update or insert trigger on a SAP table

    Hi all,
    A question for you regarding using a database trigger in and SAP system. 
    We are needing to export data for our datawarehouse.  Currently we export all the data.  That data is getting quite large tho and time is becoming an issue.
    One suggestion has been to add a custome field to an existing SAP table to hold a flag to indicate the record has changed but not been extracted.  Thenput a trigger on the table in question so that the new field is updated upon update or insert of the record.  Then when the extract runs, it will only extract those records with the flag set, then reset the flag.
    we are using ERP 6 and SQL Server 2005 (or soon to as we will be upgrading next month).
    Any suggestions regarding triggers?  Or other options for flagging changed records in large table so we don't have to extract all records every time?
    Thanks
    Laurie
    Edited by: Laurie McGinley on Oct 27, 2008 10:51 PM

    Hi Laurie,
    just really shouldn't consider to put triggers into your application.
    The problem here is the very nature of triggers to do things 'in the background'.
    If you have problems due to the trigger, you won't see it anywhere in the SAP environment.
    In a while you probably forget about the trigger at all and then nobody can see, what is happening to the database, just because something is changed "in the background".
    Besides that you don't get support for this from SAP, you will make your life a lot harder.
    Tabledefinitions may change - your trigger might break.
    Put application logic where it belongs - to the application layer!
    regards,
    Lars

  • Event for infotype 1001 updates doesn't trigger

    Hi everyone,
    I'm facing the following problem at HR Workflow
    I've created the object ZEHSBUS900, subtype of PDOTYPE_SH. And so, created two events: NOTIFYCREATE and NOTIFYUPDATE.
    At SWEHR3 transaction, I have this two entries:
    S     Position     1001     Relationships     A003     Belongs to     INS          0     ZEHSBUS900     NOTIFYCREATION
    S     Position     1001     Relationships     A003     Belongs to     UPD          0     ZEHSBUS900     NOTIFYUPDATE
    But when I create or update an infotype 1001, only the NOTIFYCREATION is triggered. I mean, the UPD operation doesn't work.
    What is stange is that I've made this kind of implementation at another system and it's working fine ( a creation at 1001 triggers NOTIFYCREATION and modifications trigger NOTIFYUPDATE ).
    Do you know what could be missing?
    Thanks in advance,
    Raphael Xavier

    Hi Abdullah!
    Thank you for the tip, but it still doesn't work this way. As what I've said before, what is strange is that problem occurs in one system and didn't occur in another one, and the same procedure was used in both.
    What I did to "solve" this was using a function instead calling the event at SWEHR3. In this function there is a verification if it is an insert ou update operation and then a call to the function SWE_EVENT_CREATE.
    It wasn't the best solution, but still was a solution.
    If anyone has any idea what it can be, I'm still interested about it.
    Raphael

  • Insert, update and delete trigger over multiple Database Links

    Hello guys,
    first of all I'll explain my environment.
    I've got a Master DB and n Slave Databases. Insert, update and delete is only possible on the master DB (in my opinion this was the best way to avoid Data-inconsistencies due to locking problems) and should be passed to slave databases with a trigger. All Slave Databases are attached with DBLinks. And, additional to this things, I'd like to create a job that merges the Master DB into all Slave DB's every x minutes to restore consistency if any Error (eg Network crash) occurs.
    What I want to do now, is to iterate over all DB-Links in my trigger, and issue the insert/update/delete for all attached databases.
    This is possible with the command "execute immediate", but requires me to create textual strings with textually coded field values for the above mentioned commands.
    What I would like to know now, is, if there are any better ways to provide these functions. Important to me is, that all DB-Links are read dynamically from a table and that I don't have to do unnecessary string generations, and maybe affect the performance.
    I'm thankful for every Idea.
    Thank you in advance,
    best regards
    Christoph

    Well, I've been using mysql for a long time, yes, but I thought that this approach would be the best for my requirements.
    Materialized View's don't work for me, because I need real-time updates of the Slaves.
    So, sorry for asking that general, but what would be the best technology for the following problem:
    I've got n globally spread Systems. Each of it can update records in the Database. The easies way would be to provide one central DB, but that doesn't work for me, because when the WAN Connection fails, the System isn't available any longer. So I need to provide core information locally at every System (connected via LAN).
    Very important to me is, that Data remain consistent. That means, that it must not be that 2 systems update the same record on 2 different databases at the same time.
    I hope you understand what I'd need.
    Thank you very much for all your replies.
    best regards
    Christoph
    PS: I forgot to mention that the Databases won't be very large, just about 20k records, and about 10 queriees per second during peak times and there's just the need to sync 1 Table.
    Edited by: 907142 on 10.01.2012 23:14

  • WHEN DOES UPDATE  HAPPEN IN JDBC SENDER Adapater

    Hi folks ,
    I am using jdbc sender adapater to call RFC function and the o/p pf the RFC i am writing to the file
    This is my select query
    SELECT * FROM ULIDTA2.F5631505 WHERE QSINTF='N'
    and mu update query is
    Update ULIDTA2.F5631505 set QSINTF='Y' where QSINTF='N'
    now the slect returns multiple rows and  i  want the rfc to be called depending on the number of rows i get 4m select . but wht is happening is i find that seleect picks the first row calls the rfc writes to the file and updates the query .
    hence other rows are not able to be processed .
    does jdbc sender update as soon as it picks the select query . how do i update one row at a time .
    thks
    amit

    Hi Amit,
    I dont think one row at a time is possible with the SELECT query as the JDBC adapter is going to return all the rows that satisfy your query.
    One work around would be to develop a Stored Procedure in your Datbase, and then use the same Stored Procedure as your select query. Now, tits the task of the stored procedure to make sure only one row is selected at a time.
    Just look at Query SQL Statement part ubnder this link,
    http://help.sap.com/saphelp_nw04/helpdata/en/7e/5df96381ec72468a00815dd80f8b63/content.htm
    Regards,
    Bhavesh

  • Updating field using trigger

    I have a very basic table with four fields, DateReturned DueDate, daysoverdue and days. I am trying to use the following code to calculate the difference between the two dates and enter the result into days overdue. After this calculation I want to transfer only the positive values into the days field.
    Calculation 1 - based on When-Button-Pressed
    update test1 set daysoverdue = RETURNDATE - DUEDATE;
    I can get this to work using the formula option in Property Palette - is there any way I can use an if statement. I only really want to calculate days overdue if the return date is after due date so that I have positive values only - this would avoid the need for calculation two.
    Calculation two - - based on When-Button-Pressed
    update test1 set days = RETURNDATE - DUEDATE
    where daysoverdue >0;
    When I compile and press the button - my application crashes. I can run the code via SQLPlus and it works.
    What I would really like to do is the run the code automatically then the records are called up into the form. Any ideas and suggestions welcome. My PC that I am using is old and is a W2K machine with 256mb Ram and Approx 600Mhz processor.
    This is my first application I am developing so if I have left out information - sorry.

    my small advice is , pls do not write any
    insert , update or delete in forms
    if you want to do that pls call a database procedure
    for ex
    pls call a foll procedure in when-button-pressed
    trigger
    dp_update_overdue;
    and write the foll script in your oracle database
    create or replace procedure dp_update_overdue
    is
    begin
    update test1
    set daysoverdue = returndate- duedate
    where returndate > duedate;
    commit;
    end;
    bye
    pasupathy

  • 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.

  • Update audit table trigger by a column

    Have a need to update a audit table when a specific column data has been updated\deleted\inserted on table T1 . The column is Grade_complete.
    My first thought was to create an instead of trigger since the form was based on the table (T1) view
    ( CREATE OR REPLACE TRIGGER "AI_T1" AFTER INSERT OR UPDATE OF grade_complete ON T1........) but then I realized with instead of , I can't create a trigger with a update of . Can anyone give me some suggestions on how to resolve this ? There got to be something easy that I am just not getting it now.
    Thanks.
    Wan

    Jure, Roel;
    Thanks for the reply.
    I have no permission to create triggers on the table so instead of being used. when ran the following statement , I am getting "ORA-25004: WHEN clause is not allowed in INSTEAD of triggers. Have tried if statement to no avail. Can anyone help ?
    create or replace trigger ioft_test
    instead of insert or update or delete on T1
    referencing old as old new as new for each row
    when nvl(new.grade_complete, 0) != nvl(old.grade_complete, -1)
    declare
    v_seq number;
    begin
    insert statemetn here
    end;

  • Updated column in trigger

    Hi,
    How can i know if a particular column is updated in trigger ?
    Thanks

    Hi,
    I don't have the manual page handy, but search in the CREATE TRIGGER statemenet manual page, and you'll find out pretty quick.
    Little hint:CREATE OR REPLACE TRIGGER mtrig
      BEFORE UPDATE ON mtab
      FOR EACH ROW
    BEGIN
      IF (:OLD.col != :NEW.col) THEN
         NULL; -- value of mtab.col is being updated!
      END IF;
    END;
    /Regards,
    Yoann.

  • Updating existing CLR trigger - an easier way?

    [Running SQL Server 2005]
    I have a test case CLR DML trigger up and running. However, it seems tedious to update to a new version of the .dll:
    - Compile .dll
    - Delete existing trigger
    - Delete existing assembly
    - Re-create assembly
    - Re-create trigger
    Is there some method requiring fewer steps that I am missing? Thanks for any assistance.

    If you don’t change any of the method signatures of the items declared to T-SQL (which you wouldn’t for DDL trigger because it accepts no input parameters), you can simply do ALTER ASSEMBLY..... I haven’t tried with SSDT in SQL Server 2012 yet, but VS2010
    auto-deploy doesn’t support ALTER ASSEMBLY, you’ll need to code the DDL.
    Cheers,
    Bob

  • Update Opportunity Totals - trigger this action

    Is there a way to trigger the Update Opportunity Totals action (so the user does not have to click on the button)?

    Does anyone know if this functionality is available yet?
    I have a customer that would like to know if there is a way to automate the clicking of the "Update Opportunity Totals" button everytime someone changes the product revenue record(s). Their issue is that if a user forgets to click the Update Opportunity Totals button after making a change that the Opportunity totals will be off.
    Is there any work arounds for this?
    Thanks.

  • Override Update condition with trigger

    Hi
    I 've web app, and it runs an update command. But i realize in midnight, my update command's where condition is wrong. Can i manipulate this update command with instead of update trigger ?
    for example
    update mytable set sometext = 'bla' where field1= a;
    bu my filed1=a condition always empty, can we change this condition ith trigger ?
    thanks in advance.

    UPDATE is a statement and not a command; big difference. 
    Use an INSTEAD OF trigger??! Yes, and you can drive screws into furniture with big rocks. Do you know the word "kludge"? 
    Clean up your mess and write a correct update statement. In the old days, we had a joke about the "should have been" comparison operator for bad programmers. IF (x SHOULD HAVE BEEN 5) THEN..
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • 26 Aug 2010: auto update to Java 6.0.621 has stopped Firefox working. I used Add/Remove to remove the update and Firefox launched and displayed the website I was at (UK's Postal Museum) when the auto-update happened. What should do?

    I recently updated to Firefox 3.6.8. During the install routine I thought I had said OK to the process of automatically updating associated addons so when the Postal Museum prompted for an update to a new release of Java I let it happen. I sent them an email but do not remember closing down Firefox. Hour later, I clicked the Firefox button to launch it again; two seconds of eggtimer then nothing else. Tried to launch it from Start/Programs/Mozilla/Firefox. Same eggtimer. (Running WindowsXP on a middle-aged desktop).

    In Firefox 3.6 and later versions you need the Next-Generation Java™ Plug-In present in Java 6 U10 and later (Linux: libnpjp2.so; Windows: npjp2.dll).
    http://java.com/en/download/faq/firefox_newplugin.xml
    Your plugins list shows outdated plugin(s) with known security and stability risks.
    * Shockwave Flash 10.0 r32
    * Java Plug-in 1.5.0_09 for Netscape Navigator (DLL Helper)
    Update the [[Java]] plugin to the latest version.
    *http://java.sun.com/javase/downloads/index.jsp (Java Platform: Download JRE)
    Update the [[Flash]] plugin to the latest version.
    *http://www.adobe.com/software/flash/about/

  • My iphone 4 after ios 5.1 update. had error updating.my phones now in recovery mode now.usb to itunes.keeps saying!itunes doesn't recognise phone ,after update done now error.i recall doing a firmware update for the old 5.0 update.happened again.i recall

    my iphone 4 after ios 5.1 update. had error updating.my phones now in recovery mode. usb to itunes when switched on.doesnt recognise. after update done.yes updates itunes.trued different usb ports. etc . for restore .but nothing.says my phones backed up in preferences.on itunes.but can get back up.i recall doing a firware update for the last os 5.0 update..but forgot where the link was .do i have to buy a new phone ?

    UPDATE: I attempted to bypass activation using the emergency call 112 to get into the homescreen, but the call failed, in fact, even 911 will not go through and give me a call failed. (before you yell at me for dialing 911, I'm a firemedic )

Maybe you are looking for