Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle sqlplus comments

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?

like image 885
Rnet Avatar asked Feb 22 '26 01:02

Rnet


1 Answers

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;
like image 130
Nick Krasnov Avatar answered Feb 23 '26 20:02

Nick Krasnov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!