Trigger that avoids "is changing, function of triggering/can not see ' error

Version Oracle 11.2.0.2

I have a problem where I try to avoid duplicates in a table using a trigger.  Data looks like:

EQUIP LO ACCT

---------- -- ----

1000000000 0

1000000001 0

1000000002 0

1000000003 0

1000000004 0

Equipment = equipment identifier

Location = location number

Acct = account associated with the equipment

I need avoid the same account to have 2 pieces of equipment are allocated to the same location.

for example

EQUIP LO ACCT

---------- -- ----

1000000000 1 1234

1000000001 1 1234

1000000002 0

1000000003 0

1000000004 0

I can't create a unique index for this table that when there is no assigned equipment (first example) I couldn't have uniqueness through the location and number.  So, I wrote the following:

CREATE or REPLACE TRIGGER TEST_TRG before update of test WE acct

Old SEO AS OLD AS new NEW

for EACH LINE

DECLARE

v_chk number: = 0;

BEGIN

Select count (*) in the test v_chk where acct =:new.acct and rental =:new.location;

IF v_chk > 0 then raise_application_error ("-20001, ' multiple devices at the same location not allowed");

END IF;

END;

/

.. but of course that I'm shot in the table that is being updated, I get the error of mutation:

setting a day of test set acct = "1234", location = '1' where equip = '1000000001'

*

ERROR on line 1:

ORA-04091: table xxx. TEST is changing, function of triggering/can not see

ORA-06512: in "xxx. TEST_TRG', line 4

ORA-04088: error during execution of trigger ' xxx. TEST_TRG'

I tried this split into two pieces where a trigger calls another procedure to perform the check and write error, but results were inconsistent and end-user demand does not pick up the error for a reason - it seems to process the transaction very well even if the update was not made at the table level.

Are there other ways in addition to a trigger to achieve?

Thank you!

Adam

Monty77 wrote:

... I can't do this, acct is not a null value, it is ' '.  Right or wrong it is not editable as integrated in application logic.

Thank you!

Adam

Then also consider this value in your index of function according to:

create table test

(

equip the varchar2 (10),

location varchar2 (2),

ACCT varchar2 (4)

);

CREATE a UNIQUE INDEX TestLocationAcct_UK ON Test

(case when the ACCT is not null ACCT AND! =' ' then location |) « ; » || end of the ACCT);

Insert test values ('1000000000 ', ' 0',' ');

Insert test values ('1000000001 ', ' 0',' ');

Insert test values ('1000000002 ', ' 0',' ');

Insert test values ('1000000003 ', ' 0',' ');

Insert test values ('1000000004 ', ' 0',' ');

Update test set acct = "1234", location = '1' where equip is '1000000000';.

Update test set acct = "1234", location = '1' where equip is '1000000001';.

Error on line 1

ORA-00001: unique constraint (SYSADM. TESTLOCATIONACCT_UK) violated

Kind regards.

Al

Name of the index has changed to testlocationacct

Tags: Database

