DB Trigger error - Updating same table in the trigger script

Hi All,
I have a table tab1, when ever any update is done on this table on column col1 then col2 also need to get update.(These are linked to forms so user can update only col1 from form frontend)
so I created a trigger as follows.
CREATE OR REPLACE TRIGGER tri1
AFTER UPDATE
ON tab1
FOR EACH ROW
WHEN (NEW.col1 = 'YES')
DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
UPDATE tab1 SET col2= 1
WHERE transaction_id = :OLD.transaction_id;
COMMIT;
END;
When there is any update on this table I get following error. Please let me know if I miss any thing.
ORA-00060: deadlock detected while waiting for resource
ORA-06512: at "user1.tab1", line 5
ORA-04088: error during execution of trigger 'user1.tab1'
Please let me know if I am not clear. Thanks
Edited by: DharV on Aug 23, 2011 5:17 AM

Is your transaction_id unique?
If that is the case then you could perhaps use BEFORE UPDATE instead of AFTER UPDATE:
CREATE OR REPLACE TRIGGER tri1
BEFORE UPDATE
ON tab1
FOR EACH ROW
WHEN (NEW.col1 = 'YES')
BEGIN
   :NEW.col2 := 1;
END;If your transaction_id is not unique - so you really want to update more than one row in tab1 - your update cannot update the same row as the trigger reacted upon, even with the use of autonomous transaction. Then you could combine the above BEFORE UPDATE trigger with your own AFTER UPDATE, but then add ROWID != :OLD.ROWID to the where clause, but it would be a bad idea because some of your rows will be updated in one transaction and others in another transaction.
In general autonomous transaction is not a great way to solve mutating table problem in a trigger. Hopefully you have a unique transaction_id and can do BEFORE UPDATE - if not then a better way is to save the id's to be updated in a package array in the FOR EACH ROW triggers, and then do a AFTER UPDATE trigger that is NOT "for each row" to update the list of saved id's.

