首页 > 解决方案 > “SQL 命令未正确结束” - 插入语句

问题描述

运行语句时出现以下错误,

[sql] Failed to execute:  
INSERT INTO REPORT ( 
                   ID
                 , CI
                 , TECHNOLOGY
                 , MAJOR_VERSION
                 , MINOR_VERSION
                 , PATCH_LEVEL
                 , INSTALL_DATE
                 , INSTALLED_BY
                 , TASK ) values ( 
                                 REPORT_ID_SEQ.nextval
                               , 'host1'
                               , 'Apple card'
                               , 'N/A'
                               , 'N/A'
                               , '12233'
                               , SYSTIMESTAMP
                               , 'test@gmail.com'
                               , '' ) FROM dual

执行 SQL 脚本时出错:java.sql.SQLSyntaxErrorException:ORA-00933:SQL 命令未正确结束

标签: sqloracle

解决方案


最后你不需要from dual,你没有使用任何 SELECT 语句。

您可以执行SELECTVALUES插入值:

使用选择

INSERT INTO report 
            ( 
                    id, 
                    ci, 
                    technology, 
                    major_version, 
                    minor_version, 
                    patch_level, 
                    install_date, 
                    installed_by, 
                    task 
        ) 
SELECT     
                        report_id_seq.nextval, 
                        'host1', 
                        'Apple card', 
                        'N/A', 
                        'N/A', 
                        '12233', 
                        systimestamp, 
                        'test@gmail.com', 
                        '' 
from        dual;

使用价值观

INSERT INTO report 
            ( 
                        id, 
                        ci, 
                        technology, 
                        major_version, 
                        minor_version, 
                        patch_level, 
                        install_date, 
                        installed_by, 
                        task 
            ) 
            VALUES 
            ( 
                        report_id_seq.nextval, 
                        'host1', 
                        'Apple card', 
                        'N/A', 
                        'N/A', 
                        '12233', 
                        systimestamp, 
                        'test@gmail.com', 
                        '' 
            ) ;

推荐阅读