When to use it: old.value &: new.value and when to use after and before in trigge

Hi all

I have a base table and a table of newspaper. Whenever I insert values in the base table can immediately update the table of the journal with some of the columns in the base table. To do this, I wrote the code. It looks like this:

CREATE OR REPLACE
Temp_log_track RELAXATION
AFTER INSERT OR DELETE ON temp_list_cmpgn_hist_dtl
FOR EACH LINE
DECLARE
v_partition_name varchar2 (20);
v_num_records varchar2 (20);
BEGIN
v_partition_name: = to_char (: new .campaign_start_date, "YYYYMM");
SELECT v_num_records FROM list_campaign WHERE program_id = num_records: new.program_id
AND program_child_id =: new.program_child_id;
IF the insertion
INSERT INTO temp_list_cmpgn_bkup_log
(campaign_start_date, load_date, program_child_id, program_id, partition_name, num_records)
VALUES (: new .campaign_start_date,: new.load_date,: new.program_child_id,: new.program_id,)
"list_cmpgn_" | (v_partition_name, v_num_records);
DBMS_OUTPUT. PUT_LINE ('INSERTED');
ON THE OTHER
DELETE FROM temp_list_cmpgn_bkup_log
WHERE program_child_id =: old.program_child_id / * AND campaign_start_date =: old.campaign_start_date AND load_date =: old.load_date
AND program_id =: old.program_id
AND nom_partition = 'list_cmpgn_ ' | v_partition_name AND num_records = v_num_records * /;
END IF;
EXCEPTION
WHILE OTHERS THEN
DBMS_OUTPUT. Put_line ('Error');
END;

(1.) I am able to insert values into the table of the journal whenever I insert values in the base table, but I'm not able to delete the values in the table of the newspaper whenever delete is performed on the base table.
2.) when to use it: OLD.value and: NEW.value?
(3.) when to use AFTER and when to use BEFORE?

As sb90275, you should really use the actual dates, no strings, in your query. You can use the TO_DATE function to convert a date string, i.e.

DELETE FROM table_name
 WHERE program_id = :1
   AND program_child_id = :2
   AND load_date = to_date( '30-NOV-84', 'DD-MON-RR' )
   AND campaign_start_date = to_date( '20-NOV-85', 'DD-MON-RR' )

If you store data in LOAD_DATE or CAMPAIGN_DATE where the component "hour" is something else that at midnight, you would need to TRUNC (load_date) or TRUNC (campaign_start_date).

If you look at the error stack, you'll see that the error is thrown to line 6 of your relaxation. Line 6 of your trigger is the statement

SELECT num_records
  INTO v_num_records
  FROM list_campaign
 WHERE program_id = :new.program_id
   AND program_child_id = :new.program_child_id; 

If you delete data, there is none: new.program_id or: new.program_child_id. Both values are NULL. This means that the SELECT statement retrieves no data, which means he raises an ORA-01403 error. I don't know why you do this query in the first place. You may delete it. Maybe you should do inside the INSERT IF statement. Maybe you need to change to select the COUNT (*) BOF the: old.program_id and: old.program_child_id if you are deleting lines.

Justin

Tags: Database

