0

这是我对约会表的创建表查询

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;

什么地方出了错 ???

4

1 回答 1

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)

希望能帮助到你。

于 2013-10-22T18:06:26.703 回答