Reputation: 35
I wrote a .sql script in Linux environment and I'm executing it in SQL*Plus but a single query in that is getting executed twice.
Script:
cat s2.sql
/* Global Name of DB */
select * from global_name;
/*Database Status */
SELECT INSTANCE_NAME, STATUS, DATABASE_STATUS FROM V$INSTANCE;
Output:
SQL> @ s2.sql
GLOBAL_NAME
--------------------------------------------------------------------------------
xyz
GLOBAL_NAME
--------------------------------------------------------------------------------
xyz
INSTANCE_NAME STATUS DATABASE_STATUS
---------------- ------------ -----------------
xyz OPEN ACTIVE
I tried it with both the extension .sql and .txt though I'm getting the same results.
Why is it doing that, and how can I stop it?
Upvotes: 0
Views: 311
Reputation: 191235
The problem is the second comment. The line:
/*Database Status */
is being interpreted as a buffer-submitting /
, not as a comment at all. If you add a space to match the other one:
/* Database Status */
then it will be correctly seen as a comment, and won't cause the second invocation of the statement.
The behaviour you're seeing is actually documented, sort of - indirectly:
You must enter a space after the slash-asterisk(/*) beginning a comment.
Upvotes: 2