Similar Questions

  • To get the old value and the new value

    create table test (ID NUMBER,
    Number of REV,
    Number FIELD_ID,
    FieldName varchar2 (200),
    ACTION varchar2 (50).
    Field_value varchar2 (200),
    MODIFIED_BY varchar2 (50).
    Date MODIFIED_DATE);

    Insert into TEST (ID, REV, FIELD_ID, FIELD_NAME, ACTION, FIELD_VALUE, MODIFIED_BY, MODIFIED_DATE) values (1007,283,12,'status','UPDATE','Started','2002',to_date('13-DEC-13','DD-MON-RR'));
    Insert into TEST (ID, REV, FIELD_ID, FIELD_NAME, ACTION, FIELD_VALUE, MODIFIED_BY, MODIFIED_DATE) values (1007,224,12,'status','UPDATE','preview','2002',to_date('12-DEC-13','DD-MON-RR'));
    Insert into TEST (ID, REV, FIELD_ID, FIELD_NAME, ACTION, FIELD_VALUE, MODIFIED_BY, MODIFIED_DATE) values (1007,290,12,'status','UPDATE','revision','2002',to_date('14-DEC-13','DD-MON-RR'));


    Insert into TEST (ID, REV, FIELD_ID, FIELD_NAME, ACTION, FIELD_VALUE, MODIFIED_BY, MODIFIED_DATE) values (1008,283,12,'status','UPDATE','Started','2002',to_date('13-DEC-13','DD-MON-RR'));
    Insert into TEST (ID, REV, FIELD_ID, FIELD_NAME, ACTION, FIELD_VALUE, MODIFIED_BY, MODIFIED_DATE) values (1008,224,12,'status','UPDATE','preview','2002',to_date('12-DEC-13','DD-MON-RR'));
    Insert into TEST (ID, REV, FIELD_ID, FIELD_NAME, ACTION, FIELD_VALUE, MODIFIED_BY, MODIFIED_DATE) values (1008,290,12,'status','UPDATE','teststat','2002',to_date('14-DEC-13','DD-MON-RR'));

    1007 283 12 status of started the UPDATE 2002 13 December 13
    1007 224 12 status update overview 2002 12 December 13
    12 290 1007 State review UPDATED 2002 December 14, 13
    1008 283 12 status of started the UPDATE 2002 13 December 13
    1008 224 12 status update overview 2002 12 December 13
    1008 290 12 intensified status 2002 Update December 14, 13

    I need to Get for each id for each field Ineed to get the old value and new_value.


    Planned result for the simulacrum of the data is:

    ID FIELD_NAME ACTION OLD_FIELD_VALUE NEW_FIELD_VALUE MODIFIED_BY MODIFIED_DATE
    1007 status UPDATE started review 2002 December 14, 13
    1008 State updated started intensified 2002 December 14, 13


    Thank you
    Ann

    Hello

    9728f65c-CE79-4c28-9efb-9e76dc6eaf8b wrote:

    Yes I need a production line for all id.the the last rows should be the one with the highest rev.

    Then use id where I guessed a group of columns starting with id and rev in most of the places where I used modifed_date:

    WITH got_analytics AS

    (

    SELECT id, field_name, action

    LAG (field_value) over (PARTITION BY ID.

    ORDER BY rev

    ) AS old_field_value

    field_value AS new_field_value

    modified_by

    modified_date

    rev

    MAX (rev) over (PARTITION BY id)

    AS max_rev

    OF the test

    )

    SELECT id, field_name, old_field_value, new_field_value, modified_by, modified_date

    OF got_analytics

    WHERE rev = max_rev

    ORDER BY id

    ;

  • Get the old value and the new value based on the date

    Hello

    I have a table called list created below with the rest of the insert statements.

    CREATE TABLE ROSTER
    (
    NUMBER OF ROSTER_EMPLOYEE_DEF_ID
    NUMBER OF EMPLOYE_ID
    NUMBER OF DEFINITION_REGION_CODE
    NUMBER OF DEFINITION_DISTRICT_CODE
    NUMBER OF DEFINITION_TERRITORY_CODE
    START_DATE DATE,
    END_DATE DATE
    )



    INSERT IN THE LIST
    (ROSTER_EMPLOYEE_DEF_ID, EMPLOYE_ID, DEFINITION_REGION_CODE, DEFINITION_DISTRICT_CODE, DEFINITION_TERRITORY_CODE, START_DATE, END_DATE)
    VALUES
    (1,299,222,333,444, 'JUNE 1, 2011', 30 JUNE 2011 "")

    INSERT IN THE LIST
    (ROSTER_EMPLOYEE_DEF_ID, EMPLOYE_ID, DEFINITION_REGION_CODE, DEFINITION_DISTRICT_CODE, DEFINITION_TERRITORY_CODE, START_DATE, END_DATE)
    VALUES
    (2,299,223,334,445, "1 JULY 2011', JULY 20, 2011" "")

    INSERT IN THE LIST
    (ROSTER_EMPLOYEE_DEF_ID, EMPLOYE_ID, DEFINITION_REGION_CODE, DEFINITION_DISTRICT_CODE, DEFINITION_TERRITORY_CODE, START_DATE, END_DATE)
    VALUES
    (3,299,224,335,446, 'AUGUST 1, 2011', AUGUST 30, 2011 "")

    INSERT IN THE LIST
    (ROSTER_EMPLOYEE_DEF_ID, EMPLOYE_ID, DEFINITION_REGION_CODE, DEFINITION_DISTRICT_CODE, DEFINITION_TERRITORY_CODE, START_DATE, END_DATE)
    VALUES
    (4,300,500,400,300, 'JUNE 1, 2011', JUNE 20, 2011 "")

    INSERT IN THE LIST
    (ROSTER_EMPLOYEE_DEF_ID, EMPLOYE_ID, DEFINITION_REGION_CODE, DEFINITION_DISTRICT_CODE, DEFINITION_TERRITORY_CODE, START_DATE, END_DATE)
    VALUES
    (5,300,501,401,301, "1 JULY 2011', JULY 20, 2011" "")


    In the table above we have columns like

    EMPLOYE_ID, DEFINITION_REGION_CODE, DEFINITION_DISTRICT_CODE, DEFINITION_TERRITORY_CODE, START_DATE, END_DATE

    The result I'm looking for the table above is based on the employe_id OF start_date AND end_date

    I need to get the OLD_DEFINITION_REGION_CODE and the NEW_DEFINITION_CODE
    Similarly, OLD_DEFINITION_REGION_CODE and the NEW_DEFINITION_REGION_CODE
    and OLD_DEFINITION_TERRITORY_CODE and the NEW_DEFINITION_TERRITORY_CODE


    I need to get a row of data for each employee saying old value and the new value

    for the employee 299 there are 3 records he puts the new record which is the latest date is to say beginning August 1, 2011 and end date of recordings old 30 August 2011
    beginning July 1, 2011 and July 20, 2011


    For the data in the table above, I need to get the data as below


    EMPLOYE_ID OLD_DEFINITION_REGION_CODE NEW_DEFINITION_CODE OLD_DEFINITION_REGION_CODE NEW_DEFINITION_REGION_CODE START_DATE END_DATE
    299 223 224 334 335 20 JULY 11 30 AUG 11
    300 500 501 400 401 20 JUNE 11 JULY 20, 11


    Please suggest me to get the result above, based on the data. Please let me know if my messages are not clear


    Thank you
    Sudhir
    SELECT  EMPLOYEE_ID,
            OLD_DEFINITION_REGION_CODE,
            NEW_DEFINITION_REGION_CODE,
            OLD_DEFINITION_DISTRICT_CODE,
            NEW_DEFINITION_DISTRICT_CODE,
            OLD_DEFINITION_TERRITORY_CODE,
            NEW_DEFINITION_TERRITORY_CODE,
            START_DATE,
            END_DATE
      FROM  (
             SELECT  EMPLOYEE_ID,
                     ROW_NUMBER() OVER(PARTITION BY EMPLOYEE_ID ORDER BY START_DATE DESC) RN,
                     LAG(DEFINITION_REGION_CODE) OVER(PARTITION BY EMPLOYEE_ID ORDER BY START_DATE) OLD_DEFINITION_REGION_CODE,
                     DEFINITION_REGION_CODE NEW_DEFINITION_REGION_CODE,
                     LAG(DEFINITION_DISTRICT_CODE) OVER(PARTITION BY EMPLOYEE_ID ORDER BY START_DATE) OLD_DEFINITION_DISTRICT_CODE,
                     DEFINITION_DISTRICT_CODE NEW_DEFINITION_DISTRICT_CODE,
                     LAG(DEFINITION_TERRITORY_CODE) OVER(PARTITION BY EMPLOYEE_ID ORDER BY START_DATE) OLD_DEFINITION_TERRITORY_CODE,
                     DEFINITION_TERRITORY_CODE NEW_DEFINITION_TERRITORY_CODE,
                     LAG(END_DATE) OVER(PARTITION BY EMPLOYEE_ID ORDER BY START_DATE) START_DATE,
                     END_DATE
               FROM  ROSTER
            )
      WHERE RN = 1
    /
    
    EMPLOYEE_ID OLD_DEFINITION_REGION_CODE NEW_DEFINITION_REGION_CODE OLD_DEFINITION_DISTRICT_CODE NEW_DEFINITION_DISTRICT_CODE OLD_DEFINITION_TERRITORY_CODE NEW_DEFINITION_TERRITORY_CODE START_DAT END_DATE
    ----------- -------------------------- -------------------------- ---------------------------- ---------------------------- ----------------------------- ----------------------------- --------- ---------
            299                        223                        224                          334                          335                           445                           446 20-JUL-11 30-AUG-11
            300                        500                        501                          400                          401                           300                           301 20-JUN-11 20-JUL-11
    
    SQL>  
    

    SY.

  • Why substitution strings are now old value in application translated even after seed/publish?

    Hello

    Recently, I noticed a small, but from the perspective of our customer "big" issue. We defined in our application, some chains of substitution to keep more detailed information about the version of the application. Later, they are used in page templates to display information to end users. Recently I had to update the value of one of the chains of substitution. The change is immediately visible in the main application. Unfortunately, it is not the case for the translated application. For some reason the old value is retained. Even after doing the "seed"-> "Apply translation file"-> "publish." It is keeping the old value. I tried to use the "Translatable" checkbox in the model. In the translation file, is to show correctly the substitution in the 'source' and the tags string 'target', but still he is resolved to the old value.

    We use the APEX 4.2.2.00.11 running on 11g.

    Waiting for suggestions that maybe it's me forget somewhere extra time "checkbox. Thank you in advance.

    Greetings,

    kempiak

    It was my mistake. Value of the substitution string is included in the translation file. I changed it it and it works perfectly.

    Greetings,

    kempiak

  • Old VI, new LabView and DAQmx Driver

    They gave me a VI that was made with LabView 2012 and DAQmx 7.0 drivers. I'm in 2013 of LabView. This VI would still work if I installed new drivers (drivers compatible with LabView 2013)? -Do I have to install LabView 2012 or can I just install new drivers?

    DAQmx 7.0 was not compatible with LabVIEW 2012.  In fact, it was barely compatible with 8.1.  Perhaps you meant 9.7?

    Just use the new drivers and save the VI (s) in 2013 from LabVIEW.  You should not have problems.

  • He had to capture the old value and new values using the oracle audit trail

    Hello

    I put the parameter audit_trail for db, extended. I am in treatment of the LMD. I need to display the values changed by these instructions DML audit trail stored in dba_audit_trail. How can I achieve the same?

    Kindly guide me.

    If you want images of column of the table target before and after then the native audit function is probably not your best option. I think that you want to set triggers to audit for the insert tables and write either the CDC or duplicate lines in a historical table of change.

    HTH - Mark D Powell.

  • Update a column to keep the old values and by adding a new

    I have to update a column...

    Select * from test;

    TYPE_TEXTE RULE_NBR
    -----------------------------------
    30 AAX, AAR, AAV, AAB, AAK
    40 BBD, WWN, AAF, AAB, AAK

    now, I have to add BBB, WWW where rule_nbr = 30 and CCC, TTT where rule_nbr = 40

    so this stmt update will do...


    UPDATE TEST
    Type_texte SET = "AAX, AAR, AAV, AAB, AAK, BBB, WWW.
    WHERE rule_nbr = '30';


    Update test
    Set the argument type_texte = "BBD, WWN, AAF, AAB, AAK, CCC, TTT.
    where rule_nbr = '40';


    I was wondering is there an another way to update the same

    LPS says:
    UPDATE TEST
    SET Type_texte = concat (type_text, 'BBB, WWW')
    WHERE rule_nbr = '30';

    Update test
    Set the argument type_texte = concat (type_text, 'CCC, TTT')
    where rule_nbr = '40';

    Check your answer ;) should be concat(type_text,',BBB,WWW') or type_texte |', BBB, WWW'
    You missed the point.

    See you soon,.
    Manik.

  • I move to New Zealand and before my operating system, data and programs middle with me. My big desktop PC is too great for travel!

    What is the best way to transfer all my installed programs and data to another computer with ease?
    I am currently using Windows Vista Ultimate Edition with service pack 2.

    Can anyone help?

    Thank you.

    Windows is not designed to be moved from one computer to another, you must reinstall Windows when you change computers.

    Find the discs installation and license/product associated to all your programs keys, because you have to manually reinstall all programs. If you have downloaded some Internet programs you can redownload them. Also back up personal files to external storage for transfer to the new computer.

    You can move the windows on a new computer

    If it's a full license or upgrade retail - Yes. You can move it to another computer as long as it is installed on one computer at a time (and if it's a version upgrade the new Windows computer must have its own license of qualification). The previous Windows installation on your old computer must be formatted or deleted. You will have to perhaps call Microsoft and explain what happened to complete activation. Turning it on the second computer will automatically be in effect 'disable' the license for the first computer.

    If it's an OEM license - don't. OEM licenses, including Windows preinstalled on a computer before purchase and Windows purchased separately, are related to the first computer, they are installed on and cannot be transferred to another computer. To install Windows on another computer, you will need to buy another copy.

  • Change the tasks triggered with the old values

    Hi all

    We have a problem where our editing on the definition of process AD sometimes tasks copy old values of the form user IOM, for example "Surname of change", "Change Display Name", etc. Sometimes it works for all fields that are changed on the UserForm IOM and the updated values are copied all over the user AD form, sometimes a mixture of new and old values are copied, and sometimes only the old values are copied. Anyone seen this before? We post the event handlers for the email address and display name causing additional updates on the user IOM form, when the values are changed.

    Thank you

    Albin

    We were already using UserManager instead of the EntityManager. The question must have been that several updates triggered by our event handlers and the user object was so an inconsistent state, sometimes the old name values were transmitted to the AD form and sometimes the new values. We have solved by adding all the electronic trigger code and display name updated in a single event handler instead of two separate. It seems to work now.

    Albin

  • retrieve a NEW VALUE rather than the OLD VALUE when firepartialaction called even

    Hi gurus of the OFA.

    I have an advanced table where to enter a value. This table is populated using vo.

    (1) now I have a firepartialaction with a parameter with one of the columns of the table.
    (2) I noticed that when I change a value and the hover out of this column, the parameter returns the OLD value of the table.
    (3) the question is, how do I get the new value? If the creation of a parameter for the firepartialaction event will NOT recover the NEW value, what is the best why to get it back!

    Thank you!

    In the settings of the firePartialAction, you must by the way some settings for the resulting values in the CO.
    In general, the format is ${oa. ViewInstance.AttributeName}

    For your case try using ${oa.*current *.} AttributeName}
    This will give you the new value.

  • Using old value in calculation...

    Hello again,

    If I have for example the senario below

    Debtor credit balance Emp_name

    Ahmad 200.00 $ $30.00-$170.00

    Ahmad $50.00 400.00-$ 180.00

    such that the value of the balance in the second row is calculated as: credit - debit + old balance = 400 - 50 + (-170) = 180.

    If I want to express this in my trigger, is it correct to write it like this:

    : New.Balance: =: New.Credit -: New.Debit +: old. Balance;

    And what happens if we do not have old balance, as for the original line?

    Any background?

    Thank you very much in advance...

    Your requirement seems incomplete. You have to tell us what you want to do when you don't have an old value. Check if this helps you. It's about old value 0 if you do not.

    SELECT THE CREDIT + DEBIT + LAG (BALANCE, 1, 0) (PARTITION SORT ENAME ENAME) OF TABLE;

  • How to compare the new values with the old values in triggers.

    Dear all,

    Please tell me how to compare the new values with the old values in triggers.

    Hi, the employee example is in the document. You'd better read yourself.

    CREATE OR REPLACE TRIGGER Print_salary_changes
      BEFORE DELETE OR INSERT OR UPDATE ON Emp_tab
      FOR EACH ROW
    WHEN (new.Empno > 0)
    DECLARE
        sal_diff number;
    BEGIN
        sal_diff  := :new.sal  - :old.sal;
        dbms_output.put('Old salary: ' || :old.sal);
        dbms_output.put('  New salary: ' || :new.sal);
        dbms_output.put_line('  Difference ' || sal_diff);
    END;
    /
    
  • < af:valueChangeListener > sets the new value back to the old value

    Hi people,

    I'm trying to implement a search bar with < af:inputText > and < af:selectOneListbox >.

    When the user selects an item in the listbox control, the inputText will be updated. After hitting the "ENTER" key, the search action will be taken.

    The valueChangeListener will be called when the selection of items in the listbox.

    The problem can be described by the following two cases:

    (1) the user types something in the inputText box and hitting 'ENTER' key for a search. The valueChangeListener is called and sets the value of the string user typed.

    (2) the user selects something in the list box, each time changes the selection in the listbox control, the valueChangeListener will be called. But when the user presses the "ENTER" key, the valueChangeListener is still called, and it sets the return value to the old value. For example, the list has 'a ', ' b', 'c '. The user selects 'a', then 'b '. After hitting the "ENTER" key, the value in the inputText is replaced with "a".

    The code is as follows:

    Code in .jspx:

    < af:inputText value = "#{pageFlowScope.word} '"

    autoSubmit = 'true' immediate = "true".

    valueChangeListener = "#{pageFlowScope.update}" / >

    < af:selectOneListbox valuePassThru = "true" >

    < f: selectItems value = "#{pageFlowScope.items}" / >

    < / af:selectOneListbox >

    Bean managed code:

    publicvoid update (ValueChangeEvent event) {}

    This.Word = event.getNewValue (m:System.NET.SocketAddress.ToString ());

    }

    I don't know how the valueChangeListener behaves like that.

    Could someone provide me with clues or tips?

    Thank you

    Carl

    Carl, tell us your version of jdev, please!

    There is something wrong in your implementation. I do not see an inputText field who's value stored in a variable pageflowscope "word". This field has an attached valuechangelistener which is obsolete, because the field already stores its value in the variable pageflowscope. The same that you are trying to do in the valuechangelistener. So I don't see a selectonelistbox which does not store the value selected anywhere because it doesn't have the value property for it. There isn't an attached valuechangelistener so I wonder how your valuechangelistener is called at all when you change the selectoneListBox.

    Timo

  • Get the old value of the element when sending, why?

    I am looking for the value of the newly submitted to the building of a controller method.  However, the previous value is obtained, not the new value that is entered in this area before submitting the page, and I don't know why.

    OAMessageTextInputBean tableNameSearchBean = (OAMessageTextInputBean) webBean.findChildRecursive ("tableName");
    String tableName = tableNameSearchBean.getText (pageContext);

    What I am doing wrong?  How do you get the value of an item that should be part of the shipment?

    Thank you

    Hello

    Can you please use--> tableNameSearchBean.getValue (pageContext) and check the result?

    In addition, if you can explain with an example of prior value and a new, it will be easier to help.

    Kind regards

    Zahid

  • When I use a new computer and install Thunderbird I lose all of my old folders and emails

    I need to buy a new laptop. I install Thunderbird on it for my emails. Will I lose all of my old emails, they are in difference on Thunderbird records.

    Thank you

    Copy your profile on your new computer, and it'll be just as it was on the old computer.

    https://support.mozilla.org/en-US/kb/profiles-tb
    