Similar Questions

  • ORA-04091: table that postal_address is changing, function of triggering/can not see

    First of all, there are any number of TRIGGERS defined on the table in question in our database.

    The process that we have to do is:

    1. load the addresses from the table.

    2. send the addresses by a routine of standardization.

    3. down any address that has been standardized with success and is not already present.

    So, how can I say ODI 12 c to create a temporary table before doing the multicables?  So far, everything I've tried gets 'flattened' and translates into the same error.

    OR

    Is there another solution?

    Thanks for your help,

    Scott

    I fixed that by creating a second physical + sense + model to this same base (not sure if I need all three, but because of this way to make sure).  This caused ODI generate a SOURCE_GROUP and TARGET_GROUP instead of just a TARGET_GROUP in the physical view.  I had to do everything on the properties of the first element in the target, set the properties on the Oracle of LKM Oracle shoot (DB Link). GLOBAL no matter what option I wanted to (USE_STAGE_TABLE or SELECT_FROM_SOURCE_VIEW).  One thing to do is put the database owner SID in the SOURCE_ACCESS_DB_LINK so it does not create an unnecessary DB link.

    Hope that helps someone else!

  • Table is changing, function of triggering/can not see?

    Hello
    I had this error before, and I solved it with the help of this forum.
    But I didn't ask then why is - this error happening at all?
    Now I have it again, with different trigger:

    ORA-04091: table TRACKER. APPLICATIONS is changing, function of triggering/can not see

    My trigger code is:
    create or replace trigger "REQUEST_EMAIL_T2"
         after update of assigned_to_assigned_id
         on requests
         referencing new as new old as old
         for each row
    begin
            if :new.assigned_to_assigned_id != :old.assigned_to_assigned_id
         then
          for emp_rec
           in (select      username, assigned_email, form_name
              from      assigned, form_type, requests
                 where  assigned.assigned_id = form_type.assigned_id
                      and assigned.assigned_id = :new.assigned_to_assigned_id
                      and requests.request_id = :new.request_id)
                    loop
               apex_mail.send (
                   p_to          => emp_rec.assigned_email,
                   p_from     => emp_rec.upline_email,
                   p_body     => 'You have been assigned a new Request. '
                                    || CHR (10)
                                    || ' Request: '
                                    || :new.request_id
                                    || CHR (10)
                                    || ' Type: '
                                    || emp_rec.form_name
                                    || CHR (10)
                                    || ' Login: '
                                    || emp_rec.username
                                    || CHR (10)
                                    || ' Pass: '
                                    || '******',
                   p_subj     => 'New Request'
              );
         end loop;
    end;
    / 
    The relaxation will compile without error. The error I get trying to update the table!

    I absolutely need to define a trigger as "after" update and need to know how to avoid the same mistake again?

    Thank you!

    But I didn't ask then why is - this error happening at all?

    Have you looked at the error message? It is very explicit:
    >
    ORA-04091: table String is changing, the function of triggering/can not see
    Cause: A trigger (or a plsql function defined by the user referenced in this statement) attempted to watch (or modify) a table that stood in the middle of being modified by the statement that shot.
    Action: Rewrite the trigger (or function) so it does not read this table.
    >

    Should this request to join the table of queries ? Does not look like it...

  • ERROR / T_ITEMS in the TABLE is changing, function of triggering/can not see ORA-06512... ?

    Hi all

    I CREATED THE TRIGGER TO CHECK NOM_ELEMENT BEFORE UPDATE ON THE T_ITEMS TABLE IF AN ANOTHER NOM_ELEMENT LIKE NOM_ELEMENT CURRENT OR NOT, IF AS AN ANOTHER NOM_ELEMENT DON'T SAVE UPDATED CURRENT NOM_ELEMENT.

    MY NO IS:

    1 - I CREATED the FUNCTION CALL CH_UNIQUE_ITEM_NAME

    CREATE OR REPLACE FUNCTION CH_UNIQUE_ITEM_NAME
    (NUMBER OF P_ID, P_ITEM_NAME IN VARCHAR2)
    RETURN NUMBER
    AS
    NUMBER OF X_COUNT;
    -FUNCTION "CH_UNIQUE_ITEM_NAME" TO CHECK NOM_ELEMENT LIKE OTHER NOM_ELEMENT OR NOT.
    BEGIN
    SELECT COUNT (ITEM_NAME)
    IN X_COUNT
    OF T_ITEMS
    WHERE ID! P_ID =
    AND UPPER (ITEM_NAME) AS UPPER (P_ITEM_NAME);
    RETURN X_COUNT;
    END CH_UNIQUE_ITEM_NAME;

    2. I CREATED TRIGGER CALL TRG_CH_UNIQUE_T_ITEMS

    CREATE OR REPLACE 'TRG_CH_UNIQUE_T_ITEMS' before FIRING
    UPDATE
    ON T_ITEMS FOR EACH LINE
    DECLARE
    NUMBER OF X_CHECK;
    BEGIN
    SELECT CH_UNIQUE_ITEM_NAME (: OLD.ID,: NEW.) NOM_ELEMENT) IN DOUBLE X_CHECK;
    IF (: NEW.) NOM_ELEMENT DISLIKES: OLD. Nom_element AND X_CHECK > 0)
    THEN RAISE_APPLICATION_ERROR (-20007, "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
    END IF;
    END;

    NOW WHEN I UPDATE ANY ITEMS FOUND ERROR "ERROR / T_ITEMS in the TABLE is changing, function of triggering/can not see ORA-06512.

    Form on T_ITEMS22222.png

    Please help me TO RESOLVE THIS ERROR. I TIRED TO SOLVE...

    Thank you

    You don't realize that you have just set a UNIQUE INDEX of several columns?

    create unique index index_name_uq on table_name( user#, upper(item_name) );
    

    In addition, a GUI Design point, (using the terms of the APEX) that you want to validate the data before submit you.

    (use a Page-level Validation)

    MK

  • Changing table - SQL error: ORA-04091: table XYZ is changing, function of triggering/can not see

    Hi all

    I am a newbie to Oracle and I am faced with the above error. Please see the below code snippets. Can someone please tell what I am doing wrong? Thank you in advance.

    Thank you

    CREATE TABLE ABC

    (

    ID VARCHAR2 ENABLE NUMBER NOT NULL,

    FIELD1 ACTIVATE THE NUMBER NOT NULL,

    FIELD2 ACTIVATE THE VARCHAR2 (8 BYTE) NOT NULL,

    CONSTRAINT JOB_PK PRIMARY KEY (ID)

    )

    ;

    CREATE TABLE XYZ

    (

    ACTIVATE THE NUMBER 4 R_ID NOT NULL,.

    ID VARCHAR2 ENABLE NUMBER NOT NULL,

    Column1 NUMBER (2.0) default 0.00,.

    Column2 NUMBER (2.0) default 0.00,.

    COLUMN3 NUMBER (2.0).

    NUMBER (2.0) TOTAL 0.00 default.

    CONSTRAINT TRIP_PAYMENT_PK PRIMARY KEY (ID)

    )

    ;

    create or replace trigger trigger1

    After Insert on XYZ

    for each line

    Declare

    number of newTotal;

    Start

    newTOTAL: =: new. Column1 +: new. Column2 +: new. COLUMN3;

    setting a day of XYZ together Total = newTotal;

    end;

    Insert into ABC (1, 45, ' Demo');

    insertion in XYZ (1, 1, 12.50, 10.20 33,50, ");

    Error report:

    SQL error: ORA-04091: table XYZ is changing, function of triggering/can not see

    Try one before line

    create or replace trigger trigger1

    before inserting on XYZ

    for each line

    Start
    : new. TOTAL: =: new. Column1 +: new. Column2 +: new. COLUMN3;
    end;

  • Trigger - "Trigger is undergoing change, function of triggering/can not see.

    Hi all

    This is the first time I work with triggers. I have a question, because I don't understand how it works.
    create or replace trigger ctai_delivery
      after insert on delivery   
      for each row
    begin
      if :new.delivery_status_code is null then
        update delivery d
        set d.delivery_status_code = 'LEV'
        where d.delivery_number = :new.delivery_number;
      end if;
    end ctai_delivery;
    This trigger must run after an insertion. It will need to check if the inserted row delivery_status_code is not null, if it is, then fill it with 'LEVl.

    I read that you are not allowed to change the values of: news and: old. So, how can I change the value of delivery_status_code?

    Kind regards

    Metro
    SQL> create table delivery
      2  (delivery_status_code varchar2(3));
    
    Table created.
    
    SQL> create or replace trigger trig_delivery
      2  before insert on delivery
      3  begin
      4   :new.delivery_status_code := nvl(:new.delivery_status_code,'LEV');
      5  end;
      6  /
    create or replace trigger trig_delivery
                              *
    ERROR at line 1:
    ORA-04082: NEW or OLD references not allowed in table level triggers
    
    SQL> create or replace trigger trig_delivery
      2  before insert on delivery
      3  for each row ----<<<<<<<------
      4   begin
      5    :new.delivery_status_code := nvl(:new.delivery_status_code,'LEV');
      6   end;
      7   /
    
    Trigger created.
    
    SQL> 
    
  • Need to change credit card, but can not see my previous card info and how to change.

    Here's what I see when I go on my account. You will have to update my card because my membership is suspended and I have urgent work to do.

    Please help as soon as POSSIBLE.

    Screen Shot 2015-07-30 at 10.34.08 am.png

    Hi Aniket,

    Refer to this to renew your membership:

    https://helpx.Adobe.com/creative-cloud/help/renew-restart-extend-membership.html

    Refer to re-subscribe:

    Pricing plans and creative Cloud membership | Adobe Creative Cloud

    I hope this helps.

    Concerning

    Megha Rawat

  • Only windows 7 can set the image of the user that appears in the start menu you can not change it. True or false?

    Is true or false. Only windows 7 can set the image of the user that appears in the start menu you can not change it.

    Set to false.

    Type the user accounts in the start search box.

    Press ENTER.

    Select change your image.

    Browse the picture than what you want.

  • I lost the small contraption white balance eyedropper and the possibility to change the exposure and can not find a way to get them back! Help! Thank you!

    I lost the small contraption white balance eyedropper and the possibility to change the exposure and can not find a way to get them back! Help! Thank you!

    You say you have lost the tab "tool"?

    If so, just right click on one of the other tabs and select "basic" in the context menu that appears.

  • My Thunderbird page is screwed - there is no address book that appears in the toolbar, and I do not see a ' writing: tab - right message - how to restore.

    My Thunderbird page is screwed - there is no address book that appears in the toolbar, and I do not see a tab 'write' - just 'message' how can I restore back to normal?

    Would so much appreciate help... frustrating.

    This is the Contact Sidebar in the entry window. Press F9 when in the write window to enable or disable.
    Or you can also access it from the view menu in the window of writing.
    Sidebar view-presentation-Contact

    Another clue. If something is missing in any look of window on the View Menu. This is how you configure the view you want.

  • Can not see the images of the patent (i.e., D/359 691) on research of patent USPTO.gov, it tells me I need a plugin (7.7.1.0 Quicktime) that I've already updated.

    Can not see the images of the patent (that is, D/359 691) on USPTO.gov patent search, it tells me I need a plugin (Quicktime) that I've already updated.
    In the 'quick search' I give terms & it compiles a list. I have then cross to every doc and look to see the doc and associated drawings. I don't know what to say at this stage.

    Thank you.

    QuickTime cannot handle images in TIFF format.

    You can watch AlternaTIFF - http://www.alternatiff.com/

  • Qosmio G20-127: after that Windows update I can not see list fax and printer

    Description of the problem
    Model: Toshiba Qosmio G20-127
    Operating Sysytem: Microsoft Windows Media Center Edition

    After the restoration of BONE of restore DVD, I can see list Fax and printer. But after the Windows Update I can not see the list of fax and printer and cannot run the Wizard "add a printer".

    I just installed printers.

    It seems that it s a Microsoft Windows problem and it s not bound Toshiba laptops
    See this Microsoft Knowledge base article:
    http://support.Microsoft.com/kb/823447/

  • I did a backup of the computer on my old HD 110 GB. Install a new 500 GB HD and restore complete pc but windows onliy see the 100 GB on the C drive and the 9.99 on the D drive that were on my old HD and do not see the additional 400 GB. How can I solve th

    I did a backup of the computer on my old HD 110 GB. Install a new 500 GB HD and restore complete pc but windows onliy see the 100 GB on the C drive and the 9.99 on the D drive that were on my old HD and do not see the additional 400 GB. How I can solve this problem.

    Hi abgolf3,

    The question may be how the new hard drive has been formatted.  Take a look at the way in which the reader is implemented by clicking Start > Control Panel > Administrative Tools > double-click on computer management > double-click storage.  Is all the space on the disk are responsible?  If so, take a look at these two documents for your problem:

    Mark a partition as active

    Format a hard drive or partition to NTFS format

    Dena
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • I forgot to backup Outlook Express! However, the .dbx files are all in the data folder of Application that I have back up! How can I see what is in them to import to my chosen e-mail program?

    Original title: .dbx files

    I've updated computer laptop of my client from Windows XP to 7.  I forgot to backup Outlook Express!  However, the .dbx files are all in the data folder of Application that I have back up!  How can I see what is in them to import to my chosen e-mail program?

    This is how you would normally import into Windows Live Mail. If all goes well it will give you enough of a jump start.
     
     
     
    Copy the * ENTIRE * OE message store folder to a flash drive. (Folders.dbx must be included). Place it on the desktop or another location on the computer using WLMail.
     

    WLMail 2011/2012: folder button. Import Messages. Microsoft Outlook Express 6, and the point where it was saved.
     
     

     
     
     
     
     
     
     
     
  • files that are about 50 MB or more, can not be downloaded the integrity of my windows 7 Home premium

    files that are about 50 MB or more, can not be downloaded the integrity of my windows 7 Home premium

    for example, to install the Java SDK downloaded by my laptop, will appear a message a .cab file is corrupted, and I have to cancel the installation. However, if use the package downloaded by my friend, it works correctly.

    The most common causes are

    (1) a bad internet connection leading to corrupt downloads.

    (2) malicious software on the system that infect downloads.

    We cannot do anything on the first of these forums - so...

    Download and install Malwarebytes Anti-malware (free version) - uncheck "Activate the free trial version of MBAM PRO" at the end of installation - www.malwarebytes.org and update to update, then run a complete analysis of your main account and quick scans in all other user accounts.

    Remove what it finds

Maybe you are looking for

  • option to print Photosmart 6510 not highlighted

    With windows 7, I can print when you use Word, but if I want to print the e-mail or the internet, I can only do on my ophotosmart 6510 first economy on the desktop. Economy option is available, but there is no response from the printing option is gra

  • Cannot turn off the prompt of password to wake up sleep monitor

    So whenever my screensaver lights up and I'll be back to wake up the monitor I get the password of the user account guest.  I am running Windows XP home on a dual boot Macbook Pro.  I have the owner administrator account and staff use account for the

  • need to 'general of the Pacific' patch, game keep crashing

    * - Original title - "general of the Pacific" game patch I have a game called General Pacific. It keeps crashing in most of the scenerios.  I need a patch from someone who has the game and encountered the same problem. The author of the game no longe

  • Setup Internet on XP Pro

    I have an old PIII I formatted and reinstall XP Pro; However my question is internet connection.  I have my wireless connected but cannot get a Web page through.  I think I need to connect to the internet, but I forgot how to do this. Can you help me

  • Dialog.Alert () cannot display in implements method

    class DialogCommandHandler extends CommandHandler { public void execute(ReadOnlyCommandMetadata metadata, Object context) { if (context.equals(contextSearch)) { Dialog.alert("Coming soon!"); } } } Hi, everyone, I found this problem while I'm my debug