我正在尝试插入新数据的ORA-00928

时间:2020-08-03 07:33:39

标签: sql oracle sql-insert

我可能在这里犯了一个菜鸟错误,但是当我尝试插入新数据时,我得到了ORA-00928错误代码。看看:

INSERT ALL
INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'GLOCK', '1982', 'PISTOLS', 'AUSTRIA')
INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'BERETTA', '1526', 'PISTOLS', 'ITALY')
INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'SMITH AND WESSON', '1856', 'PISTOLS', 'UNITED STATES')
INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'MOSSBERG', '1919', 'SHOTGUNS', 'UNITED STATES')
INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'BENELLI', '1967', 'SHOTGUNS', 'UNITED STATES')
INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'BROWNING', '1878', 'SHOTGUNS', 'UNITED STATES')
INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'WINCHESTER', '1866', 'RIFLES', 'UNITED STATES')
INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'BUSHMASTER', '1973', 'RIFLES', 'UNITED STATES')
INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'REMINGTON', '1816', 'RIFLES', 'UNITED STATES')
INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'KLASHNIKOV', '1807', 'RIFLES', 'UNITED STATES');

我在做什么错?任何见解都会有所帮助。

3 个答案:

答案 0 :(得分:1)

在声明末尾添加此内容:

SELECT * FROM dual

ORA-00928的意思是“缺少SELECT关键字”。 INSERT ALL语句需要它,因此其格式为:

INSERT ALL
  INTO t1 (col1, col2, ...) VALUES (val1, val2, ...)
  INTO t1 (col1, col2, ...) VALUES (val1, val2, ...)
  INTO t1 (col1, col2, ...) VALUES (val1, val2, ...)
SELECT * FROM dual

答案 1 :(得分:0)

  1. Year_founded列必须是INT类型的列,因此请勿使用'' 在INT类型列中插入值时。

  2. 在末尾添加SELECT * FROM DUAL

以下是使用您的查询的示例:

    INSERT ALL
    INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
    VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'GLOCK', 1982, 'PISTOLS', 'AUSTRIA')
    INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
    VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'BERETTA', 1526, 'PISTOLS', 'ITALY')
    INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
    VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'SMITH AND WESSON', 1856, 'PISTOLS', 'UNITED STATES')
    INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
    VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'MOSSBERG', 1919, 'SHOTGUNS', 'UNITED STATES')
    INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
    VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'BENELLI', 1967, 'SHOTGUNS', 'UNITED STATES')
    INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
    VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'BROWNING', 1878, 'SHOTGUNS', 'UNITED STATES')
    INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
    VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'WINCHESTER', 1866, 'RIFLES', 'UNITED STATES')
    INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
    VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'BUSHMASTER', 1973, 'RIFLES', 'UNITED STATES')
    INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
    VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'REMINGTON', 1816, 'RIFLES', 'UNITED STATES')
    INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
    VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'KLASHNIKOV', 1807, 'RIFLES', 'UNITED STATES')

    SELECT 1 FROM DUAL;

答案 2 :(得分:0)

完整脚本(';'应在DUAL之后)

INSERT ALL
INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'GLOCK', '1982', 'PISTOLS', 'AUSTRIA')
INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'BERETTA', '1526', 'PISTOLS', 'ITALY')
INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'SMITH AND WESSON', '1856', 'PISTOLS', 'UNITED STATES')
INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'MOSSBERG', '1919', 'SHOTGUNS', 'UNITED STATES')
INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'BENELLI', '1967', 'SHOTGUNS', 'UNITED STATES')
INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'BROWNING', '1878', 'SHOTGUNS', 'UNITED STATES')
INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'WINCHESTER', '1866', 'RIFLES', 'UNITED STATES')
INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'BUSHMASTER', '1973', 'RIFLES', 'UNITED STATES')
INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'REMINGTON', '1816', 'RIFLES', 'UNITED STATES')
INTO MANUFACTURER ( MANUFACTURER_ID, NAME, YEAR_FOUNDED, SPECIALTY, ORIGIN)
VALUES (MANUFACTURER_ID_SEQ.NEXTVAL, 'KLASHNIKOV', '1807', 'RIFLES', 'UNITED STATES')
select * from dual;