Maybe you are looking for

  • Satellite A200 - internal mic has background noises

    Hello Description: Internal microphone with full boost, and volume has background noise. By reducing its levels, it has insufficient gain to drive Skype etc, so the only viable solution is to use front mic. Have you tried several MICS known for work

  • Lenovo, Yoga Pro 1370 - backlit 3 does not

    Hello! I bought a Lenovo Yoga 3 Pro, but the keyboard backlight seems to not work. I tried Fn + space with no luck. I tried to update via the parameters of Lenovo, but it takes a hundred years. I also installed the latest drivers, no luck. What can I

  • The PC upgrade

    Hello guys and gurls a few years ago, I bought a HP Pavilion a6230n PC maybe 07 who knows and I would like to know what is the most high processor and video game card I could buy and put on this bad boy it would be able to run it without have smoke o

  • Sony Bravia 55 '' goes off and lights repeatedly

    Hello I'm sure this has been asked and answered many times, but I thought would like to ask once again accelerate things. We have a Bravia KDL-55HX800 is only 3 years old 55 "and out of nowhere, he began to turn power off and back on.   Even if you s

  • Windows 7 - display size too big

    Just replaced XP with Windows 7 on my Dell PC and now the graphica are much too large for the screen. I tried to change the resolution, but it makes it just worse. Did I miss something?