Skip to content Skip to sidebar Skip to footer

Why Is 'create Table' In Sql Script Executing 3 Times When Only Using 1 Create Statement?

I have an SQL script in which I want to automate the creation of a table. However, when I exec it, it seems as though it's trying to create the table 3 times. The first time, it cr

Solution 1:

You've said you have commented out code. It is those comments that are causing the problem.

SQL>createtable t42(id number(38));

Table created.

SQL>/*insert into t42(id) values (1);*/createtable t42(id number(38))
             *
ERROR at line 1:
ORA-00955: name is already used by an existing object


SQL>/*exec dbms_stats.gather_schema_stats(user);*/createtable t42(id number(38))
             *
ERROR at line 1:
ORA-00955: name is already used by an existing object


SQL>show errors
No errors.
SQL>

The slash (/) at the start of the comments is resubmitting the command in the buffer.

The SQL*Plus documentation also says:

Enter the SQL comment delimiters, /*...*/, on separate lines in your script, on the same line as a SQL command, or on a line in a PL/SQL block.

You must enter a space after the slash-asterisk (/*) beginning a comment.

So if you change your comments to have a space between the /* and the commented-out code that won't happen, and those will be ignored:

SQL>createtable t42(id number(38));

Table created.

SQL>/* insert into t42(id) values (1); */SQL>/* exec dbms_stats.gather_schema_stats(user); */SQL>show errors
No errors.
SQL>

Post a Comment for "Why Is 'create Table' In Sql Script Executing 3 Times When Only Using 1 Create Statement?"