0

これは、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;

何が悪かったのか ???

4

1 に答える 1

4

問題は、変数名にキーワードを使用したことです。「日付」は、その変数名を別の名前にすると機能します。

別の名前を付ける必要があるステートメント

  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 に答える