首先我创建了审计表。表的代码如下:
CREATE TABLE AUDIT_NEW_1
( AUDIT_NUMBER NUMBER(3,0) NOT NULL,
"CUSTOMER_NAME" VARCHAR2(20 BYTE) NOT NULl,
"CONCERT_ID" NUMBER(5,0) NOT NULL,
"EVENT_DATE" DATE NOT NULL,
"VENUE_ID" NUMBER(5,0),
CONSTRAINT AUDIT_NEW_1 PRIMARY KEY (AUDIT_NUMBER)
);
bookings
表的代码
CREATE TABLE Bookings
(
Event_Event_ID NUMBER (5) NOT NULL ,
Customer_Customer_ID NUMBER (5) NOT NULL ,
Arrival_time TIMESTAMP ,
Evaluation NUMBER (1) ,
Vehicle_Number VARCHAR2 (7)
) ;
创建触发器代码:
CREATE OR REPLACE
TRIGGER LOW_EVALUAT_1
AFTER INSERT OR UPDATE OF EVALUATION ON BOOKINGS
FOR EACH ROW
DECLARE
CUSTOMER_NAME VARCHAR(20 CHAR);
CONCERT_ID NUMBER (5,0);
EVENT_DATE DATE;
VENUE_ID NUMBER(5,0 );
BEGIN
IF (:NEW.EVALUATION = 0) THEN
SELECT CUSTOMER.CUSTOMER_ID, CONCERT.CONCERT_ID, EVENT.EVENT_DATE, VENUE.VENUE_ID
INTO CUSTOMER_NAME,CONCERT_ID,EVENT_DATE,VENUE_ID
FROM CUSTOMER, CONCERT, EVENT, VENUE
WHERE
CUSTOMER.CUSTOMER_ID = :NEW.CUSTOMER_ID AND
EVENT.EVENT_ID = :NEW.EVENT_ID AND
CONCERT.CONCERT_ID = EVENT.CONCERT_ID;
INSERT INTO AUDIT_NEW_1 VALUES (AUDIT_NUMBER.NEXTVAL, CUSTOMER_NAME, CONCERT_ID,
EVENT_DATE, VENUE_ID, :NEW.EVALUATION);
END IF;
END;
SQL开发人员在这些行上返回错误你能帮我解决一下错误吗?:
SELECT CUSTOMER.CUSTOMER_ID, CONCERT.CONCERT_ID, EVENT.EVENT_DATE, VENUE.VENUE_ID
INTO CUSTOMER_NAME,CONCERT_ID,EVENT_DATE,VENUE_ID
错误返回
Error(12,30): PLS-00049: bad bind variable 'NEW.CUSTOMER_ID'
Error(13,24): PLS-00049: bad bind variable 'NEW.EVENT_ID'
CREATE TABLE Bookings
(
Event_Event_ID NUMBER (5) NOT NULL ,
Customer_Customer_ID NUMBER (5) NOT NULL ,
Arrival_time TIMESTAMP ,
Evaluation NUMBER (1) ,
Vehicle_Number VARCHAR2 (7)
) ;
ALTER TABLE Bookings ADD CHECK
(
Evaluation IN (0, 1, 2, 3, 4, 5)
)
;
ALTER TABLE Bookings ADD CONSTRAINT Relation_2__IDX PRIMARY KEY
(
Event_Event_ID, Customer_Customer_ID
)
;
CREATE TABLE Concert
(
Concert_ID NUMBER (5) NOT NULL ,
Name VARCHAR2 (25) NOT NULL ,
Duration NUMBER (1) NOT NULL ,
Type VARCHAR2 (9) NOT NULL ,
Cost NUMBER (25) NOT NULL
) ;
ALTER TABLE Concert ADD CHECK
(
Duration IN (2, 3, 4, 5)
)
;
ALTER TABLE Concert ADD CHECK
(
Cost BETWEEN 30 AND 500
)
;
ALTER TABLE Concert ADD CONSTRAINT Concert_PK PRIMARY KEY
(
Concert_ID
)
;
CREATE TABLE Customer
(
Customer_ID NUMBER (5) NOT NULL ,
Full_Name VARCHAR2 (20) NOT NULL ,
Gender VARCHAR2 (6) NOT NULL ,
Telephone_Number NUMBER (11) NOT NULL ,
Address VARCHAR2 (50) NOT NULL
) ;
ALTER TABLE Customer ADD CHECK
(
Gender IN ('F', 'M')
)
;
ALTER TABLE Customer ADD CONSTRAINT Customer_PK PRIMARY KEY
(
Customer_ID
)
;
CREATE TABLE Event
(
Event_ID NUMBER (5) NOT NULL ,
"Date" DATE NOT NULL ,
Concert_ID NUMBER (5) NOT NULL ,
Venue_ID NUMBER (5) NOT NULL
) ;
ALTER TABLE Event ADD CONSTRAINT Event_PK PRIMARY KEY
(
Event_ID
)
;
CREATE TABLE Venue
(
Venue_ID NUMBER (5) NOT NULL ,
Name VARCHAR2 (25) NOT NULL ,
Capacity NUMBER (6) NOT NULL ,
PostCode VARCHAR2 (15) NOT NULL ,
Location VARCHAR2 (20) NOT NULL
) ;
ALTER TABLE Venue ADD CHECK
(
Capacity BETWEEN 1000 AND 60000
)
;
ALTER TABLE Venue ADD CONSTRAINT Venue_PK PRIMARY KEY
(
Venue_ID
)
;
ALTER TABLE Event ADD CONSTRAINT Event_Concert_FK FOREIGN KEY ( Concert_ID ) REFERENCES Concert ( Concert_ID ) ;
ALTER TABLE Event ADD CONSTRAINT Event_Venue_FK FOREIGN KEY ( Venue_ID ) REFERENCES Venue ( Venue_ID ) ;
ALTER TABLE Bookings ADD CONSTRAINT FK_ASS_22 FOREIGN KEY ( Event_Event_ID ) REFERENCES Event ( Event_ID ) ;
ALTER TABLE Bookings ADD CONSTRAINT FK_ASS_23 FOREIGN KEY ( Customer_Customer_ID ) REFERENCES Customer ( Customer_ID ) ;
答案 0 :(得分:2)
您在触发器中使用的列名与其他表不匹配。 bookings
包含名为customer_customer_id
和event_event_id
的列,而不仅仅是customer_id
和event_id
。这些是PLS-00049的直接错误。
由于某种原因,event
"Date"
已event_date
,而不是:new.evaluation
。
当只有五列时,你会在审计表中插入六个值 - audit_num
无处可去......
这些都是相当基本的错误。
至少假设您有一个名为CREATE OR REPLACE
TRIGGER LOW_EVALUAT_1
AFTER INSERT OR UPDATE OF EVALUATION ON BOOKINGS
FOR EACH ROW
DECLARE
CUSTOMER_NAME VARCHAR(20 CHAR);
CONCERT_ID NUMBER (5,0);
EVENT_DATE DATE;
VENUE_ID NUMBER(5,0 );
BEGIN
IF (:NEW.EVALUATION = 0) THEN
SELECT CUSTOMER.CUSTOMER_ID, CONCERT.CONCERT_ID, EVENT."Date", VENUE.VENUE_ID
INTO CUSTOMER_NAME,CONCERT_ID,EVENT_DATE,VENUE_ID
FROM CUSTOMER, CONCERT, EVENT, VENUE
WHERE
CUSTOMER.CUSTOMER_ID = :NEW.CUSTOMER_CUSTOMER_ID AND
EVENT.EVENT_ID = :NEW.EVENT_EVENT_ID AND
CONCERT.CONCERT_ID = EVENT.CONCERT_ID;
INSERT INTO AUDIT_NEW_1 VALUES (AUDIT_NUMBER.NEXTVAL, CUSTOMER_NAME, CONCERT_ID,
EVENT_DATE, VENUE_ID);
END IF;
END;
/
的序列:
select
但我不认为它会像你期望的那样发挥作用;您需要在too_many_rows
开始加入,或者获得no_data_found
,您仍然可以获得该加入SELECT CUSTOMER.FULL_NAME, ...
,具体取决于您的数据。根据您如何定义局部变量,它看起来也像SELECT CUSTOMER.CUSTOMER_ID, ...
而不是{{1}} - 因此假设您确实希望在审计表中存储名称而不是ID,这本身有点奇怪。你真的不需要变量,你可以选择作为插入的一部分,但这是另一个主题。
答案 1 :(得分:0)
你的DDL:
CREATE TABLE Bookings
(
Event_Event_ID
但在内部触发器中你有:
EVENT.EVENT_ID = :NEW.EVENT_ID AND
应该是:
EVENT.EVENT_ID = :NEW.EVENT_EVENT_ID AND