0

我创建了这张表:

CREATE TABLE diagnosis(
  diag_id NUMBER(8),
  SCT_CODE CHAR(10),
  diag_date DATE NOT NULL,
  GP_ID CHAR(5),
  PHN CHAR(5),
  Rx CHAR(3),
  CONSTRAINT diagnosis_PK PRIMARY KEY (diag_id, SCT_CODE),
  CONSTRAINT diagnosis_FK4 FOREIGN KEY (SCT_CODE)
    REFERENCES symptom (SCT_CODE) ON DELETE CASCADE,
  CONSTRAINT diagnosis_FK1 FOREIGN KEY (GP_ID)
    REFERENCES GP (GP_ID) ON DELETE CASCADE,
  CONSTRAINT diagnosis_FK2 FOREIGN KEY (PHN)
    REFERENCES Patient (PHN) ON DELETE CASCADE,
  CONSTRAINT diagnosis_FK3 FOREIGN KEY (Rx)
    REFERENCES drug (Rx)
  ON DELETE CASCADE);

我已经尝试了这两种方法来填充表格,但它不起作用。请帮助我的语法有什么问题

INSERT ALL
  INTO DIAGNOSIS VALUES ('10000001', '38341003', '04-APR-12', ‘GP001’, ‘p1001’, ‘Rx1’)
  INTO DIAGNOSIS VALUES ('10000002', '423430007', '07-APR-12', ‘GP001’, ‘p1001’, ‘Rx1’)
  INTO DIAGNOSIS VALUES ('10000003', '371032004', '05-APR-12', ‘GP002’, ‘p1002’, ‘Rx2’)
  INTO DIAGNOSIS VALUES ('10000004', '38341003', '08-APR-12', ‘GP003’, ‘p1003’, ‘Rx1’)
  INTO DIAGNOSIS VALUES ('10000005', '73211009', '07-APR-12', ‘GP003’, ‘p1003’, ‘Rx3’)
  INTO DIAGNOSIS VALUES ('10000006', '73211009', '06-APR-12', ‘GP004’, ‘p1004’, ‘Rx3’)
  INTO DIAGNOSIS VALUES ('10000007', '38341003', '10-APR-12', ‘GP001’, ‘p1005’, ‘Rx1’)
  SELECT * FROM DUAL;

/* Populate Diagnosis Table */

INSERT INTO Diagnosis(diag_id, SCT_CODE, diag_date, GP_ID, PHN, Rx)
  VALUES ('10000001', ‘38341003’, '04-Apr-12', 'GP001', 'p1001', 'Rx1');
INSERT INTO Diagnosis(diag_id, SCT_CODE, diag_date, GP_ID, PHN, Rx)
  VALUES ('10000002', ‘423430007’, '07-Apr-12', 'GP001', 'p1001', 'Rx1');
INSERT INTO Diagnosis(diag_id, SCT_CODE, diag_date, GP_ID, PHN, Rx)
  VALUES ('10000003', ‘371032004’, '05-Apr-12', 'GP003', 'p1002', 'Rx2');
INSERT INTO Diagnosis(diag_id, SCT_CODE, diag_date, GP_ID, PHN, Rx)
  VALUES ('10000004', ‘38341003’, '08-Apr-12', 'GP003', 'p1003', 'Rx1');
INSERT INTO Diagnosis(diag_id, SCT_CODE, diag_date, GP_ID, PHN, Rx)
  VALUES ('10000005’, ‘73211009’, '07-Apr-12', 'GP003', 'p1003', 'Rx3');
INSERT INTO Diagnosis(diag_id, SCT_CODE, diag_date, GP_ID, PHN, Rx)
  VALUES ('10000006', ‘73211009’, '06-Apr-12', 'GP004', 'p1004', 'Rx3');
INSERT INTO Diagnosis(diag_id, SCT_CODE, diag_date, GP_ID, PHN, Rx)
  VALUES ('10000006', ‘38341003’, '10-Apr-12', 'GP001', 'p1005', 'Rx1');
4

1 回答 1

4

正如评论者(@Glenn)所说,您的问题很可能是单引号的使用非常不一致。

这两项工作:

INSERT ALL
  INTO DIAGNOSIS VALUES 
      ('10000001', '38341003', '04-APR-12', 'GP001', 'p1001', 'Rx1')
  INTO DIAGNOSIS VALUES 
      ('10000002', '423430007', '07-APR-12', 'GP001', 'p1001', 'Rx1')
SELECT * FROM DUAL;

INSERT INTO Diagnosis(diag_id, SCT_CODE, diag_date, GP_ID, PHN, Rx)
  VALUES ('10000003', '371032004', '05-Apr-12', 'GP003', 'p1002', 'Rx2');
INSERT INTO Diagnosis(diag_id, SCT_CODE, diag_date, GP_ID, PHN, Rx)
  VALUES ('10000004', '38341003', '08-Apr-12', 'GP003', 'p1003', 'Rx1');

我所做和经历的一切,并确保'始终使用它。

看到这个 sqlfiddle: http ://sqlfiddle.com/#!4/c824d/ 1(我已经删除了约束,因为我不想输入所有这些。)

不过,就我个人而言,我一直不喜欢第一种方法,因为这select * from dual看起来太武断了(是的,我知道它有效——这更像是一个审美问题。)

于 2012-04-11T03:17:24.283 回答