What I want: When every defaussee
are equal to 1 I want to turn them to 0. Here is my table
create table Pile(
id_carte Int NOT NULL,
id_pilecarte Int NOT NULL,
defaussee Int NOT NULL,
id_personne Int
);
To do that I want to use a trigger on Pile
. But I know that I can't modify my table into that trigger.
Here is what I have:
create or replace trigger trg_pile_porte_vide
after update
on Pile
for each row
declare
v_count Int;
begin
-- pile tresor
select count(*) into v_count from (select id_carte from Pile where id_pilecarte = 0 and defaussee = 0 and id_personne is null);
-- toutes les cartes sont defause
if(v_count = 0) then
update Pile set defaussee = 0 where id_pilecarte = 0;
end if;
-- pile tresor
select count(*) into v_count from (select id_carte from Pile where id_pilecarte = 1 and defaussee = 0 and id_personne is null);
-- toutes les cartes sont defause
if(v_count = 0) then
update Pile set defaussee = 0 where id_pilecarte = 1;
end if;
end;
Can't somebody help me ?
The error is not only on the UPDATE
. Oracle shout from the first SELECT
. He doesn't want that I Read/Write on Pile
during a trigger on Pile
.
Can you try the following?
UPDATE Pile
SET defaussee = 0
WHERE (id_pilecarte, 1) IN (
SELECT id_pilecarte, MIN(defaussee)
FROM Pile
GROUP BY id_pilecarte
HAVING MIN(defaussee) = 1
);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.