Calling function in before insert trigger

HELLO,
**TRIGGER IS NOT DISPLAYING THE DATA ACCURATELY**
**PLZ HELP ITS URGENT...**
THE CODE IS BELOW.....
create or replace TRIGGER GENSTUDYID
BEFORE INSERT
ON ER_PATPROT
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
     lPatStudyID varchar2(30);
     lSiteCode number(10);
     lStudyCode number(10);
     lpk_patprot     Number(10);     
     lpatprot_enroldt date;
     lFK_PER number(20);
     lIPADD varchar2(15);
     lfk_protocol number(20);
     llast_modified_by number;
     lgencal_status number;
BEGIN
     lSiteCode := :New.fk_site_enrolling;
     lStudyCode := :new.fk_study;
     lpk_patprot := :new.pk_patprot;
     lpatprot_enroldt := :new.patprot_enroldt;
     lFK_PER := :new.fk_per;      
     lIPADD :=NULL;                
     lPatStudyID:=GenerateStudyID(lSiteCode,lStudyCode,lFK_PER);
     IF lPatStudyID IS NOT NULL then
          :NEW.patprot_patstdid := lpatstudyid;
     END IF;
END;
-----------FUNCTION CODE STARTS
create or replace
function GenerateStudyID (sitecode number,studycode number,pid number) RETURN VARCHAR IS
     lfield_name varchar2(10);
     lfield_format varchar2(10);
     lfield_length number(2);
     lfield_deftext varchar2(500);
     lparam1 varchar2(30):=sitecode;
     lparam2 varchar2(30):=studycode;
     lresult varchar2(30);
     lstudyid varchar2(30);
     lPATPROT_PATSTDID     varchar2(20);
CURSOR studyid_def_cur is select field_name, field_format, field_length, field_deftext from bayatree.studyid_definition
where study_code = studycode and site_code=sitecode order by field_seqno;
     CURSOR patprot_patstdid_cur is select PATPROT_PATSTDID from eres.er_patprot where fk_study=studycode and fk_per=pid;
BEGIN
     lstudyid := NULL;
dbms_output.put_line('studycode: '||studycode);
     dbms_output.put_line('pid; '||pid);
     FOR disp_studyid in patprot_patstdid_cur
     LOOP
          lPATPROT_PATSTDID:=disp_studyid.PATPROT_PATSTDID;
          dbms_output.put_line('lPATPROT_PATSTDID: '||lPATPROT_PATSTDID);
     END LOOP;
          IF lPATPROT_PATSTDID IS NULL THEN
          OPEN studyid_def_cur;
          LOOP
          FETCH studyid_def_cur INTO lfield_name, lfield_format, lfield_length, lfield_deftext;
          EXIT WHEN studyid_def_cur%NOTFOUND;
lfield_deftext:= replace(lfield_deftext,'param1',lparam1);
          lfield_deftext:= replace(lfield_deftext,'param2',lparam2);
     if (instr (lfield_deftext, 'select',1) > 0) then
               execute immediate lfield_deftext into lresult;
          else
               execute immediate lfield_deftext;
               lresult := null;
          end if;
          if lfield_format is not null and lresult is not null and lfield_length is not null then
               lresult := lpad(lresult, lfield_length, 0);
          end if;
          if lfield_name is not null and lresult is not null then
               lstudyid := lstudyid || lresult;
          end if;
     END LOOP;
     return (lstudyid);
     ELSE
          lstudyid:=lPATPROT_PATSTDID;
          Dbms_output.put_line('Study Id: '||lstudyid);
          return (lstudyid);
     END IF;
END;

