How to write the trigger for update of 2 tables

Hi all
I have 2 tables,

1.lv_data,
It contains the following fields,
emp_name        tot_days
 guru                    18
            
2.leave_data
It contains the following fields,
 emp_name          From_date              to_date            no_of_days       remaining_days
 guru                    02/05/2012          03/05/2012           2                         
In the second table, if the data is inserted.
the no_of_days will be calculated automatically (from to_date - From_date) + 1,

Here, I need to write the trigger to update the remaining_days column,

First table for all tot_days emp_name is 18 days,
Thus, in the second table every time that the record is inserted.
the remaining_days must be calculated as follows,

remaining_days: = tot_days - no_of_days and this (calculated) value should be updated in the tot_days column in the first table (lv_data).

Example:
emp_name        tot_days
guru                    18
            
2.leave_data
 emp_name          From_date              to_date            no_of_days        remaining_days
 guru                    02/05/2012          03/05/2012         2                          16
[/code  

Now the first table should be updated like,
emp_name tot_days
Guru 16


So I need to update to 2 tables,
can someone help me to update these 2 tables through TRIGGER?

Thank you
Kind regards
gurujothi

Edited by: Gurujothi may 1, 2012 19:54

It is generally considered bad practice to store the value even in 2 places. You are having the kind of problems that you are experiencing now. It is much easier to store in the main table and get the value from there where you need to show in your forms.

Tags: Database

Similar Questions

  • How to write the trigger for update or delete multiple columns in a table?

    Hello

    I create one in the form of table of sample_emp. In that, every time I want to change of name, team_id, team_leader_id, supervisor_id, manager_id it must store the update-able and old values of those in the job_history table. When I write the trigger for which it shows "ORA-04082 new or the old value not table level triggers. Here is my emp_table. My table also similar job_history like this. Need your help.

    Header 1 Header 2 Header 3 Header 4 Header 5 Heading 6 Heading 7 8 header Header 9
    EMP_IDEMP_NAMEDESIGNATIONTEAM_IDTEAM_LEADER_IDEMPLOYEEMANAGER_IDHIRE_DATERELIEVED_DATE

    --

    Thank you.

    Hi Joel,.

    Venky_prs wrote:

    Hello

    I create one in the form of table of sample_emp. In that, every time I want to change of name, team_id, team_leader_id, supervisor_id, manager_id it must store the update-able and old values of those in the job_history table. When I write the trigger for which it shows "ORA-04082 new or the old value not table level triggers. Here is my emp_table. My table also similar job_history like this. Need your help.

    Header 1 Header 2 Header 3 Header 4 Header 5 Heading 6 Heading 7 8 header Header 9
    EMP_ID EMP_NAME DESIGNATION TEAM_ID TEAM_LEADER_ID EMPLOYEE MANAGER_ID HIRE_DATE RELIEVED_DATE

    --

    Thank you.

    You can try something like this given below to complete the historical table on update and delete.

    create or replace TRIGGER  "CLONE_EMP_UPDATE_DELETE"
    BEFORE DELETE OR UPDATE ON EMP
    FOR EACH ROW
    DECLARE
        PRAGMA autonomous_transaction;
    BEGIN
    INSERT INTO JOB_HISTORY("EMP_ID","EMP_NAME","DESIGNATION","TEAM_ID","TEAM_LEADER_ID","SUPERVISOR_ID","MANAGER_ID"
    ,"HIRE_DATE","RELIEVED_DATE")
      VALUES(:OLD.EMP_ID,:OLD.EMP_NAME,:OLD.DESIGNATION,:OLD.TEAM_ID,:OLD.TEAM_LEADER_ID,:OLD.SUPERVISOR_ID,
    :OLD.MANAGER_ID,:OLD.HIRE_DATE,
    :OLD.RELIEVED_DATE);
    COMMIT;
    END;
    

    Hope this helps you,

    Kind regards

    Jitendra

  • How can I write the trigger for the global temporary Table

    Hi Grus,
    How can I write the trigger for the global temporary Table.

    I created the TWG with trigger using the script below.


    CREATE A GLOBAL_TEMP GLOBAL TEMPORARY TABLE
    (
    EMP_C_NAME VARCHAR2 (20 BYTE)
    )
    ON COMMIT PRESERVE ROWS;


    CREATE OR REPLACE TRIGGER TRI_GLOBAL_TEMP
    BEFORE DELETE, UPDATE OR INSERT
    ON GLOBAL_TEMP
    REFERRING AGAIN AS NINE OLD AND OLD
    FOR EACH LINE
    BEGIN
    INSERT INTO VALUES EMPNAME (: OLD.) EMP_C_NAME);
    END;
    /


    trigger was created successfully, but her would not insert EMPNAME Table...

    Please guide if mistaken or not? If not wanting to give a correct syntax with example


    Thanks in advance,
    Arun M M
    BEGIN
    INSERT INTO EMPNAME VALUES (:OLD.EMP_C_NAME);
    END;
    
    you are referencing old value in insert stmt.
    
    BEGIN
    INSERT INTO EMPNAME VALUES (:new.EMP_C_NAME);
    END;
    

    then run your app, it works very well...

    CREATE GLOBAL TEMPORARY TABLE GLOBAL_TEMP
    (
    EMP_C_NAME VARCHAR2(20 BYTE)
    )
    ON COMMIT PRESERVE ROWS;
    
    CREATE OR REPLACE TRIGGER TRI_GLOBAL_TEMP
    BEFORE DELETE OR UPDATE OR INSERT
    ON GLOBAL_TEMP
    REFERENCING NEW AS NEW OLD AS OLD
    FOR EACH ROW
    BEGIN
    dbms_output.put_line(:OLD.EMP_C_NAME||'yahoo');
    INSERT INTO EMPNAME VALUES (:new.EMP_C_NAME);
    dbms_output.put_line(:OLD.EMP_C_NAME);
    END;
    /
    
    create table EMPNAME as select * from GLOBAL_TEMP where 1=2
    
    insert into GLOBAL_TEMP values('fgfdgd');
    commit;
    select * from GLOBAL_TEMP;
    select * from EMPNAME;
    
    output:
    1 rows inserted
    commit succeeded.
    EMP_C_NAME
    --------------------
    fgfdgd               
    
    1 rows selected
    
    EMP_C_NAME
    --------------------
    fgfdgd               
    
    1 rows selected
    

    He got Arun

    Published by: OraclePLSQL on December 28, 2010 18:07

  • How to use the trigger for Hammer

    Hello

    I used a hammer and an accelerometer of pcb to do some tests of beam. I want to express signal for start of log data after I use the hammer hit something. Here is my configuration in express signal.

    Trigger type: analog edge. Source of relaxation: the channel of the hammer
    Slope: fall. Level: 0

    However, once he began to run, it says "logging was stopped because an error occurred with a step in the project. If this error is due to a device buffer overflow, you can improve performance by disabling updates to screen using the "view > views of Signal update during the race" menu item. You can also change the way in which the signals are recorded by changing the Logging Options in the tools > Options dialog box. Disabling "Prepare the log for display data" will greatly improve performance. "I've changed everything, but it didn't work.

    Should I use other types of trigger?

    Thank you
    Ningyu


  • How to write the function for bottom of logic...

    I have a picture in the picture I have a records like below
    code value
    1 20
    2 null
    3 30
    4 null
    5 40
    6 null


    The output need to have the values displayed in the fields first, followed by the NULL values as below

    code value
    1 20
    2 30
    3 40
    4 null
    5 null
    6 null

    I think the suspicion is that the values must be concatenated with the replacement of NULL values with (;).
    as
    20, 30, 40
    Get single values and insert into the table...

    for this I don't know how to write function for who can please help me on these...

    Published by: Claudia on June 22, 2011 22:45

    Published by: Claudia on June 22, 2011 22:51

    Create or replace function test_fun
    is
    cursor fun1 is the value select from table by CSA 2;-"this select query will return 20,30,40, null, null, null".
    v_out varchar2 (20);
    Start
    fun1 open cursor;
    loop
    extract the fun1 in v_out;
    dbms_output.put_line (v_out); - this is the command display output on the screen.
    output when fun1 not found %;
    end loop;
    close;
    end;

    Please try it and tell us if no query...

    Thank you
    IQ

  • How to display the note for a cell of table with javascript?

    My goal is to do it with javascript. No manipulation of the side server.

    < af:table id = "t1" >
    < af:column id = "c1" >
    < af:outputText id = "ot1" >...
    < af:clientListner ...method="showpopup"/ >
    < /... >
    < /... >
    < /... >

    ....

    < af:popup id = "p1" >
    < af:noteWindow id = ot2 >
    here to show the value of ot1
    < /... >
    < /... >


    function showPopup (e) {}
    var text is e.getSource () .getValue ();.
    var popup is e.getSource (.findComponent("::p1"));.
    now, how to upgrade the content of the notewindow?
    Popup.Show ();
    }

    Hello

    You can try with something like that.

                   
                        
                    
    
                    
                        
                            
                        
    
                    
                    
                        function showPopup(evt){
                            var ot1 = AdfPage.PAGE.findComponent("ot1");
                            var text=ot1.getValue();
                            var popup=AdfPage.PAGE.findComponent("p1");
                            var ot2=AdfPage.PAGE.findComponent("ot2");
                            ot2.setValue(text);
                            popup.show();
    
                            }
    
                    
    

    Arun-

  • How to create the widget for updated by the customer?

    At the last moment, I used the widget of composition for the addition of new food for some clients. And right now, they would like to add the news that feed themselves.

    I try to find a different widgets that he can be there. Please answer me.

    00.JPGClick on the orange words to show the details01.JPGdetails is in the orange box which is the tootips widget.

    This message is marked as are answered, you always face the same problem?

    Thank you

    Sanjit

  • How to write a query for the data exchange between two columns?

    How to write a query for the data exchange between two columns?

    I tried a request, does NOT work.
    update tmp t1 set t1.m1=t1.m2 and t1.m2=(select t2.m1 from tmp t2 where t2.student_id = t1.student_id)
    Thank you.

    Published by: user533361 on October 23, 2009 14:04

    Just plain and simple:

    update tmp t1
     set t1.m1=t1.m2,
         t1.m2=t1.m1
    /
    

    SY.

  • How to write a script for date get to the Clipboard

    Hi experts,

    How to write a script for date get to the Clipboard.

    the date format will be like this:

    05 - may

    respect of

    John

    Thanks guys, thanks Sanon

    I finally use the .bat doc

    like this:

    @@echo off
    for /f "delims =" % in (' wmic OS Get localdatetime ^ | find ".") "") Set "dt = %% a"
    the value "YYYY = % dt: ~ 0, 4%.
    the value "MM = % dt: ~ 4, 2%.

    If MM % is 01 set MM = January
    If % MM == 02 set MM = February
    If MM % is MM value = March 03
    If MM % is 04 MM value = April
    If MM % is 05 MM value = may
    If MM % is 06 MM value = June
    If MM % == 07 set MM = July
    If MM % is MM value = August 08
    If MM % is MM value = September 09
    If MM % is 10 MM value = October
    If MM % is 11A set MM = November
    If MM % is game MM 12 = December

    the value "DD = % dt: ~ 6, 2%.
    the value "HH = % dt: ~ 8, 2%.
    the value "Min = % dt: ~ 10, 2%.
    Set "s = % dt: ~ 12, 2%.

    Echo DD - MM HH % %% % Min | Clip

    It works

    respect of

    John

  • How to write the select query for it

    Hello

    I had an html form and the area I drop down and he needs to select several values in the drop-down box. When I select multiple values then I have to write the query to SQL select statement.

    When I try to write the select statement and trying to run I get the error message.

    Select * from Table

    where emo_no = '1,2,3 '.

    That's how I write the query please suggest me how to write the query to select several values in the drop-down box.

    Thank you

    Use the keyword sql 'in '.  If you don't know how, I've heard good things about the book Teach Yourself SQL in 10 Minutes by Ben Forta.

  • How to disable the AppStore offers updated app that does not exist on the ipod touch 5g ios 9 and Reset counter app

    Regularly I receive notifications of updated Brainiacs Sudoku which I had deleted Ipod Touch 5 g a long time ago.  I can't disable the app update counter until I have download the update.  So, how to disable the AppStore offers updated app that does not exist on the ipod touch 5g ios 9 and Reset counter of the application once and for all?

    Try to hide this purchase

    Hide and show purchases iTunes or iBooks on your Mac or PC - Apple Support

  • How to upgrade the driver for my video card?

    How to upgrade the driver for my video card?

    Most often when a device does not work, it's because the driver has been corrupted.

    Try reinstalling your.

    http://Windows.Microsoft.com/en-us/Windows7/update-a-driver-for-hardware-that-isn ' t-work correctly? SignedIn = 1

    http://captaindbg.com/how-to-update-drivers-on-Windows-7/

  • Windows 7 continues the search for updates

    Recently, I have restored my laptop to factory settings, and after you install the service pack 1 update, this does not block the search for updates.  I tried everything on this site but without success.  Help, please.  Thank you.

    The installation of the plant is the worst possible Windows, that no tech fan would go because of the bloatware and installation utility factory duplicate that interfere with better integrated in the operating system versions.  Corruption as it is so just wait until you make a clean reinstall Windows 7 .

    If you want to try to wrestle with the factory install, so first thing I "d to recover some lost performance is Clean Up Factory Bloatware. "  It also checks and fix the integrity of the installation itself, which is not only limited but damaged by bloatware.

    Then, if the problem run the troubleshooting Windows Update - Microsoft Windows Help tool

    Then, try to Reset Windows Update components.

    Finally, as a last resort, run the System Update tool .

    Let us know how it goes and if there are any questions or problems.

  • Open XML, how to write the path

    Hello

    I'm new to the Blackberry development and I hope you can help me with my problem. I try to work with an XML file, and so far, all that does very well as long I had the xml file, I work on, in the folder of my java application and deyployed using the desktop software. Now, I tried to put the file somewhere else on the Blackberry and I don't know how wirte the path to the source code. I tried the following, but it seems to be bad:

    private static String _xmlFileName = "file:///store/home/user/documents/test.xml";
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
                DocumentBuilder builder = factory.newDocumentBuilder();
                InputStream inputStream = getClass().getResourceAsStream( _xmlFileName );
                Document document = builder.parse( inputStream );
    

    I hope you can give me a hint, how I write the correct path?

    Thank you very much!

    Best regards, jtr87

    PS: Sorry for my bad English, but I did not use it very often.

    You need to do something like that to get your InputStream:

    /** * @return an open InputStream for a file, or null if file does not * exist. * @throws IOException if there is an error opening the file */InputStream getInputStream(String name) throws IOException {
        FileConnection fc = null;
        try {
            fc = (FileConnection) Connector.open(name, Connector.READ);
            if (fc.exists()) {
                return fc.openInputStream();
            }
        } finally {
            if (fc != null) {
                try {
                    fc.close();
                } catch (Exception ignored) {
                }
            }
        }
        return null;
    }
    

    Notice that you must close the FileConnection at some point, regardless of if the call to openInputStream worked.

  • How to stop the date of update when I opened the old correspondence

    I asked this question two years when I had XP. I'm now running Windows 7. The answer I received before does not work now.

    Hi Kerisis,

    1. What do you mean by "how to stop the date of update when I opened the old correspondence?

    2 edit. you and save the document?

    Answer us with more information for you help.

    Also see this link for suggestions for a question on the help forums
    http://support.Microsoft.com/kb/555375

    Kerisis, when you open a document, make a few changes, save it, date will be automatically updated. However, creation date won't change. You can check this by clicking on the file, select Properties, on the general tab, you will find the dates of access created, modified.

Maybe you are looking for

  • Case of the suitable laptop...

    Wonder if anyone knows of a padded envelope that I can put my laptop, but still allows the laptop be opened and used. As the former mobile phone cases.

  • replacement of Spanish keyboard for Yoga 14?

    Hello I recently bought this laptop at BestBuy: THINKPAD YOGA 14 - 20DM009GUS (2 in 1) I need to get the keyboard in Spanish (with the N key) This room is available for purchase? could someone give me the part number? I have the instructions to chang

  • [ISSUE] Network driver HP Pavilion 15-n023sy wireless

    Hi all! My laptop is HP Pavilion n023sy 15. There is no driver official support for Windows 7 for this laptop. I managed to install Windows 7 64 x on it, with the necessary drivers from other distributions of the HP series. And the only question is l

  • RootKit Revealer

    Y at - it a compatible version of RootKit Revealer for 64-bit operating systems?

  • Problems with the start time/Display Tune (r) / Vista Business

    Dear community of Mic,I have two problems that slow down my computer. (1) start time:After my computer starts, it loads quickly in the logon section. However, after I give my login informationthe HP computer HP monitor goes black for about two minute