mutation in the triggers table problem (need to COUNT (col) and MAX (col) of table shot)

I was looking for the solution and find many examples, but I do not know what is the best in my option and don't understand everything.

I realized that can't do a SELECT query in the table where trigger is triggered. But I have need SELECT COUNT (col), then MAX (id) of this table, update some statistical info...
And also need to row id update, so I can't do trigger of table instead of relaxation of the line.


So this is my TRIGGER:

create or replace

update_stat relaxation

AFTER UPDATE ON TABLE1 TO EACH LINE

DECLARE

juice FLOAT;

all the NUMBER;

end NUMBER;

BEGIN

IF (: old.ended <>: new.ended) THEN

SELECT COUNT (id) FROM end FROM table1 WHERE fk_table2 = new.fk_table2 AND finished = 1;  -Error in the table of mutation

SELECT COUNT (id) FROM everything FROM table1 WHERE fk_table2 = new.fk_table2; -Error in the table of mutation

Juice: = ((end /all) * 100);

UPDATE table2 SET suc = success WHERE id =:new.fk_table2;

END IF;

END;

I also tried with

pragma autonomous_transaction;

 

trigger body....AND

 

 

commit;

But don't working right when insert more records.

Thanks, Urban

Data and structure of the example table

SQL> create table table2
  2  (
  3     id        integer
  4   , success   number
  5   , constraint table2_pk primary key (id)
  6  );

Table created.

SQL> create table table1
  2  (
  3     id        integer
  4   , id_t2     integer
  5   , ended     integer
  6   , constraint table1_pk primary key (id)
  7   , constraint table1_fk_id_t2 foreign key (id_t2) references table2
  8  );

Table created.

SQL> insert into table2(id, success) values (1, 0);

1 row created.

SQL> insert into table2(id, success) values (2, 0);

1 row created.

SQL> insert into table1
  2  (
  3     id
  4   , id_t2
  5   , ended
  6  )
  7  select level
  8       , ceil(level/10)
  9       , 0
 10    from dual
 11  connect by level <= 20;
20 rows created.

SQL> commit;

Commit complete.

Create objects to the suite

create or replace type update_stat_obj as object (id integer, id_t2 integer, ended integer)
/
create or replace type update_stat_tbl as table of update_stat_obj
/
create or replace package update_stat_pkg
as
   g_table_1 update_stat_tbl;
   procedure load(p_id integer, p_id_t2 integer, p_ended integer);
   procedure updt;
end;
/
show err
create or replace package body update_stat_pkg
as
   procedure load(p_id integer, p_id_t2 integer, p_ended integer)
   is
   begin
      if g_table_1 is null then
        g_table_1 := update_stat_tbl();
      end if;

      g_table_1.extend;
      g_table_1(g_table_1.count) := update_stat_obj(p_id, p_id_t2, p_ended);
   end;
   procedure updt
   is
   begin
       merge into table2 t2
       using (
              select t1.id_t2
                   , (count(t2.id)/count(t1.id))*100 success
                from table1 t1
                left
                join table(g_table_1) t2
                  on t1.id    = t2.id
                 and t2.ended = 1
               group
                  by t1.id_t2
             ) t1
          on (t2.id = t1.id_t2)
        when matched then
            update set t2.success = t1.success;

       g_table_1 := null;
   end;
end;
/
show err
create or replace trigger update_stat_row_trig after update on table1 for each row
begin
    if (:old.ended <> :new.ended)
    then
       update_stat_pkg.load(:new.id, :new.id_t2, :new.ended);
    end if;
end;
/
show err
create or replace trigger update_stat_trig after update on table1
begin
    update_stat_pkg.updt;
end;
/
show err

Now look for the UPDATE.

SQL> select * from table1;

        ID      ID_T2      ENDED
---------- ---------- ----------
         1          1          0
         2          1          0
         3          1          0
         4          1          0
         5          1          0
         6          1          0
         7          1          0
         8          1          0
         9          1          0
        10          1          0
        11          2          0
        12          2          0
        13          2          0
        14          2          0
        15          2          0
        16          2          0
        17          2          0
        18          2          0
        19          2          0
        20          2          0

20 rows selected.

SQL> select * from table2;

        ID    SUCCESS
---------- ----------
         1          0
         2          0

SQL> update table1 set ended = 1 where id between 1 and 7 or id between 11 and 19;

