这是我对Appointment表的创建表查询
CREATE TABLE Appointment (
ap_id varchar(10) PRIMARY KEY,
ap_date Date,
pat_id varchar(10) REFERENCES Patient(pat_id),
doc_id varchar(10) REFERENCES Doctor(doc_id),
rec_id varchar(10) REFERENCES Receptionist(rec_id)
);
这是我的pl / sql块
DECLARE
ap_id Appointment.ap_id%type;
date Appointment.ap_date%type;
pat_id Appointment.pat_id%type;
doc_id Appointment.doc_id%type;
rec_id Appointment.rec_id%type;
BEGIN
ap_id:=:appointment_id;
date:=:appointment_date;
pat_id:=:patient_id;
doc_id:=:doctor_id;
rec_id:=:Receptionist_id;
INSERT INTO Appointment
VALUES (ap_id,date,pat_id,doc_id,rec_id);
END;
运行时会出错
ORA-06550: line 15, column 15:
PL/SQL: ORA-00936: missing expression
ORA-06550: line 14, column 1:
PL/SQL: SQL Statement ignored
1. DECLARE
2. ap_id Appointment.ap_id%type;
3. date Appointment.ap_date%type;
出了什么问题?
答案 0 :(得分:4)
问题是您使用了关键字作为变量名称。 'date'使变量名称成为其他名称,它将起作用。
您需要提供不同名称的陈述
date Appointment.ap_date%type;
和
date:=:appointment_date;
和
INSERT INTO Appointment
VALUES (ap_id,date,pat_id,doc_id,rec_id);
另外,最佳做法是始终使用INSERT语句中的列列表。
INSERT INTO tbl_name (columns list separated by comma)
VALUES (value list separated by comma)
希望它有所帮助。