Similar Messages

  • Trigger in mutation - Update another rows in the same table with a trigger

    Hi ,
    I try to do a before update trigger on a table , but the trigger is in mutation. I understand why it do that but my question is :
    How can I update other rows in the same table when a UPDATE is made on my table??????
    Here is my trigger :
    CREATE OR REPLACE TRIGGER GDE_COMPS_BRU_5 BEFORE
    UPDATE OF DEPARTEMENT--, DISCIPLINE, DEG_DEMANDE, CE_ETAB
    ON GDEM.COMPOSITION_SUBV
    FOR EACH ROW
    Organisme : FQRNT-FQRSC
    Date de création : 14-07-2011
    Date de modification :
    Modifié par :
    Auteur : Johanne Plamondon
    Description : Ce déclencheur s'executera lors de la modification
    du responsable dans la table COMPOSITION_SUBV
    DECLARE
    V_OSUSER V$SESSION.OSUSER%TYPE;
    V_PROGRAM V$SESSION.PROGRAM%TYPE;
    V_TERMINAL V$SESSION.TERMINAL%TYPE;
    V_MACHINE V$SESSION.MACHINE%TYPE;
    V_MODULE V$SESSION.MODULE%TYPE;
    V_LOGON_TIME V$SESSION.LOGON_TIME%TYPE;
    V_AUDIT_ID NUMBER;
    vSEQ NUMBER;
    i NUMBER;
    vID DEMANDE.ID%TYPE;
    BEGIN
    begin
    SELECT OSUSER, PROGRAM, TERMINAL,MACHINE,MODULE, LOGON_TIME
    INTO V_OSUSER,V_PROGRAM,V_TERMINAL,V_MACHINE,
    V_MODULE,V_LOGON_TIME
    FROM V$SESSION
    WHERE TYPE = 'USER'
    AND USERNAME = USER
    AND LAST_CALL_ET IN (0,1)
    AND ROWNUM < 2;
    exception when others then null; end;
    IF NVL(:NEW.SC_PART,' ') = 'CHC' THEN
    SELECT COUNT(*)
    INTO i
    FROM DEMANDE
    WHERE DEM_REF = :NEW.DEM_ID
    AND PER_NIP = :NEW.PER_NIP;
    IF i = 1 THEN
    SELECT ID
    INTO vID
    FROM DEMANDE
    WHERE DEM_REF = :NEW.DEM_ID
    AND PER_NIP = :NEW.PER_NIP;
    UPDATE COMPOSITION_SUBV
    SET --CE_ETAB     = :NEW.CE_ETAB,
    --DISCIPLINE  = :NEW.DISCIPLINE,
    DEPARTEMENT = :NEW.DEPARTEMENT,
    --DEG_DEMANDE = :NEW.DEG_DEMANDE,
    DATE_MODIF = SYSDATE,
    USER_MODIF = V_OSUSER
    WHERE DEM_ID = vID
    AND PER_NIP = :NEW.PER_NIP
    AND ANNEE = :NEW.ANNEE;
    END IF;
    END IF;
    /*EXCEPTION
    WHEN OTHERS THEN
    NULL;*/
    END;

    A standard disclaimer, the mutating trigger error is telling you that you really, really, really don't want to be doing this. It generally indicates a major data model problem when you find yourself in a situation where the data in one row of a table depends on the data in another row of that same table. In the vast majority of cases, you're far better off fixing the data model than in working around the problem.
    If you are absolutely sure that you cannot fix the data model and must work around the problem, you'll need
    - A package with a collection (or global temporary table) to store the keys that are modified
    - A before statement trigger that initializes the collection
    - A row-level trigger that adds the keys that were updated to the collection
    - An after statement trigger that iterates over the data in the collection and updates whatever rows need to be updated.
    If you're on 11g, this can be simplified somewhat by using a compound trigger with separate before statement, row-level, and after statement sections.
    Obviously, though, this is a substantial increase in complexity over the single trigger you have here. That's one of the reasons that it's generally a bad idea to work around mutating table exceptions.
    Justin

  • Two forms that update differrent tables on the same page?

    I tried to add two forms that update different tables on to one page.
    Problem is when I do that the forms gives me an error saying the field does not exist. It's like it is trying to update one table with the other tables fields.
    As an example Say I have one forms that is for people table and another one that is the Jobs table.
    When I go to update the people table, it sends the data for the jobs fields too I get an error like the field job description does not exist.
    I have two different forms for these and everything.
    I would hope it is possible to have two forms that update different tables on the same page.

    I was trying the exact same thing, but i managed to work round it by setting the steps to hide one region, so the user would enter the form see one region submit the region then direct back to the same page with the different region visible and the original hidden.
    I don't know if this would be acceptable for you...

  • Updating two tables at the same time

    Please,
    Does someone have an idea on how to update two tables at the same times?
    Thanks a lot in advance

    I was thinking about a single session and single update command.
    That's why I thougth someone else could have a clue.
    Thank you

  • Trigger and Update Flag Table

    I've recently started trying to automate around a dozen procedures. These procedures are set to run immediately after the necessary previous procedure(s) is(are) done.
    What I am attempting to accomplish is a single generic trigger that will fire off each procedure when its parent procedures have finished firing. This will be accompanied by an update_flag table with three columns
    PARENT_PRC----------------------CHILD_PRC----------------------FLAG
    parent_prc_name1--------------child_prc_name1-----------------N
    parent_prc_name1--------------child_prc_name2-----------------N
    parent_prc_name3--------------child_prc_name3-----------------Y
    Logic:
    *1.*     When a procedure fires it updates this table to set any rows in which it is the “PARENT_PRC” by updating the FLAG column to = Y.
    *2.*     The trigger will execute a child procedure if its flag (or in the case of multiple parent procedures; all of its flags) are set to 'Y'. This trigger is set to fire AFTER a table update on the UPDATE_FLAG table.
    ----a.     I have to execute the procedure UFLAG in a job because I want the trigger to execute the procedure and then continue running immediately, rather than wait for the procedure to finish then commit. This way the trigger could start several procedures all running at the same time.
    ----b.     I have made it an autonomous transaction because I needed the job to fire immediately rather than be queued, which required a commit within the trigger.
    *3.*     The last step is to set the flag in UPDATE_FLAGS back to 'N' for CHILD_PRC = '||uflag||' once the child procedure is complete.
    ----a.     I have tried placing the update child_prc = 'N' in the trigger but it won’t allow a trigger that fires on update to update the same table.
    ----b.     I want to avoid putting the update statement in all of my procedures because I would like the option of running these procedures manually for testing purposes WITHOUT effecting the update_flags table.
    Number 3. is the key problem I have been having. Placing code within the trigger to update the update_flags table setting 'Y's back to 'N's once the procedures have fired causes a deadlock error.
    I believe this is simply because the trigger is attempting to update a table which (upon updating) causes the same trigger to fire before it has finish executing.
    How can I update the Flag table to reset the update flags back to 'N'?
    Is there a different way of doing this all together?
    Here is some code with dummy procedures that demonstrates what I have so far.
    With this code, executing parent procedures should set the update_flag table to 'Y' for FLAG where procedure = 'parent_prc'.
    I need to find a way to execute the child procedures AND set the FLAG column back to 'N' from the trigger.
    ex. executing parent_1 should set update_flags.flag = 'Y' where parent_prc = 'parent_1' and thus execute procedure CHILD_A and CHILD_B.
    create table update_flags (parent_prc varchar2(10), child_prc varchar2(10), flag varchar2(1));
    insert into update_flags values('parent_1', 'child_a', 'N');
    insert into update_flags values('parent_1', 'child_b', 'N');
    insert into update_flags values('parent_2', 'child_c', 'N');
    insert into update_flags values('parent_3', 'child_c', 'N');
    insert into update_flags values('parent_4', 'child_d', 'N');
    CREATE OR REPLACE procedure parent_1 as
    BEGIN
    update update_flags set flag = 'Y' where parent_prc = 'parent_1';
    END parent_1;
    CREATE OR REPLACE procedure parent_2 as
    BEGIN
    update update_flags set flag = 'Y' where parent_prc = 'parent_2';
    END parent_2;
    CREATE OR REPLACE procedure parent_3 as
    BEGIN
    update update_flags set flag = 'Y' where parent_prc = 'parent_3';
    END parent_3;
    CREATE OR REPLACE procedure parent_4 as
    BEGIN
    update update_flags set flag = 'Y' where parent_prc = 'parent_4';
    END parent_4;
    CREATE OR REPLACE procedure child_a as
    BEGIN
    dbms_output.PUT_LINE('CHILD_A Worked');
    commit;
    END child_a;
    CREATE OR REPLACE procedure child_b as
    BEGIN
    dbms_output.PUT_LINE('CHILD_B Worked');
    commit;
    END child_b;
    CREATE OR REPLACE procedure child_c as
    BEGIN
    dbms_output.PUT_LINE('CHILD_C Worked');
    commit;
    END child_c;
    CREATE OR REPLACE procedure child_d as
    BEGIN
    dbms_output.PUT_LINE('CHILD_D Worked');
    commit;
    END child_d;
    CREATE OR REPLACE TRIGGER MASTER_TRG
    AFTER UPDATE
    ON UPDATE_FLAGS
    DECLARE
    Pragma  AUTONOMOUS_TRANSACTION;
    BEGIN
      DECLARE
      job_num number;
      uflag varchar2(1000);
      BEGIN
            select  MAX(case when COUNT(case when flag='Y' then 1 end)=COUNT(*) then CHILD_PRC else '  ' end)
            into uflag
            from        update_flags
            group by    child_prc;
            IF   uflag <> '  ' THEN
                                      --update update_flags set  flag = 'N' where child_prc = uflag     --(line of code that causes deadlock error)
                            dbms_job.submit (job => job_num,
                            what => ' '||uflag||';'
            END IF; 
       END;            
    COMMIT;
    END MASTER_TRG;
    execute parent_2;
    execute parent_3;

    >
    I think I am getting my head around the transactional/trigger issue.
    >
    It doesn't sound like it since you are still talking 'triggers'. At any rate it is OP that needs to get their head around it.
    OP doesn't even know what the entire process needs to be but has already decided that
    1. a single generic trigger that will fire off each procedure when its parent procedures have finished firing
    2. an update_flag table with three columns: PARENT_PRC, CHILD_PRC, FLAG
    3. a procedure fires it updates this table to set any rows in which it is the “PARENT_PRC” by updating the FLAG column to = Y.
    4. a job - I have to execute the procedure UFLAG in a job
    5. I have made it an autonomous transaction because I needed the job to fire immediately rather than be queued, which required a commit within the trigger.
    6. there should be an option of running these procedures manually for testing purposes WITHOUT effecting the update_flags table.
    Fortunately OP had the wisdom to ask
    >
    Is there a different way of doing this all together?
    >
    Doesn't anyone design things anymore? Seems like everyone just wants to decide what the solution ought to be be and then try to force the problem to fit into it.
    The first stage is the DESIGN - not the implementation details or technology to use.
    The first design step is to outline, or flowchart, the PROCESS that needs to take place. Since OPs post lacks sufficient detail I will substitute my own 'guesstimations' to illustrate.
    1. there are one or more 'parent' processes
    2a. these parent processes are allowed to run in parallel as they do not interfere in any way with the processing done by other parent or child processes. (is this true?)
    2b. these parent processes ARE NOT allowed to run in parallel as they may interfere with each other.
    3. Each parent process can have one or more 'child' processes. (it appears that these aren't really children but rather processes that are 'dependent' on the parent or that must always be executed after, and each time that the parent executes.
    So here are just SOME of the things that are missing that must be known before possible alternatives can be explored
    1. Re item #2 - can the parent processes be executed in parallel? Or must they be executed serially? Will any of the parent processes be dependent on any other parent or child process?
    2. What is the relationship between a parent process and its child processes? Is the parent always executed first? What triggers the parent execution? How often is it executed?
    What if it is already executing? What if other parent processes are currently executing? What if one or more of its child processes are executing? What if the parent process fails for any reason - what action should be taken?
    Based on what was posted a set of parent and child processes might need nothing more than: execute parent, execute child1, execute child2, . . ., execute childn.
    3. What is the relationship between the child processes that belong to the same parent? Can they be executed in parallel (i.e. are they completely independent)? Or must they be executed in some particular order? What if one or more of the child processes fails for any reason - what action should be taken?
    4. Will any other user or process be executing these parent or child processes? That could interfered with the automated stream.
    5. What type of exception handling and recovery needs to be implemented in one or more steps of the processing fail for some reason?
    Typically there is often one or more control tables (OPs flag table) to control and limit the processing. But the table would have status information for every process not just the children:
    A. STATUS - DISABLED, ACTIVE, RUNNING, IDLE, ERROR
    B. START_TIME
    C. END_TIME
    D. RESULT_CODE
    The control table can be used by a parent or child process to determine if it is permitted to run. For example the first thing a procedure might do is check it's own STATUS. If it is already running it would exit or log an error or message. If that test is passed it might check the status of any dependent processes. For example it might check that its child processes are ACTIVE and ready to run; if a child was still running the parent would exit or log an error or message.
    The control process would lock the appropriate control table records (FOR UPDATE) and would set the status and other fields appropriately to prevent interference by other processes or procedures.
    Design first. Then look at the implementation options.

  • Howto trigger an update of SCEP at the end of the task sequence?

    Hi,
    Howto trigger an update of SCEP at the end of the task sequence?
    Please advise.
    J.
    Jan Hoedt

    Do you know if the command is running in WinPE mode or full-OS mode? You might try wrapping the command into a .bat or .cmd file and then running that through the task sequence.
    Edit - I don't know how you're doing your task sequence initializing (e.g. unknown computers, OSD imaging collections, etc), but do you have a Client Policy (not Endpoint Protection Policy) set to allow SCEP to be managed?  And if so, how are your imaged
    PC's getting into the collection to be managed.  Same for SCEP updates.
    What I wonder is if your PC's know they have updates deployed to them.  That command line, if I remember right, will search for your internal update server, aka WSUS/SCCM for updates.  If the device does not have SCEP updates deployed to it, that
    command will do nothing.  If you add -MMPC to the end of it the device will download from Microsoft.
    There's a setting client setting for Endpoint protection called Disable Alternate Sources for the Initial Update.  What is that set to?  Sorry, I know I just threw a bunch of information at you and asked a lot of questions.

  • Is 2 external table allowed for same table in the same db.

    Hi,
    Is it possbile to have 2 external tables in a database for the same table? The intention is to run the loading in parallel.
    I would be highly grateful if someone can answer my query?
    Regards,
    Ankit Agrawal.

    Hi,
    Is it possbile to have 2 external tables in a database for the same table?Yes you can, with usage of view which make an union...
    The intention is to run the loading in parallel.You can use sqlldr with parallel clause
    => http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96652/ch09.htm#1008227
    Nicolas.

  • How to create table in the sap script

    Hi,
    How to create a table in the  sap script layout, i Have to use table in the main window with  7 columns. can any one send sample code.
    How to calculate the number of line items which are displaying in the main window, if the number of line items are exceed in the main window then the amount has to be calculate and print as "BALANCE FORWARD" and the next page had to be displayed as "CARRY FORWARD" that amount. if this is the last page not subsequent page the amount had to be calculated the carry forward amount and total amount and print as "TOTAL AMOUNT". i am creating the new layout and the program is the standrad driver program i have to use and i have to use the standard Text elements only, can any one help me on this issue

    hi
    good
    there is no "pattern" option in SAPscript. All you have at your disposal are the following SAPscript commands: BOX, POSITION and SIZE. Not only are these commands both confusing and tedious to implement, they also are limited in what they can achieve. For instance, although you can suppress a box during printout (by making it conditional), there is no simple way to adjust it dynamically instead. Thus, to divide sequential line items, you may wish to use an underline (ULINE) or simply white space.
    thanks
    mrutyun

  • I am trying to get my vi to trigger, not sure where to add the trigger

    I need a vi that can trigger using an analog rising edge (1V), then produces a square wave (any square wave will do for now), and then show the measurement of the waveform.  Attached is the code that I have made so far.  Not sure how to get a trigger attached, or where to place the trigger, onto what I have done so far.  Another question is where to have it triggered from, do I need to add another generate waveform to produce the trigger signal?
    Any help is appreciated!!
    -ncm
    Solved!
    Go to Solution.
    Attachments:
    Generate and Read Waveform.vi ‏39 KB

    Hi,
    You can place a DAQmx start trigger VI in the code at the top, between the DAQmx Timing and DAQmx write VIs, and then set the trigger type to "Analog Edge" and specify the channel to trigger from (in this case I think you would use the APFI line on your card).  Check out the 'Voltage - Continuous Output' Example'  if you need help implementing this in code, that example covers analog output with different types of triggering in a setup similar to yours.
    Matt Lee
    National Instruments
    Applications Engineer

  • Trigger Issue while updating same table

    Hi all,
    I am creating one after insert trigger on table tests, which will check, if application id is null, application will be fetched from another table and update the table
    tests table. But this trigger is not updating the application id of the table tests
    CREATE OR REPLACE
    TRIGGER TB_REC_APPL_TESTS1
    AFTER INSERT ON tests FOR EACH ROW
    DECLARE
    v_application_id NUMBER;
    v_rec_appl_tests_id NUMBER;
    v_a_recruit_id NUMBER;
    PRAGMA AUTONOMOUS_TRANSACTION;
    BEGIN
    v_rec_appl_tests_id := :NEW.rec_appl_tests_id;
    v_a_recruit_id := :NEW.a_recruit_id;
    IF :NEW.a_applic_id IS NULL THEN
    SELECT a_applic_id INTO v_application_id FROM recruit WHERE a_recrut_id = v_a_recruit_id;
    dbms_output.PUT_LINE(v_application_id||'-'||v_rec_appl_tests_id);
    UPDATE tests SET a_applic_id = v_application_id
    WHERE rec_appl_tests_id = v_rec_appl_tests_id;--:NEW.rec_appl_tests_id;
    END IF;
    commit;
    END;
    Thanks in advance,
    Pal

    user546710 wrote:
    Hi all,
    I am creating one after insert trigger on table tests, which will check, if application id is null, application will be fetched from another table and update the table
    tests table. But this trigger is not updating the application id of the table tests
    CREATE OR REPLACE
    TRIGGER TB_REC_APPL_TESTS1
    AFTER INSERT ON tests FOR EACH ROW
    DECLARE
    v_application_id NUMBER;
    v_rec_appl_tests_id NUMBER;
    v_a_recruit_id NUMBER;
    PRAGMA AUTONOMOUS_TRANSACTION;
    BEGIN
    v_rec_appl_tests_id := :NEW.rec_appl_tests_id;
    v_a_recruit_id := :NEW.a_recruit_id;
    IF :NEW.a_applic_id IS NULL THEN
    SELECT a_applic_id INTO v_application_id FROM recruit WHERE a_recrut_id = v_a_recruit_id;
    dbms_output.PUT_LINE(v_application_id||'-'||v_rec_appl_tests_id);
    UPDATE tests SET a_applic_id = v_application_id
    WHERE rec_appl_tests_id = v_rec_appl_tests_id;--:NEW.rec_appl_tests_id;
    END IF;
    commit;
    END;
    Thanks in advance,
    Palyou are creating triger on the table and updating it. It will not allow to update since you are firing trigger on same table.
    Best practice is to use other table to update or any other operation.

  • Update Trigger Assistance - Update Same Row More than Once?

    Good morning,
    I'm new to Triggers and am not understanding why this is not working.  I've tried the web and none of the articles seem to answer my question.  What I'm trying to do is clean a string and standardize some data the users input into a 1000 character
    varchar field.  I have a source table which has a trigger on it that inserts a limited number of columns that we'll use for reporting purposes.  After the row has been inserted into the table (referred to as "destination" in the code block),
    I'm looking to update the comments string, capitalizing the first character of the string, standardizing spacing after a colon, removing hyphens at the beginning of the string.  The source and destination tables both have the comments field as a varchar
    1000, not null data type with a key id between the source and destination tables.  At another segment of our system, there were errors reporting nulls and when this was removed, everything cleared up.  I can do a series of replace statements when
    the data is required in reports but would rather have it clean in the destination table.  The code is below:
    CREATE TRIGGER [dbo].[destination_Update_trg]
    ON [dbo].[destination]
    AFTER UPDATE
    AS
    BEGIN
    SET NOCOUNT ON;
    IF EXISTS (SELECT *
    FROM destination C
    JOIN INSERTED I
    ON I.PrimaryKeyID = C.PrimaryKey
    WHERE I.Comments IS NOT NULL AND I.Comments <> '')
    BEGIN
    UPDATE T
    SET T.Comments =
    CASE
    WHEN T.Comments <> '' AND LEFT(CAST(T.Comments AS VARCHAR (1000)), 2) LIKE '- %'
    THEN SUBSTRING(T.Comments, 3, 1000)
    END
    FROM destination T
    JOIN INSERTED I
    ON T.primarykey = I.primarykey
    WHERE T.primarykey = I.primarykey
    UPDATE T
    SET T.Comments = UPPER(LEFT(CAST(T.Comments AS VARCHAR (1000)), 1)) + SUBSTRING(CAST(T.Comments AS VARCHAR (1000)), 2, 1000)
    FROM destination T
    JOIN INSERTED I
    ON T.primarykey = I.primarykey
    WHERE T.primarykey = I.primarykey
    UPDATE T
    SET T.Comments = REPLACE(SUBSTRING(T.Comments, 1, 1000), ': ', ': ')-- '[A-9]: [A-9]'
    FROM destination T
    JOIN INSERTED I
    ON T.primarykey = I.primarykey
    WHERE T.primarykey = I.primarykey
    AND SUBSTRING(T.Comments, 1, 1000) LIKE '%[A-Z]%: [A-Z]%'
    END
    RETURN
    END;
    GO
    Perhaps there's a better way to accomplish the task. I appreciate your review and assistance. Thank you.

    First, the trigger only fires when you do an UPDATE.  I'm not sure from your description whether or not you are expecting this trigger to fire when you do an insert on dbo.destination.  If you want it to fire on INSERTs, then you need to specify
    FOR INSERT (or FOR INSERT, UPDATE if you want it to fire on both inserts and updates).
    More importantly, the first update in your trigger does
    SET T.Comments =
    CASE
    WHEN T.Comments <> '' AND LEFT(CAST(T.Comments AS VARCHAR (1000)), 2) LIKE '- %' THEN SUBSTRING(T.Comments, 3, 1000)
    END
    When you do a CASE and you don't have an ELSE clause, there is an implicit ELSE NULL clause added.  So your update is equivalent to
    SET T.Comments =
    CASE
    WHEN T.Comments <> '' AND LEFT(CAST(T.Comments AS VARCHAR (1000)), 2) LIKE '- %' THEN SUBSTRING(T.Comments, 3, 1000)
    ELSE NULL
    END
    So your very first update sets the Comments column to NULL in every row that was updated where the Comments column is not like '- %'.  You want to change the case statement to be
    SET T.Comments =
    CASE
    WHEN T.Comments <> '' AND LEFT(CAST(T.Comments AS VARCHAR (1000)), 2) LIKE '- %' THEN SUBSTRING(T.Comments, 3, 1000)
    ELSE T.Comments
    END
    (Or you can put the test in the where clause so that you only update those rows where the Comments column is like '- %'.  That would look like
    UPDATE T
    SET T.Comments = SUBSTRING(T.Comments, 3, 1000)
    END
    FROM destination T
    JOIN INSERTED I
    ON T.primarykey = I.primarykey
    WHERE LEFT(CAST(T.Comments AS VARCHAR (1000)), 2) LIKE '- %'
    (Note that you do not need to include the T.Comments <> '' because if T.Comments is Like '- %', then it cannot be the empty string and you do not need to include WHERE T.primarykey = I.primarykey because you know that is true since you did an inner
    join on T.primarykey = I.primarykey.
    Tom

  • For the same table in the same page, how to use 2 different forms (simple and tabular)?

    Hello! How I can be on the same page with the same table insert and update operations using 2 different forms (single form and tabular form)
    I have little knowledge of Apex, but I know PLSQL
    Thanks
    Ginger
    Ecuador

    Thank you Gramps.  It took some time, but I've got it working now.  I had to re-do all the user authentication actions from scratch for one of the databases, but it's finally behaving itself now.  I appreciate you pointing me in the right direction.

  • Error in Forms while creating the trigger- WHEN-CREATE-RECORD

    Hello,
    Right now I am using 11g client side and 10g database.
    I am constantly getting an error while creating triggers in 11g.
    I have created a sequence in SQL developer using the following code:
    create sequence loc_id_sequence
    start with 14;
    After creating the sequence. I am trying to write the PL/SQL code in forms builder for the trigger WHEN-CREATE-RECORD
    declare
    loc_id number;
    begin
    loc_id := loc_id_sequence.nextval;
    end;
    But I have been getting the following error constantly. Can anyone please help me?
    "Error 0 at line 5, column 4
    SQL statement ignored".
    Can anyone please tell me why I am getting that error

    In fact, even I thought there might be some problem with the connectivity with the 10g database and 11g client but the other DB related code works.
    I just have the problem with using sequence for the trigger WHEN-CREATE-RECORD.
    In fact I also tried using WHEN-NEW-RECORD-INSTANCE smart trigger instead of WHEN-CREATE-RECORD for the same sequence. But even that doesn't work.
    Do u have any idea of what that error means?
    "Error 0 at line 5, column 4
    SQL statement ignored"
    Edited by: Pooja 1985 on Feb 26, 2013 5:43 PM
    Edited by: Pooja 1985 on Feb 26, 2013 5:44 PM

  • Oracle 11gr2 ODBC - error updating linked table (Ora 01722 and 01461)

    Good day folks,
    My shop has just moved to 11gR2 client and server. We were previously using 11gR1 with no issues (and before that, 10, 9, 8, etc). After moving from 11r1 to 11r2, we began getting errors from some of our MS Access ODBC applications with linked Oracle tables. The error would occur when executing an UPDATE statement that had a table join in it. Here is a simple example:
    UPDATE TableX SET TableX.Fieldx = “valuex” WHERE TableX.Fieldx = TableZZZ.Fieldx AND TableZZZ.fieldzzz is not null
    Currently, after moving to 11r2 client, an update query like the one above will error out in one of the following ways:
    - odbc -- update on a linked table failed - Ora 01722 invalid number
    - ORA-01461: can bind a LONG value only for insert into a LONG column
    - Or it will say that the records were not updated because they are locked.
    In some cases, I have noticed some records being updated that were not supposed to be updated.. records that the where clause was meant to exclude. That is very unsettling.
    I understand that perhaps an update statement shouldn’t be joining table and perhaps it should be done over a couple calls, but the reality is – this code is out there in abundance and if there is a solution that doesn’t amount to my changing all this code or reverting to 11gR1, I would love to find it.
    Since the query runs fine using SQL Plus and also runs fine if I run it against a local table in Access rather than a linked Oracle table – I figured the issue was possibly with the Oracle 11r2 ODBC driver. So, I switched the Oracle ODBC driver (sqora32.dll version 11.2.0.1 with version 11.1.0.7), and the problem went away.
    I believe this verifies the issue resides with Oracle ODBC version 11.2.0.1. Can anyone help? I'm assuming it's not particularly wise to simply swap sqora32.dll files on all my clients machines, so I am searching for an actual solution here instead.
    I also did performed ODBC tracing to see what Access is handing to the Oracle ODBC driver. I then used database or SQLNet tracing to see what the ODBC driver was handing off to SQLNet/database.
    The results are in the following post:
    Thanks guys!!

    SQLNET TRACE
    If you want an Admin level trace, I can have one right away.
    (856) [13-JUN-2010 22:11:00:657] nsopen: opening transport...
    (856) [13-JUN-2010 22:11:00:657] nttcni: Tcp conn timeout = 60000 (ms)
    (856) [13-JUN-2010 22:11:00:657] nttcni: trying to connect to socket 1364.
    (856) [13-JUN-2010 22:11:00:688] nttcni: connected on ipaddr 142.139.221.62
    (856) [13-JUN-2010 22:11:00:688] nttcon: set TCP_NODELAY on 1364
    (856) [13-JUN-2010 22:11:00:688] nsopen: transport is open
    (856) [13-JUN-2010 22:11:00:688] nsnainit: inf->nsinfflg[0]: 0x61 inf->nsinfflg[1]: 0x61
    (856) [13-JUN-2010 22:11:00:688] nsopen: global context check-in (to slot 0) complete
    (856) [13-JUN-2010 22:11:00:688] nscon: doing connect handshake...
    (856) [13-JUN-2010 22:11:00:688] nscon: sending NSPTCN packet
    (856) [13-JUN-2010 22:11:00:688] nscon: sending 233 bytes connect data
    (856) [13-JUN-2010 22:11:00:688] nsdo: 233 bytes to NS buffer
    (856) [13-JUN-2010 22:11:00:719] nscon: got NSPTRS packet
    (856) [13-JUN-2010 22:11:00:719] nscon: sending NSPTCN packet
    (856) [13-JUN-2010 22:11:00:719] nscon: sending 233 bytes connect data
    (856) [13-JUN-2010 22:11:00:719] nsdo: 233 bytes to NS buffer
    (856) [13-JUN-2010 22:11:00:735] nscon: got NSPTAC packet
    (856) [13-JUN-2010 22:11:00:735] nscon: connect handshake is complete
    (856) [13-JUN-2010 22:11:00:735] nscon: nsctxinf[0]=0x61, [1]=0x21
    (856) [13-JUN-2010 22:11:00:735] nsnainconn: inf->nsinfflg[0]: 0x61 inf->nsinfflg[1]: 0x21
    (856) [13-JUN-2010 22:11:00:735] nsnasend: bytes to send: 158
    (856) [13-JUN-2010 22:11:00:735] nsdo: 158 bytes to NS buffer
    (856) [13-JUN-2010 22:11:00:735] nsnareceive: buffer address: 0x132c34 bytes wanted: 2048
    (856) [13-JUN-2010 22:11:00:735] nsnareceive: calling NS to receive 2048 bytes into address 0x132c34
    (856) [13-JUN-2010 22:11:00:766] nsdo: 153 bytes from NS buffer
    (856) [13-JUN-2010 22:11:00:766] nsnareceive: received 153 bytes
    (856) [13-JUN-2010 22:11:00:766] nsnareceive: no more data to receive - returning
    (856) [13-JUN-2010 22:11:00:766] nsnareceive: total bytes received: 153
    (856) [13-JUN-2010 22:11:01:063] nsnasend: bytes to send: 77
    (856) [13-JUN-2010 22:11:01:063] nsdo: 77 bytes to NS buffer
    (856) [13-JUN-2010 22:11:01:063] nsnareceive: buffer address: 0x132c34 bytes wanted: 2048
    (856) [13-JUN-2010 22:11:01:063] nsnareceive: calling NS to receive 2048 bytes into address 0x132c34
    (856) [13-JUN-2010 22:11:01:079] nsdo: 64 bytes from NS buffer
    (856) [13-JUN-2010 22:11:01:079] nsnareceive: received 64 bytes
    (856) [13-JUN-2010 22:11:01:079] nsnareceive: no more data to receive - returning
    (856) [13-JUN-2010 22:11:01:079] nsnareceive: total bytes received: 64
    (856) [13-JUN-2010 22:11:01:079] naun5authent: Authentication type is 0
    (856) [13-JUN-2010 22:11:01:079] nsnasend: bytes to send: 1862
    (856) [13-JUN-2010 22:11:01:079] nsdo: 1862 bytes to NS buffer
    (856) [13-JUN-2010 22:11:01:079] nsnareceive: buffer address: 0x132c34 bytes wanted: 2048
    (856) [13-JUN-2010 22:11:01:079] nsnareceive: calling NS to receive 2048 bytes into address 0x132c34
    (856) [13-JUN-2010 22:11:01:141] nsdo: 165 bytes from NS buffer
    (856) [13-JUN-2010 22:11:01:141] nsnareceive: received 165 bytes
    (856) [13-JUN-2010 22:11:01:141] nsnareceive: no more data to receive - returning
    (856) [13-JUN-2010 22:11:01:141] nsnareceive: total bytes received: 165
    (856) [13-JUN-2010 22:11:01:141] nsnasend: bytes to send: 33
    (856) [13-JUN-2010 22:11:01:141] nsdo: 33 bytes to NS buffer
    These lines are present using both version of sqora32.dll
    (856) [13-JUN-2010 22:11:01:141] nszgwop: SQLNET.WALLET_OVERRIDE not found, using default.
    (856) [13-JUN-2010 22:11:01:157] nscontrol: Vect I/O support: 0(856) [13-JUN-2010 22:11:01:391] nioqrc: Recieve: returning error: 3111
    (856) [13-JUN-2010 22:11:01:391] nsdo: sending NSPTMK packet
    (856) [13-JUN-2010 22:11:01:391] nserror: nsres: id=0, op=77, ns=12630, ns2=0; nt[0]=0, nt[1]=0, nt[2]=0; ora[0]=0, ora[1]=0, ora[2]=0
    These lines only happen when using the R2 version of sqora32.dll
    (856) [13-JUN-2010 22:11:01:719] nioqrc: Recieve: returning error: 3111
    (856) [13-JUN-2010 22:11:01:719] nsdo: sending NSPTMK packet
    (856) [13-JUN-2010 22:11:01:860] nserror: nsres: id=0, op=0, ns=12630, ns2=0; nt[0]=0, nt[1]=0, nt[2]=0; ora[0]=0, ora[1]=0, ora[2]=0
    (856) [13-JUN-2010 22:21:03:782] nstimarmed: no timer allocated

  • UPDATING A TABLE IN THE DATABASE

    I was just wonderng if u had 2 Java applications 1 ,a replica of another.Each application updates the exact same table with information in a database.If both applications are run at the exact same time what would happen,would it have any effect on the database?or would it do any harm?

    The chances of two applications running at exactly the same time are miniscule. If they each have a connection to the database, and are both trying to modify the same table, then chances are one will be slightly after the other its changes would be committed last. In the case where one might delete a row just before another tries to access that row, you're going to have some sort of problem. However, those circumstances are pretty rare, and even so, some small amount of exception handling can deal with them gracefully.

Maybe you are looking for

  • Pl/sql vs. t-sql

    Please help me. data's on sql server and application on oracle. I need a query to sum (sls+mkdn+ rtn) but one of column has null value. thank you. chris

  • DTW BUSINESS PARTNER IMPORT

    Hi all, I've been attempting to import customers to a database and I seem to have mapped all of the fields except I can't seem to get a "state" in the mail to section of the card. I looked at the choices available when mapping in the DTW but I'm unsu

  • Doesn't sync correctly with Outlook 2007!

    All I wanted was a cute nice looking cell phone that syncs with outlook, and after I found it! It appears that Nokia my beloved company maybe has a bug in its software! I have a Nokia 6300, MS Office 2007 and I'm using Nokia PC suite 6.84.10.3 which

  • Specified directory does not exist

    Hi there, I'm having a wierd problem, and can't seem to find a way around it. I'm logging into my clients' version 5 SP10 application, and the "Finance" app works fine: all dimensions downloaded, all folders created locally, etc (today is the first d

  • Business Area not set in IT0001 during Batch input

    Hi! I'm trying to load the IT0001 trough a batch input, but the fields for cost center, business area function and organizational assignment are not derived from the position. The batch input is running the entry action. But if I run the action norma