Я хотел бы проверить некоторые значения в BEFORE TRIGGER
, но значения отличаются от того, что я вижу в базе данных.
Это мой триггер:
create or replace TRIGGER TAH_BEFORE
BEFORE INSERT ON TAH
FOR EACH ROW
DECLARE
V_HRA_ID number := -1;
V_OBLAST_ID number := -1;
V_RESULT number := -1;
BEGIN
V_RESULT := -1;
begin
select H.ID, H.OBLAST_ID into V_HRA_ID, V_OBLAST_ID from HRA H where H.STAV_ID = 0;
exception
when no_data_found
then raise_application_error(-20001, 'No game in playing state.', TRUE);
end;
begin
select P.SHOWN into V_RESULT from POLE P where P.OBLAST_ID = V_OBLAST_ID and P.ROW_ID = :new.ROW_ID and P.COL_ID = :new.COL_ID;
if V_RESULT > 0 then
raise_application_error(-20002, 'Already shown.' || V_RESULT || ' ' || V_OBLAST_ID || ' ' || :new.ROW_ID || ' ' || :new.COL_ID, TRUE);
end if;
end;
begin
select count(M.ID) into V_RESULT from MINA M
join HRA H on H.OBLAST_ID = M.OBLAST_ID
where H.id = V_HRA_ID;
if V_RESULT > 0 then
raise_application_error(-20003, 'This field is marked as mine.', TRUE);
end if;
end;
:new.TIMESTAMP := CURRENT_TIMESTAMP;
:new.HRA_ID := V_HRA_ID;
END;
Если я бегу
Insert into TAH(ROW_ID, COL_ID) VALUES(5,5);
Я получаю сообщение об ошибке
Error starting at line : 2 in command -
insert into TAH (ROW_ID, COL_ID) VALUES (5, 5)
Error report -
ORA-20002: Already shown.1 143 5 5
ORA-06512: na "SK1X1.TAH_BEFORE", line 29
ORA-04088: chyba během provádění triggeru 'SK1X1.TAH_BEFORE'
Но если я проверяю базу данных с помощью select (или я проверяю данные таблицы в GUI oracle sqldeveloper), ВСЕ строки в таблице POLE
имеют SHOWN = 0
.
Сначала insert into
с VALUES(4,4)
прошло без ошибок. Но с тех пор каждый следующий (с разными значениями) выдает мне эту ошибку. Я что-то не так написал в триггере?
редактировать
DDL таблиц POLE
и HRA
--------------------------------------------------------
-- DDL for Table POLE
--------------------------------------------------------
CREATE TABLE "SK1X1"."POLE"
( "ID" NUMBER,
"ROW_ID" NUMBER(3,0),
"COL_ID" NUMBER(3,0),
"OBLAST_ID" NUMBER,
"VALUE" NUMBER(2,0),
"SHOWN" NUMBER(1,0) DEFAULT 0
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "STUDENTS2014" ;
--------------------------------------------------------
-- DDL for Table HRA
--------------------------------------------------------
CREATE TABLE "SK1X1"."HRA"
( "ID" NUMBER,
"FIRST_MOVE" TIMESTAMP (6) DEFAULT '01-01-17',
"LAST_MOVE" TIMESTAMP (6) DEFAULT '01-01-17',
"TAGGED_MINES_COUNT" NUMBER(4,0) DEFAULT 0,
"STAV_ID" NUMBER,
"OBLAST_ID" NUMBER
) SEGMENT CREATION IMMEDIATE
PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "STUDENTS2014" ;
--------------------------------------------------------
-- DDL for Index POLE_PK
--------------------------------------------------------
CREATE UNIQUE INDEX "SK1X1"."POLE_PK" ON "SK1X1"."POLE" ("ID")
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "STUDENTS2014" ;
--------------------------------------------------------
-- DDL for Index HRA_PK
--------------------------------------------------------
CREATE UNIQUE INDEX "SK1X1"."HRA_PK" ON "SK1X1"."HRA" ("ID")
PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "STUDENTS2014" ;
--------------------------------------------------------
-- DDL for Trigger POLE_TRG
--------------------------------------------------------
CREATE OR REPLACE TRIGGER "SK1X1"."POLE_TRG"
BEFORE INSERT ON POLE
FOR EACH ROW
BEGIN
<<COLUMN_SEQUENCES>>
BEGIN
IF INSERTING AND :NEW.ID IS NULL THEN
SELECT POLE_SEQ.NEXTVAL INTO :NEW.ID FROM SYS.DUAL;
END IF;
END COLUMN_SEQUENCES;
END;
/
ALTER TRIGGER "SK1X1"."POLE_TRG" ENABLE;
--------------------------------------------------------
-- DDL for Trigger HRA_TRG
--------------------------------------------------------
CREATE OR REPLACE TRIGGER "SK1X1"."HRA_TRG"
BEFORE INSERT ON HRA
FOR EACH ROW
BEGIN
<<COLUMN_SEQUENCES>>
BEGIN
IF INSERTING AND :NEW.ID IS NULL THEN
SELECT HRA_SEQ1.NEXTVAL INTO :NEW.ID FROM SYS.DUAL;
END IF;
END COLUMN_SEQUENCES;
END;
/
ALTER TRIGGER "SK1X1"."HRA_TRG" ENABLE;
--------------------------------------------------------
-- Constraints for Table POLE
--------------------------------------------------------
ALTER TABLE "SK1X1"."POLE" ADD CONSTRAINT "POLE_CHK1" CHECK (shown in ( '1', '0' )) ENABLE;
ALTER TABLE "SK1X1"."POLE" ADD CONSTRAINT "POLE_PK" PRIMARY KEY ("ID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "STUDENTS2014" ENABLE;
ALTER TABLE "SK1X1"."POLE" MODIFY ("ID" NOT NULL ENABLE);
ALTER TABLE "SK1X1"."POLE" MODIFY ("ROW_ID" NOT NULL ENABLE);
ALTER TABLE "SK1X1"."POLE" MODIFY ("COL_ID" NOT NULL ENABLE);
ALTER TABLE "SK1X1"."POLE" MODIFY ("OBLAST_ID" NOT NULL ENABLE);
ALTER TABLE "SK1X1"."POLE" MODIFY ("VALUE" NOT NULL ENABLE);
ALTER TABLE "SK1X1"."POLE" MODIFY ("SHOWN" NOT NULL ENABLE);
--------------------------------------------------------
-- Constraints for Table HRA
--------------------------------------------------------
ALTER TABLE "SK1X1"."HRA" ADD CONSTRAINT "HRA_PK" PRIMARY KEY ("ID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS
STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT FLASH_CACHE DEFAULT CELL_FLASH_CACHE DEFAULT)
TABLESPACE "STUDENTS2014" ENABLE;
ALTER TABLE "SK1X1"."HRA" MODIFY ("ID" NOT NULL ENABLE);
ALTER TABLE "SK1X1"."HRA" MODIFY ("TAGGED_MINES_COUNT" NOT NULL ENABLE);
ALTER TABLE "SK1X1"."HRA" MODIFY ("STAV_ID" NOT NULL ENABLE);
ALTER TABLE "SK1X1"."HRA" MODIFY ("OBLAST_ID" NOT NULL ENABLE);
ALTER TABLE "SK1X1"."HRA" MODIFY ("FIRST_MOVE" NOT NULL ENABLE);
ALTER TABLE "SK1X1"."HRA" MODIFY ("LAST_MOVE" NOT NULL ENABLE);