Your post is not quiet readable, please include your program in tags, Include sample data and sample output, table and other objects creation and insert scripts.
What error are you getting anyway post the Oracle error code
SS                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • Problem determining if id is present in BEFORE INSERT trigger

    Hi,
    I have written a BEFORE INSERT trigger in which I am trying to determine whether or not an id (primary key ) has been submitted as part of the insert. The reason for this is that in my application there are two cases in which the trigger will be called, 1) when the id has been previously obtained from a sequence and passed in, and 2) when an id needs to be 'automatically' generated from within the trigger'. (two subsystems which work differently talk to the database in different ways)
    this is the key part of the trigger code:
    CREATE OR REPLACE TRIGGER trg_submissions_seq_id
    BEFORE INSERT on submissions
    FOR EACH ROW
    BEGIN
    if :new.id IS NULL THEN
    select seq_submissions_id.nextval INTO :new.id FROM DUAL;
    end if;
    ....more code here
    END;
    I think this is correct. Can someone confirm this.
    However the behaviour I see is that in case 1 the id is increased twice , once when it is obtained from the sequence , and then again in the trigger... despite the condition I put in.
    If anyone can shed any light on this behaviour I would be grateful.
    Mark

    This trigger (at least what you've posted of it) won't increment the sequence if Rails passes in the ID column. If you're always seeing the sequence incremented twice, I would tend to wager that either Rails is calling the nextval function twice or that it is not passing in an ID. Of course, since Oracle sequence-generated values are not gap-free, presumably this is just a cosmetic issue, not a functionality issue.
    As a general matter, I'd suggest not using ID as a column name for a table. In addition to being a poor naming convention, ID is a reserved word.
    Justin

  • INSERTstatement is not working if there is a before insert trigger

    INSERTstatement is not working if there is a before insert trigger on that table. That trigger contains an insert to another table which having the main table reference.
    Let us say, for example there a table named 'EMP_DEPT' and there is a before insert trigger on this table.
    In this trigger inserting a record in to another table named 'AUDIT_EMP' and in this table using EMP_Dept primary key as foreign key.
    Table EMP_DEPT is having the below columns:
    EMP_DEPT_SYS_ID
    EMP_DEPT_NO
    DEP_NAME etc..
    Table AUDIT_EMP is having the below columns:
    AUDIT_EMP_SYS_ID
    EMP_DEPT_SYS_ID
    AUDIT_NO etc..
    the code in the trigger is
    INSERT INTO audit_emp
    (audit_emp_sys_id, emp_dept_sys_id, audit_no
    VALUES (audit_emp.NEXTVAL, :new EMP_DEPT_SYS_ID, '1101'
    Now when you execute the insert query like:
    INSERT INTO emp_dept
    (emp_dept_sys_id, emp_dept_no, dep_name
    VALUES (EMP_DEPT.nextval, 1001, 'Dep-1'
    It is giving the error saying 'Integrity constraint error, parent key not found' from the trigger.
    But, when you modify the above insert query like the below then it is working.
    INSERT INTO emp_dept
    (emp_dept_sys_id, emp_dept_no, dep_name
    SELECT EMP_DEPT.nextval, 1001, 'Dep-1'
    FROM DUAL;
    I am using Oracle 10g.
    Why the insert into values is not working. Is there any commit transaction sequence change? Any idea please?
    Edited by: user6475632 on Sep 16, 2009 7:08 AM

    Obviously the code you posted can not work.
    You are inserting the detail record (the audit record) before the master record, where it should have been after. IMO, you should fire the trigger AFTER INSERT for each row.
    If that still doesn't work, you need to change the foreign key constraint into a deferred constraint, which is evaluated at commit, instead of immediately. The SQL reference manual has further info on this.
    'Oracle 10g' is considered a marketing label here, not a -4 digit- version.
    Sybrand Bakker
    Senior Oracle DBA

  • Clob field not working in BEFORE INSERT trigger

    Hello, everyone. I am trying to create a before insert trigger for a table (10g). I would like to create a value for a table field based on the xml query from a clob field. The table looks like this:
    SQL> desc lac_costing_upload
    Name Type Nullable Default Comments
    UPLOAD_ID NUMBER Y
    EMP_NUM VARCHAR2(20)
    UPLOAD_DATE DATE Y
    YEAR_MONTH VARCHAR2(10) Y
    UPLOAD_TEXT CLOB Y
    The trigger code looks like this:
    create or replace trigger lac_cst_upl_yr_month
    before insert on lac_costing_upload
    for each row
    declare
    l_month varchar2(20);
    l_year varchar2(20);
    l_error_msg varchar2(255);
    begin
    SELECT XMLTYPE (:old.upload_text).EXTRACT('Oracle_Extract/Year/text()').getstringval() Extr_Year
    , XMLTYPE (:old.upload_text).EXTRACT('Oracle_Extract/Month/text()').getstringval() Extr_Month
    into l_year
    , l_month
    FROM dual;
    :new.year_month := l_year || '.'
    || substr(l_month, 1, 3)
    exception
    when others then
    l_error_msg := substr(sqlerrm, 1, 10);
    :new.year_month := l_error_msg;
    end lac_cst_upl_yr_month;
    Here is a sample insert statement:
    insert into lac_costing_upload lcu values(2006, '008925', sysdate, null
    , '<Oracle_Extract>' || chr(10)
    || ' <Emp_Num>05417</Emp_Num>' || chr(10)
    || ' <Emp_Name>Fitzgerald</Emp_Name>' || chr(10)
    || ' <Year>2007</Year>' || chr(10)
    || ' <Month>May</Month>' || chr(10)
    || ' <Vehicle>1330</Vehicle>' || chr(10)
    || '</Oracle_Extract>'
    My hope was to see '2007.May' in the year_month field. However, I'm getting 'ORA-06502:' instead. It looks like the value of :old.upload_text is null in the trigger.
    Can anyone tell me what I'm doing wrong?
    Thanks for any help.
    --Dave                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    That's probably a really dumb error, but I don't work much with triggers.
    It's working now.
    Thanks for your help.
    --Dave                                                                                                                                                                                                                                                               

  • Problem while using Before insert Trigger

    Hello everybody,
    I am using 9.2.0.4.0 XMLDB..
    The problem occurs while using the before insert trigger shown below to convert a CLOB(:new.file_clob) to XMLTYPE(:new.file_xml). The trigger is on a table with file_clob and file_xml as columns. file_xml column is based on a registered schema.
    The trigger is:
    Create or replace trigger po_2_demo_xml_tab_trg
    before insert on po_2_demo_xml_tab
    FOR EACH ROW
    -- Step 1:to convert CLOB to XMLtype and store it
    --in :new.file_xml .
    :new.file_xml := xmltype(:new.file_clob);
    -- Step 2:to verify if :new.file_xml has been created
    dbms_output.put_line(:new.file_xml.extract('/PurchaseOrder/PONum/text()').getStringVal());
    end;
    If u insert a valid xml file, u can see the PONum value on dbms output(Step 2 of the trigger works). u also get the "1 row inserted" message.
    Surpisingly, if u query on the table it shows that the file_xml column is null! For some reason, the value of :new.file_xml in the before insert trigger is not being retained in the table.
    Has anybody encountered this before? Do I have to apply any patch?
    Appreciate any help in this regard.
    Thanks,
    Partha.

    sorry! I just noticed.. the trace file does show an error, but the error is while creating the table itself.
    Please see the segment from trace file below:
    The following statements encountered a error during parse:
    create table po_2_demo_clob_xml_tab
    file_clob CLOB,
    file_xml xmltype
    )xmltype column file_xml
    XMLSCHEMA "http://Friday/PO_2.xsd"
    ELEMENT "PurchaseOrder";
    XCTEND rlbk=0,
    Error encountered: ORA-00911
    But, inspite of this I am able to insert a xml file into file_xml using a sql statement. But the before insert trigger does not retain :new values.
    Appreciate any comments.
    Thanks,
    Partha.

  • Before insert Trigger and SQL Loader

    Hi,
    I have a table with a BEFOR insert on each row trigger . I am loading the data to that table using sqlloader and I want my trigger to fire for each row. But the trigger is firing only for alternate rows.
    body of trigger as follows.
    select max(pd_id) into VarVal from <table name> where tar_id=:new.tar_id;
    select pd_id+1 into :new.pd_id from dual;
    if I remove the first select statement from my trigger , then it is firing for all the rows. But the removel of first select statement will not satisfy my requirements.
    So please suggest me how can I achieve this.

    [url http://forums.oracle.com/forums/thread.jspa?threadID=587783&tstart=0]duplicate thread

  • Migrating from MSSQL2005: Before-Insert Trigger Generation

    The SQL Server 2005 tables with auto=incrementer primary keys result in sequence objects being defined for use in Before-Insert triggers, which is good. I see the following code in the generated triggers:
    <br>
    IF INSERTING AND :new.ofi_service_provider_id IS NULL THEN
    SELECT OFI_SERVICE_PROVIDER_ofi_servi.NEXTVAL INTO v_newVal FROM DUAL;
    -- If this is the first time this table have been inserted into (sequence == 1)
    IF v_newVal = 1 THEN
    --get the max indentity value from the table
    SELECT NVL(max(ofi_service_provider_id),0) INTO v_newVal FROM OFI_SERVICE_PROVIDER;
    v_newVal := v_newVal + 1;
    --set the sequence to that value
    LOOP
    EXIT WHEN v_incval>=v_newVal;
    SELECT OFI_SERVICE_PROVIDER_ofi_servi.nextval INTO v_incval FROM dual;
    END LOOP;
    END IF;
    </br>
    I'm guessing this is a boilerplate template. I'd like to replace this with my own template code, so the generated triggers meet our own in-house specifications. And that looping method of bumping up a sequence object's NEXTVAL is hideous!
    Is there a way to modify your template with my own, so I can generate the triggers according to our needs?
    - Dan Clamage

    I'm trying to generate the code to fit our shop. These Before-Insert triggers would need to be rewritten for our environment. The template provided doesn't suit our needs. It'd make more sense if it was picked up from a text file, or at least presented on a Preferences screen, with placeholders for the sequence object name. Then a developer could tweak it to suit their own shop's needs, and have it generated correctly from the migration.
    This migration isn't a one-time deal for us. We'd be doing it over and over.

  • How to create an INSERT trigger which creates a "sequence number"

    Imagine a table T_Q with columns C_1, C_2, C_3 and UN_123.
    C_1, C_2 and C_3 are all numeric and given by the user.
    UN_123 has to be a calculated sequence number starting by 1 and incremented by 1 for each combination of C_1, C_2 and C_3, i.e., the sequence number depends on the key values C_1, C_2 and C_3.
    Could anybody provide a code sample on how to create a BEFORE INSERT trigger , which calculates the value of the column UN_123 based on the values of C_1, C_2 and C_3 ??
    Premise: Rather than using any sequence, the trigger code should only be based on the table T_Q
    null

    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Rainer Wagner ([email protected]):
    Imagine a table T_Q with columns C_1, C_2, C_3 and UN_123.
    C_1, C_2 and C_3 are all numeric and given by the user.
    UN_123 has to be a calculated sequence number starting by 1 and incremented by 1 for each combination of C_1, C_2 and C_3, i.e., the sequence number depends on the key values C_1, C_2 and C_3.
    Could anybody provide a code sample on how to create a BEFORE INSERT trigger , which calculates the value of the column UN_123 based on the values of C_1, C_2 and C_3 ??
    Premise: Rather than using any sequence, the trigger code should only be based on the table T_Q<HR></BLOCKQUOTE>
    null

  • CALL FUNCTION 'API_SEMBPS_FUNCTION_EXECUTE'

    We r maintaining some bps function wition our project...with 
    CALL FUNCTION 'API_SEMBPS_FUNCTION_EXECUTE'
    before it used to work  without errors and sometimes with short dumps ...only remarks..
    but now it is not working ........
    we should do this manuelly in TCODE "bps0"
    with  "Execute Planning seq. in Background"
    can anybody help me to make the program to run automatically...

    HAI BINDU;
    TNX FOR QUICK REPLY..
    actually we r using this prog.. to
    getting the data from deltas into transaction cube...
    THEN THE PROGRAM DOES the following
    SPLITS the data and writes into target systems......
    here is the program......
    REPORT  ziv_upc_kapro_mc_dummydistr             .
    DATA: ltk_return TYPE STANDARD TABLE OF bapiret2.
    DATA: ls_return TYPE bapiret2.
    DATA: l_subrc LIKE sy-subrc.
    Planungsfunktion ausführen
    CALL FUNCTION 'API_SEMBPS_FUNCTION_EXECUTE'
      EXPORTING
        i_area     = 'ZIVASMP1'
        i_plevel   = 'ZIVKAPRO'
        i_package  = 'ZIVKAPRO'
        i_function = 'ZIVKAPRO'
        i_param    = 'ZIVKAPRO'
      IMPORTING
        e_subrc    = l_subrc
      TABLES
        etk_return = ltk_return.
    wenn schiefgeht --> dump
    IF l_subrc <> 0.
      MESSAGE x009(ziv_upc).
    sonst buchen
    ELSE.
      CLEAR l_subrc.
      CALL FUNCTION 'API_SEMBPS_POST'
        IMPORTING
          e_subrc   = l_subrc
          es_return = ls_return.
    wenn schiefgeht --> dump
      IF l_subrc <> 0.
        MESSAGE x009(ziv_upc).
    sonst speicher freigeben
      ELSE.
        CLEAR: l_subrc, ls_return.
        CALL FUNCTION 'API_SEMBPS_REFRESH'
          IMPORTING
            e_subrc   = l_subrc
            es_return = ls_return.
      ENDIF.

  • Truncate field before insert

    Suppose I have the following:
    table: mytable
    field: username (VARCHAR2(35))
    field: zip (VARCHAR2(5))
    I am importing data from an excel file with columns username and zip. A couple of the usernames contain more than 35 characters, and some of the zipcodes are in the xxxxx-xxxx format, thus containing more than 5 characters.
    I attempted to write a before insert trigger to truncate the data before they are inserted. For any username that is above 35 characters from the excel file, just truncate the username to the first 35 characters. Similarly, for any zip code that is above 5 characters, just truncate the zip to the first 5 characters.
    The trigger for the zip codes:
    CREATE OR REPLACE
    TRIGGER trigger_zipc
      BEFORE INSERT
      ON mytable
      FOR EACH ROW
    BEGIN
      SELECT substr(:new.zip, 1, 5)
      INTO :new.zip
      from dual;
    END;
    However, I get the error: ORA-12899: value too large for column
    I've read on other forums that this is what happens, and that a possible work around is to use INSERT INSTEAD??
    Can anyone give me a solution or point me in the right direction?

    Can anyone give me a solution or point me in the right direction?
    Sure - the 'right direction' is to mark this thread ANSWERED and repost your question in the Sql and Pl/Sql forum:
    PL/SQL
    This forum is ONLY for Sql Developer questions and your question doesn't appear to have anything to do with that tool.
    As the exception says the value is too large for the column. Your code that tries to trim the value will NEVER be executed because the exception occurs BEFORE it ever gets that far.
    The buffer that Oracle creates to hold that :NEW value is too small to hold the value you try to insert - that is why you get the exception.
    You can NOT use a trigger to perform validations such as those since the data will NEVER make it into the buffer the trigger uses.before it ever executes your code.

  • Where in the Code can I Call a function Before Insert

    Hi, using DWMX and VBSCRIPT with n MS Access table set on a
    W2k3 server and ASP
    I need to insert a value 'intGradID' from a function into a
    hidden field 'hGradID' when the submit button (to insert a record
    in an access database) is clicked (and before insert takes place as
    this is the key field that I am adding).
    I realise Javascript might be required (not too great with
    Java) so any help please tell me where to put script/code and what
    to put. Thanks.

    Why not just setup the field in the record to be
    auto-incrementing? That way
    on insert the next # in the series is assigned to the new
    record. And even
    if 2 people someone did it at exactly the same time, the
    server takes care
    of the collision.
    "Dave(UK)" <[email protected]> wrote in
    message
    news:e9uakp$s11$[email protected]..
    > Hi, using DWMX and VBSCRIPT on a W2k3 server and ASP
    >
    > I have an on-line application form for Graduates (bound
    to Insert Into a
    > table
    > called graduates). On open of the page (at the top) I
    have some some code
    > to go
    > look in the Graduates table for the last gradID No and
    add 1 for this new
    > Graduate and I set a session variab;e with the GradID
    found and that value
    > is
    > the 'Initial Value' of a hidden field hGradID which is
    inserted into
    > GradID in
    > the table on Submit, along with the other info. Works
    Perfectly!! Until,
    > that
    > is, during the course of one Graduate registering,
    another tries to do so
    > ..
    > both get the same gradID and the one who submits last
    ends up with the
    > error
    > 'Dulicate in Key field '(ie GradID in the table). What I
    got to work was
    > to set
    > up another table (GradOn) into which at the end of the
    GradID+1 routine,
    > the
    > GradID was entered and when the form was submitted, it
    ran a routine to
    > delete
    > the contents of GradOn. Then if the form was opened
    again by another user,
    > the
    > first routine now was to check for a presence of a
    record (any record) in
    > the
    > GradOn Table - if a record existed, it redirected to a
    'Registration in
    > Progress - Please try later page' ... again all worked
    well, perfectly,
    > until
    > a. The user left the form open for hours
    > b. The user used the browser to wuit the page instead of
    the logoff which
    > ran
    > a routine to 'Delele * from GradOn'

  • Regarding before insert and update trigger...Urgent!!

    i have written a trigger to trim N upper the 1st field and trim N upper N replace period(.) for second field2 for future records.
    When i compile, it says "complied with errors" is gives error as "insuffecient privlages"
    Can anyone please figure out what problem is this??? And is my code correct?? if any changes to be done please let me know????
    create or replace trigger TRG_test
    before insert or update on test
    for each row
    declare
    begin
    :new.field1 := trim(upper(:new.field1));
    :new.field2 := trim(upper(replace(:new.field2,'.' )));
    end;
    Urgent please!!!
    Thank you in advance.

    The owner of the tables is User 2 and i am creating the trigger in user1 N i m calling this table from user2...as User2.TEST ...
    User 1 as has previliges to acess the user 2 tables, since user2 tables are listed under user1 table section...
    Do you system privilages????
    I m using PL/SQL devloper tool....

  • Before or After insert trigger on HR_API_TRANSACTION_VALUES

    I am on the termination page of SSHR and after entering the details when clcked on 'Next' the validations built in before / after insert trigger of HR_API_TRANSACTION_VALUES does not retrieve the data and the error 'No data found' is displayed.
    We do not have AME approval. When clicked on 'Next' it goes to the review page. When I do a select on the HR_API_TRANSACTION_VALUES the data do exists but the validation does not work.
    We have Oracle HRMS 11i with database as 11g.
    Please give a resolution at the earliest.

    you can use
    hr_transaction_api.set_varchar2_value
    or
    hr_transaction_api.set_number_value
    based on what type of value that you want to update

  • Calling of Stored Procedure in After Insert Trigger

    Can I call a Stored Procedure in After Insert Trigger ?
    Please send a sample code (good example) of After Insert Trigger.
    Thanks.

    Kishore,
    I have two table WLCS_ORDER, WLCS_ORDER_LINE
    WLCS_ORDER - It holds order header information like
    ORDER_ID
    CUSTOMER_ID
    TRANSACTION_ID
    STATUS
    ORDER_DATE
    SHIPPING_METHOD
    SHIPPING_AMOUNT
    SHIPPING_CURRENCY
    PRICE_AMOUNT
    PRICE_CURRENCY
    SHIPPING_GEOCODE
    SHIPPING_STREET1
    SHIPPING_STREET2
    SHIPPING_CITY
    SHIPPING_STATE
    SHIPPING_COUNTRY
    SHIPPING_POBOX
    SHIPPING_COUNTY
    SHIPPING_POSTAL_CODE
    SHIPPING_POSTAL_CODE_TYPE
    SPECIAL_INSTRUCTIONS
    SPLITTING_PREFERENCE
    ORDER_SUBTOTAL
    WLCS_ORDER_LINE - It holds all order lines information like
    ORDER_LINE_ID
    QUANTITY
    PRODUCT_ID
    TAX_AMOUNT
    TAX_CURRENCY
    SHIPPING_AMOUNT
    SHIPPING_CURRENCY
    UNIT_PRICE_AMOUNT
    UNIT_PRICE_CURRENCY
    MSRP_AMOUNT
    MSRP_CURRENCY
    DESCRIPTION
    ORDER_ID
    TOTAL_LINE_AMOUNT
    Relation between WLCS_ORDER, WLCS_ORDER_LINE is one to many.
    For each WLCS_ORDER row, one or more order lines will insert into WLCS_ORDER_LINE table.
    For each new row in WLCS_ORDER table, I have to update the following columns in both the tables with my maths.
    WLCS_ORDER
    shipping_amount
    price_amount
    order_subtotal
    WLCS_ORDER_LINE
    shipping_amount
    I thought I can do this in after insert trigger, But if it is not possible, Please give the best way to fulfill this requirement.
    I appreciate your help.
    Have a great day.
    Srinivas

  • Trigger that checks if value exists in another table before insert

    Hi,
    Can any one help me with the correct code.
    I am trying to write a trigger that checks if the new value (:new.T1) does not exist in another table (T2) before entering it (in T1).
    Create or replace trigger T1
    BEFORE
    insert on T1
    for each row
    Declare
    x Number;
    begin
    SELECT Count (*) INTO x
    From T2 WHERE T2.Col1 = :new.T1;
    IF (x > 1 or x = 1) Then
    DBMS_OUTPUT.PUT_LINE('This value has been used before try another one.');
    END IF;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    INSERT INTO T2 (Col1) values (:new.T1);
    WHEN TOO_MANY_ROWS THEN
    DBMS_OUTPUT.PUT_LINE('This value has been used before try another one.');
    end;

    I think this question is suitable for the SQL and PL/SQL forum.

Maybe you are looking for

  • I need s:list display 2 colums item, like mx:tilelist.

    RT, How can I do, I need 2 colums item,  I write itemrenderer, set some properties, but it's not work. I want s:list like mx:tilelist. Please help me. code is here:       c2.mxml <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="http://

  • How do you connect wireless headphones to a dvr?

    Solved! Go to Solution.

  • Error 25308 on importing GoDaddy cert with Server Admin

    Greetings, We're in the process of migrating from Tiger Server 10.4.11 to Leopard Server 10.5.6. We did a clean install of 10.5.3 on a new machine, updated to 10.5.6, and started migrating user data. It's gone well, except that we can't import our Go

  • Ringer volume mutes on its own

    I've noticed that sometimes when I use the side switch to silence the ringer and then switch back again, my ringer volume (in Settings) is zeroed out. So in effect, the quick switching of the ringer off and on again doesn't do the job but keeps the p

  • Flash 8 or 9 Publishing error after Flash9 installation

    Hi. I had my dear Flash 8 installed and everything was working fine till I decided to install the Adobe Lab's Flash 9 AS3 Preview Alpha. Since then, inside Flash, every time I publish a movie and do "ctrl+Enter" 2 times to simulate download, it gives