我正在尝试执行以下查询。我认为应该可以工作,但是我似乎没有运行CREATE Statement
造成这种情况的原因是Loco_No.Loco_Class_No.Max_Tow_Weight
我不确定在 PL/SQL 中是否有效的这条逻辑。
CREATE TABLE Train
(Train_No integer PRIMARY KEY,
Loco_No integer
REFERENCES Locomotive(Loco_No),
Back_Loco_No float
REFERENCES Locomotive(Loco_No),
Train_Length float
CONSTRAINT Train_Len
CHECK(Train_Length <= 400),
Train_Weight float
CONSTRAINT Train_Weight
CHECK(Train_Weight <= Loco_No.Loco_Class_No.Max_Tow_Weight)));
我不能这样称呼我Max_Tow_Weight
吗?
我的其他表格供参考
CREATE TABLE Locomotive
(Loco_No integer PRIMARY KEY,
Serial_No integer UNIQUE,
Loco_Class_No integer
REFERENCES Locomotive_Class(Loco_Class_No),
Loco_name varchar2(20));
CREATE TABLE Locomotive_Class
(Loco_Class_No integer PRIMARY KEY,
Max_Tow_Weight float NOT NULL,
Loco_Class_Len float NOT NULL);
更新
CREATE TRIGGER LOCOWEIGHT
BEFORE INSERT
ON Locomotive_Class
REFERENCING NEW AS New
FOR EACH ROW
BEGIN
SELECT Train_Weight FROM locomotive
IF (Train_Weight < MAX_TOW_WEIGHT) THEN
RAISE cError;
EXCEPTION
WHEN cError THEN
RAISE_APPLICATION_EXCEPTION('Train weight has exceeded max tow weight');
END;