16 rows updated.

SQL> select * from table2;

        ID    SUCCESS
---------- ----------
         1         70
         2         90

SQL> select * from table1;

        ID      ID_T2      ENDED
---------- ---------- ----------
         1          1          1
         2          1          1
         3          1          1
         4          1          1
         5          1          1
         6          1          1
         7          1          1
         8          1          0
         9          1          0
        10          1          0
        11          2          1
        12          2          1
        13          2          1
        14          2          1
        15          2          1
        16          2          1
        17          2          1
        18          2          1
        19          2          1
        20          2          0

20 rows selected.

Tags: Database

Similar Questions

  • Change all the triggers table in the oracle schema by using a script - possible?


    Is it possible to modify all the triggers table in the oracle schema using a single script or modify each trigger table separately is the only way?

    A couple of alternatives come to mind.

    (1) you can go in SQL Develolper, go to the schema, expand the node for triggers and select all the triggers that you want to change.  Right-click and choose the fast DDL--> save spreadsheet.  Find and replace in the worksheet and then run the script.

    (2) if the trigger is the same for all 70 tables, you can move the PL/SQL out of the trigger and in a procedure in a package and just call the procedure of 70 triggers.  Now, the code is kept in the same place.  For new tables, you can add a call to the procedure and you are done.  If all 70 triggers are not the same, see if you can pass parameters to allow a generalized procedure that they can all use.

    You have not indicated what your triggers.  Are insert you columns of auditing, archiving data, inserting into a table of log, update another table or something else?  What type of trigger is it?  What you trying to accomplish with your triggers?

    Marcus Bacon

  • yet man WARNING said "the project has problems", but none are listed and dvd build work if hit ignore

    I am building a dvd project in still and when I try to compile I get a popup warning that says "the project has problems that could cause the disk to play properly...". "but when you click on 'view' to see the problems (in the form of test generation) there is no problem. And if you click on 'ignore', he seems to build a perfect drive. Should I be worried?

    You are probably right, but I would test the disc more than usual.

    Make sure you have all the options checked in the error checking window that opens.

  • I bought an Internet Marketing software it did not work properly Said they (the software vendor), I need to right click and run admin

    software I bought said need icon on the desktop right click and put run admin has never had to do with other software is it too authorization? What are the consequences? should I do?

    Hello

    they are correct

    Some programs will require that you right-click on the setup.exe program and then run as administrator to install the

    and even to run correctly

    This microsoft article should explain

    http://support.Microsoft.com/kb/922708

    Also check vista compatibility

    http://www.Microsoft.com/Windows/compatibility/Windows-Vista/

    If it is not compatible with vista read this

    http://www.howtogeek.com/HOWTO/Windows-Vista/using-Windows-Vista-compatibility-mode/

  • Whenever I start my computer, volume icon does not appear on the Notification area, I need to log out and then log in to get the volume icon.

    His comes at the start of my place of windows. Whenever I need to close and open a session to get the volume icon on the Notification area. I can see icon volume to customize the Notification area icons & select the "Show icon & notifications" and then after that I can't get the volume icon.

    Pritesh salvation,

    Please visit http://www.sevenforums.com/tutorials/19085-system-icons-enable-disable.html.  If this does not work, look at the related tutorials here (and the references in the intro) for more information.

    Some alternatives might be: http://www.sevenforums.com/tutorials/293-notification-area-icons-hide-show-system-icons-notifications.html or http://www.sevenforums.com/tutorials/292-system-icons-turn-off.html.

    Good luck!

    Kosh

  • Pavilion 17-F001dx: 'Windows 8 using 100% of the HARD drives with high average response time and low write speed '.

    It turns out that it is a pretty known issue windows 8.1 users infestation since at least 2013 and there is not a simple fix, then it cannot be * completely * lack of hp. but I've had two of these laptops, both the same model, one needing to be returned and exchanged for a problem absolutely no report with (hardware failure: ethernet port does not work with lights taped). Both are renovated. Both have been extreemly slow and unresponsive even compared to the lower Brazos powered by the laptop that I had before, but I recently decided to investigate why.

    So if there is something specific HP going on here, I hope that there is a simple fix. My average response time went upward as well more than a minute (> 60, 000ms), so that I'm an aberrant case here against this problem of reactivity/band bandwidth hardrive typical windows 8.1.

    Edit: there is a case with another HP pavilion laptop (intel powered, so there may be a problem of storage driver intel described in the first link) being much worse.

    Did not want to resort to that, but,.
    Going to a new facility to clean up an image of Windows Pro 8.1 from DreamSpark for my school.

    Disappointed by the lack of response. Given the odd subdomain name (h30434), I'm wondering if this forum has been abandoned.

  • The mutation of the Table... not triggered on SELECT error? And also not on UPDATE?

    I thought I knew how to get Oracle to report an error Table mutation, but when I tried to do it in a demonstration today, it didn't work. Here is what I tried:
    SQL> set serveroutput on
    SQL> create table test_mte (f number);
    
    Table created.
    
    SQL> insert into test_mte values (1);
    
    1 row created.
    
    SQL> insert into test_mte values (2);
    
    1 row created.
    
    SQL> insert into test_mte values (3);
    
    1 row created.
    
    SQL> create or replace trigger test_mte_bt
      2  before insert on test_mte
      3  for each row
      4  declare
      5    wk_cnt number;
      6  begin
      7  
      8    select count(*) into wk_cnt from test_mte;
      9    dbms_output.put_line(wk_cnt);
     10    
     11  end test_mte_bt;
     12  /
    
    Trigger created.
    
    SQL> insert into test_mte values (4);
    3
    
    1 row created.
    I thought that, in a level trigger line, questioning the table on which the trigger is installed, you get an error of the changing table. Same thing with INSERT, UPDATE, or DELETE. Of course, I thought I'd get the problem with DML:
    SQL> create or replace trigger test_mte_bt
      2  before insert on test_mte
      3  for each row
      4  declare
      5    wk_cnt number;
      6  begin
      7  
      8    update test_mte set f = 10 where f = 1;
      9    dbms_output.put_line('Updated: '||SQL%ROWCOUNT);
     10    
     11  end test_mte_bt;
     12  /
    
    Trigger created.
    
    SQL> insert into test_mte values (4);
    Updated: 1
    
    1 row created.
    We are on Oracle 11.1.0.7. Could something have changed in this upgrade? I'm completely confused.

    Thank you
    -= Chuck

    If the trigger is an INSERT... VALUES, Oracle knows this is a special case and that exactly 1 line will be inserted. This means that, indeed, a row-level trigger is no different with a statement-level trigger so the restriction on the questioning of the trigger table is not present.

    If you were writing your next INSERT statement as a query - even if this query returns a single row, you will get an error because Oracle knows the syntax that you are guaranteed to get exactly one line.

    SQL> insert into test_mte
      2    select 5
      3      from dual;
    insert into test_mte
                *
    ERROR at line 1:
    ORA-04091: table SCOTT.TEST_MTE is mutating, trigger/function may not see it
    ORA-06512: at "SCOTT.TEST_MTE_BT", line 4
    ORA-04088: error during execution of trigger 'SCOTT.TEST_MTE_BT'
    

    Of course, when you write the actual code, you never want to count on each insert is a single-row INSERT statement... VALUES statement so there is not much cause to take advantage of this gap in practice.

    Justin

  • Code of the trigger with the error table mutation

    I have 2 tables, cc_call_lists and cc_call_issues. I have a trigger on the table of cc_call_issues so that when the priority is updated I can determine how to set Issue_Priority.

    Basically, the priority update for an Issue_Id I need to update the I want to watch Issue_ids of all the participating on the cc_call_lists table and determine how to update the Issue_Priority column.

    Issue_Priority must always be the first priority of the table cc_call_issues for Issue_id records in the cc_call_lists table. So when I need to watch all changes priority priority values for which the Participant has records in the cc_call_lists table and take the max value priority after the record is updated.

    Unfortunately, I get the following error message when the trigger is activated:

    ORA-04091: table TTMS. CC_CALL_ISSUES is changing, function of triggering/can not see
    ORA-06512: at «TTMS.» UPDATEISSUEPRIORITY', line 30
    ORA-04088: error during execution of trigger ' TTMS. UPDATEISSUEPRIORITY'

    Is there a work around which is not too complicated? Any help would be greatly appreciated.


    Table: cc_call_lists
    Name
    -----------------
    PARTICIPANT_TYPE
    PARTICIPANT_ID
    LAST_ACCESS_DT
    LAST_ACCESS_BY
    CREATE_DT
    CREATE_BY
    MODIFY_DT
    MODIFY_BY
    CALL_STATUS
    CALL_PRIORITY


    Table: cc_call_issues
    Name
    -----------------
    ISSUE_ID
    ISSUE_DESCR
    DEACTIVATION_DT
    PRIORITY
    CREATE_DT
    CREATE_BY
    MODIFY_DT
    MODIFY_BY

    Trigger on cc_call_issues code:
    CREATE OR REPLACE TRIGGER TTMS.UpdateIssuePriority
    BEFORE UPDATE
    OF PRIORITY
    ON TTMS.CC_CALL_ISSUES 
    REFERENCING NEW AS New OLD AS Old
    FOR EACH ROW
    DECLARE
    tmpMaxPriority number:=0;
    
    -- Get list of all participants call queue records, existing priority who also have a participant issue record with this issue code
    cursor c1 is
    select a.participant_id, a.call_priority
    from cc_call_lists a, cc_participant_issues b
    where 
      a.participant_id = b.participant_id
      and b.issue_id = :new.issue_id
      and b.issue_status = '001'
      and a.call_status <> '003';  -- Not closed already
    
    BEGIN
        for thisone in c1 loop
                -- Get the existing highest priority
                select nvl(max(b.priority),0)
                into tmpMaxPriority
                from cc_participant_issues a, cc_call_issues b
                where
                  a.issue_id = b.issue_id and
                  a.participant_id = thisone.participant_id;
                  
                -- Update it if the new priority value is higher than the existing call queue record priority
                if :new.priority > tmpMaxPriority then
                        update cc_call_lists
                        set call_priority = :new.priority
                        where participant_id = thisone.participant_id; 
                elsif :new.priority < tmpMaxPriority then
                        update cc_call_lists
                        set call_priority = tmpMaxPriority
                        where participant_id = thisone.participant_id; 
                end if;
        end loop;
    END UpdateIssuePriority;
    /

    Move the level of LINE at the STATEMENT level triggers, see:
    http://www.Oracle-base.com/articles/9i/mutating-table-exceptions.php
    http://asktom.Oracle.com/pls/asktom/asktom.download_file?p_file=6551198119097816936

  • Need some tips to merge the two table-manipulation functions

    Hi guys!

    Thanks to Johnsold, Helmut O'Brian and Jcarmody, who helped me through a string function complicated (for me, the noob of LV), I got away with my project and I'm very close to its end.

    As I've described it here I wanted to explore an array of words combined with-, i.e. C1 - C10. Help, when I arrived, I was able to do. I also learned a few things and was able to do the following:

    Original array: new table:

    R1                                                       R1

    R2                                                       R2

    C1-C3                                                  C1

    K1                                                       C2

    C3

    K1

    I have this:

    Original array: new table:

    R1                                                       R1

    R2,R4,R7                                             R2

    C1                                                       R4

    K1                                                       R7

    C1

    K1

    I was also able to combine these two functions

    Now, back to my problem.

    Until now, it was just a 1 d array that I worked with. In fact, it's a 2D array, I read a. CSV file:

    As you can see there are a few places where things is combined with either - or by commas. I need to widen the first column as described above and as resolved in the thread I mentioned. Fact! No problem. I extracted the first column in table 1 d. Then expand it. Now, I need to replace in the original array and also expand all.

    It should then look like this:

    Then I only need to copy the position of the R6 line and paste it in the empty fields:

    I enclose below two screws. Start by opening the main.vi. Then copy.vi. I tried to describe the problem here too. You can see what I've accomplished and what is missing.

    Tasks:

    1. replace the column expanded in the original array and expand all.

    2 copy the needed lines.

    In the main.vi, I do the 1 d expansion, but I have the problem with the expansion of table 2D. In copy.vi, I managed to copy the lines. If this part is done.

    Basically, I need some advice on enlargement that I do and how do I get the 2D table also expanded. Because I have not much experience, I feel more comfortable working with 1 d arrays. But I can't seem to get any further with this 1 d-> expansion 2D.

    I also really can't seem to find a smart way to implement my function of copy-line-in the main.vi.

    P.S the joint screws are manufactured in LV2010.

    Fortunately, I can attend some courses of basic home OR here in Norway, but so far, I'm still learning and I think that sometimes, I try to do things that are way out of my League

    I don't know what I did but it works now

    Thanks for the help, same!

    You are even welcome!

    Have attached the file if anyone wants to see what I did.

  • I need to insert data from the parent to the child table inheritance

    Hi everyone I m using jdeveloper 12

    I have this use EDC:

    I m trying to have mini-programm in which i

    create porject, used to create and assign an employee as the project manager:

    It is therefore my phyiscal using uml data model

    cap1.PNG

    cap2.PNG

    My problem is: I need to see the values in the employee table, choose an employee id s and with the form create in this table: Project Manager: insert the employee with the s project id id

    but when I navigate to the form it is already full of I don't know why

    I did not understand your problem clearly.

    Could you please explain the problem with some screen shots and step by step flow?

    See you soon

    AJ

  • problem in the form of master-detail when you use the ADF table for detail

    Hello

    jdev version - 11.1.2.1.0


    I create master shape detail using datacontrol drag as ADF master shape secondary Table.


    Now when I create a new line in the detail table using the key CreateInsert a new empty row created on top of the secondary table.

    and other show line that the previous record data based on the master.

    problem is I want to when I click on the createInsert button all the line of the secondary table must be empty and what line to fill two or three user then validate.



    Thanks in advance

    Hello

    If a secondary table has data, then createInsert adds to them. If you want to hide the existing lines, create a new instance of the View object and set the option "extract database" to "No. Rows. Use an af:switcher to change the specified table when the user clicks the createInsert button. There is some coding needed to have this use case in the ADF, but its essentially declarative. Bottom line, is that there is no option automated other than to create new lines in a separate page or dialog box if you are bothered by existing lines

    Frank

  • I NEED HELP Please im having a problem to forget my password and when I plug it it says its locked with a password he try to put the itunes thing but

    NEED HELP Please im having a problem to forget my password and when I plug it it says its locked with a password he tried to put the itunes thing but it says enter password I put in what I rember, then said lokced for five minutes help me pls

    Without knowing the password for your iPhone, there is no way to unlock it, bring even you to the Genius Bar. If you continue to enter the wrong password, you will be locked out of your iPhone, and your data will be unaccessable.

  • 430exII fires twice in manual mode on the radio triggers? I need to stop!

    I use 430exII on radio receivers and had no problems so far.  I have it configured in manual mode, on the same channel as the transmitter, do not mess with the custom functions, but get a double glow.  How can I stop this?

    Like I said above, try to exchange the triggers and see where is the problem, that way you can refine between flash and trigger as a source.  Looks like Calumet triggers have a button on them for manual tests, I'll try on the transmitter too, in this way, you can eliminate the transmitter/camera as a source interface.

    I searched on the net and it looks like there are a few reports of pipe with random and double triggers.  Maybe you have a bad camera.

  • Problem using the Safari web browser, error: close Webkit2webprocess.exe encountered a problem & needs o.

    Original title: WEBKIT2WEBPROCESS. EXE.

    Hey Microsoft Community,

    I am a user of XP and using SAFARI for Windows 5.1. I have a problem while browsing in Safari, sometimes "Webkit2webprocess.exe encountered a problem & needs o close" named message board is coming & saying send this error to microsoft & all open pages are reopen again & Safari then has abnormally forcing to close & some time it behaves blocking condition even after the freshly launched Safari & this happen for about 8 months the update of Safari also reduced for the same time & same not solved after reinstallation. Thus, kindliy solve my problem. Sincerely waiting for your response.

    With respect,

    Rachid Purakait

    Hello

    The question you posted would be better suited in the Apple for Safari support. Check out the link and ask the question.

    http://support.Apple.com/kb/DL1531

  • need to tune up and complete the review of the computer, I have a lot of problems

    have laptop computer abput gateway 4-5 years with vista home premium with sp1 32-bit

    have been msany to have a lot of problems and worsens with a lot of gel and crashing lately

    has talked to someone at speedy pro and he said I needed a tune up and major maintenance that I had many many many problems and they wanted to charge Ms. $300 to fix did not have the $$$

    Hi Sandy,

    I'm sorry to know that you are facing this problem. Based on your description, it seems that the system freezes and it crashes very often.

    1. You receive a specific error?
    2. It does not occur when you perform a particular task?
    3. What is the brand and model of the computer?

    You can consult this documentation and see if the suggestions it can improve the performance of the computer.

    See also:

    Maintenance tasks that improve performance

    Reply with the status if it does not, then we can help you.

Maybe you are looking for