R
R
remkudusov2019-12-12 04:24:36
Oracle
remkudusov, 2019-12-12 04:24:36

Why in oracle pl/sql trigger doesn't react on all rows i insert in table?

Hello!
I have a table like this in Oracle PL/SQL:
SWe1O.png
This is the shot table. I have people who participate in a marksmanship competition. The name column describes the shooter's name, the x column shows the x coordinate of the bullet's point of impact, and the y column shows the y coordinate of the bullet's point of impact. It is assumed that the data will be entered immediately in three lines after each team of 3 shoots. Here is what the query for inserting the results of a shot looks like:

insert all 
into shots (name, x, y)
values ('Bill', 12, 61)
into shots (name, x, y)
values ('Marat', 150, 85)
into shots (name, x, y)
values ('Ivan', 18, 13)
select * from dual;

And there is one limitation. You cannot write to the table the result in which x > 120. Therefore, a trigger was written that cancels the insertion of a row with x > 120. Here is its code:
create or replace trigger delet_shot
    before INSERT on shots
for each row
begin
    if (:new.x > 120) then
        raise_application_error(-20000, 'Стрелок не попал в мишень');
    end if;
end;

And now, in fact, what is the crux of the matter. When I insert into the table shown above, due to the fact that there is a row in the query that cannot be inserted due to a trigger, the other two rows (1 and 3) are not inserted, which are correct and under the actions of the trigger do not fall. Please tell me how to fix this and write a trigger that will start up all the correct lines in one insert and not start up the wrong ones. That is, so that rows 1 and 3, since they are correct, are inserted into the table, and row 2 is not inserted, since it is incorrect. Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Armenian Radio, 2019-12-12
@gbg

The request goes in one transaction - if something gets corrupted in it, the entire transaction is rolled back.
Send in separate transactions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question