我有这个触发器:
CREATE OR REPLACE TRIGGER TR_SIGHTING_DESC
BEFORE INSERT ON sightings
FOR EACH ROW
BEGIN
SELECT bird_name
INTO bn
from birds
where bird_id = :new.bird_id;
:new.description := 'A bird of the species '
|| bn
|| ' was spotted in the '
|| :new.latitude || ','|| :new.longitude
|| ' part of the observation area';
END;
/
它一直说它无效。我试图检索bird_name形成其相应的ID,例如,这被插入到目击表中:
INSERT INTO sightings (spotter_id, bird_id, latitude,
longitude, sighting_date)
VALUES (2457, 901, -28.0, 152, '09-MAR-2016');
答案 0 :(得分:1)
你必须声明变量
CREATE OR REPLACE TRIGGER TR_SIGHTING_DESC
BEFORE INSERT ON sightings
FOR EACH ROW
DECLARE bn birds.bird_name%type;
BEGIN
SELECT bird_name
INTO bn
from birds
where bird_id = :new.bird_id;
:new.description := 'A bird of the species '
|| bn
|| ' was spotted in the '
|| :new.latitude || ','|| :new.longitude
|| ' part of the observation area';
END;
/
答案 1 :(得分:0)
好醇2200 你必须在插入之前声明dn。