创建一个触发器TR_SIGHTING_DESC,它将自动填充目击 描述列根据以下模板。 'BIRD-NAME的鸟类被发现在X-Y部分 观察区'
**CREATE TABLE birds(
bird_id NUMBER,
bird_name VARCHAR2(50)
);
CREATE TABLE sightings(
sighting_id NUMBER,
spotter_id NUMBER,
bird_id NUMBER,
latitude NUMBER,
longitude NUMBER,
sighting_date DATE,
description VARCHAR2(255)
);**
CREATE OR REPLACE TRIGGER "TR_SIGNTING_DESC"
BEFORE INSERT ON sightings
FOR EACH ROW
DECLARE
X VARCHAR(5)
Y VARCHAR(7)
NAME VARCHAR2(50)
BEGIN
IF (:NEW.latitude >-28.1) THEN
SET X:='north';
ELSE
SET X:='south';
END IF;
IF (:NEW.longgitude>151.25) THEN
SET Y:='eastern';
ELSE
SET Y:='western';
END IF;
SELECT bird_name INTO NAME FROM birds WHERE bird_id= :NEW.bird_id
:NEW.description := CONCAT('A bird of the species', NAME, ' was spotted in the ',X,'-',Y,' part of the observation area')
END;
/
答案 0 :(得分:0)
您应该从触发器文本中删除设置;忘了一些“;”
CREATE OR REPLACE TRIGGER "TR_SIGNTING_DESC"
BEFORE INSERT ON sightings
FOR EACH ROW
DECLARE
X VARCHAR2(5);
Y VARCHAR2(7);
NAME VARCHAR2(50);
BEGIN
IF (:NEW.latitude >-28.1) THEN
X :='north';
ELSE
X :='south';
END IF;
IF (:NEW.longgitude>151.25) THEN
Y:='eastern';
ELSE
Y:='western';
END IF;
SELECT bird_name
INTO NAME
FROM birds
WHERE bird_id= :NEW.bird_id;
:NEW.description := 'A bird of the species' || NAME || ' was spotted in the ' || X || '-' || Y || ' part of the observation area';
END;
/