CREATE TABLE emp (
empno NUMBER (10) NOT NULL,
empname VARCHAR2 (50) NOT NULL,
mgr VARCHAR2 (10),
hiredate DATE,
sal NUMBER (10),
comm VARCHAR2 (10),
CONSTRAINT emp_pk PRIMARY KEY (empno)
) ;
DESC emp ;
INSERT ALL
INTO emp
(100, 'MARK', 'CXS', hire_date('1999-09-08', 'yyyy/mm/dd'), 8000, 'axw')
(200, 'peter', 'NULL', hire_date('1996-01-08', 'yyyy/mm/dd'), 9000)
(300, 'karl', 'NULL', hire_date('1995-05-08', 'yyyy/mm/dd'), 5000, 'AZQ')
(400, 'MAx', 'NULL', hire_date('1994-04-08', 'yyyy/mm/dd'), 10000, 'DES')
(500, 'Maggie', 'SAQ', hire_date('1998-06-08', 'yyyy/mm/dd'), 20000, 'QAS')
SELECT * FROM dual ;
答案 0 :(得分:2)
您的insert all
syntax格式不正确,您需要多个into ... values ...
对。目前,它正试图将100
解释为列名,因此会看到您所看到的特定错误。
您还拥有hire_date(...)
而不是to_date(...)
,并且您缺少了comm
值之一;假设应该为空:
INSERT ALL
INTO emp (empno, empname, mgr, hiredate, sal, comm)
VALUES (100, 'MARK', 'CXS', TO_DATE('1999-09-08', 'yyyy-mm-dd'), 8000, 'axw')
INTO emp (empno, empname, mgr, hiredate, sal, comm)
VALUES (200, 'peter', NULL, TO_DATE('1996-01-08', 'yyyy-mm-dd'), 9000, null)
INTO emp (empno, empname, mgr, hiredate, sal, comm)
VALUES (300, 'karl', NULL, TO_DATE('1995-05-08', 'yyyy-mm-dd'), 5000, 'AZQ')
INTO emp (empno, empname, mgr, hiredate, sal, comm)
VALUES (400, 'MAx', NULL, TO_DATE('1994-04-08', 'yyyy-mm-dd'), 10000, 'DES')
INTO emp (empno, empname, mgr, hiredate, sal, comm)
VALUES (500, 'Maggie', 'SAQ', TO_DATE('1998-06-08', 'yyyy-mm-dd'), 20000, 'QAS')
SELECT * FROM dual ;
5 rows inserted.
我还将stantng文字'NULL'
更改为纯null,因为看起来更温和了,这正是您真正想要的。
我将日期格式掩码更改为使用-
而不是/
来匹配值。但是,如果您使用这样的固定值,则改为使用日期文字更简单,例如代替
INTO emp (empno, empname, mgr, hiredate, sal, comm)
VALUES (100, 'MARK', 'CXS', TO_DATE('1999-09-08', 'yyyy-mm-dd'), 8000, 'axw')
使用:
INTO emp (empno, empname, mgr, hiredate, sal, comm)
VALUES (100, 'MARK', 'CXS', DATE '1999-09-08', 8000, 'axw')
答案 1 :(得分:1)
Oracle / PLSQL中INSERT ALL语句的语法为:
INSERT ALL
INTO mytable (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
INTO mytable (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
INTO mytable (column1, column2, column_n) VALUES (expr1, expr2, expr_n)
SELECT * FROM dual;
因此,您可以使用
INSERT ALL
INTO emp (empno, empname, mgr, hiredate, sal, comm)
VALUES (100, 'MARK', 'CXS', TO_DATE('1999-09-08', 'yyyy-mm-dd'), 8000, 'axw')
INTO emp (empno, empname, mgr, hiredate, sal, comm)
VALUES (200, 'peter', NULL, TO_DATE('1996-01-08', 'yyyy-mm-dd'), 9000, null)
INTO emp (empno, empname, mgr, hiredate, sal, comm)
VALUES (300, 'karl', NULL, TO_DATE('1995-05-08', 'yyyy-mm-dd'), 5000, 'AZQ')
INTO emp (empno, empname, mgr, hiredate, sal, comm)
VALUES (400, 'MAx', NULL, TO_DATE('1994-04-08', 'yyyy-mm-dd'), 10000, 'DES')
INTO emp (empno, empname, mgr, hiredate, sal, comm)
VALUES (500, 'Maggie', 'SAQ', TO_DATE('1998-06-08', 'yyyy-mm-dd'), 20000, 'QAS')
SELECT * FROM dual ;
对于任何想要空白/无值的列,如果将其包括为“ NULL”,则只需输入NULL,它将被视为文本NULL。