Oracle sqlplus comments

巧了我就是萌 提交于 2021-02-08 05:44:23

问题


Why does the following insert statement not work when executed like sqlplus <connect> @file

INSERT INTO abc ( a
                 ,b
                 ,c)
         VALUES ( '1' --a
                 ,'2' --b
                 ,'3'); --c

but it works without the comments i.e

INSERT INTO abc ( a
                 ,b
                 ,c)
         VALUES ( '1'
                 ,'2'
                 ,'3');

Does sqlplus flatten the file i.e execute the whole thing on a single line? which might result in rest of the line getting commented out?


回答1:


The fist insert statement didn't work only because of the last comment --c you've placed after the statement terminator. SQL*Plus doesn't allow any text after a statement terminator (';' semicolon in this case). So this version of your first insert statement will be executed successfully:

INSERT INTO abc ( a
                 ,b
                 ,c)
         VALUES ( '1' --a
                 ,'2' --b
                 ,'3'); 

So will this one:

INSERT INTO abc ( a
                 ,b
                 ,c)
         VALUES ( '1' --a
                 ,'2' --b
                 ,'3') --c;


来源:https://stackoverflow.com/questions/18516132/oracle-sqlplus-comments

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!