为什么只使用 1 个 create 语句时 sql 脚本中的“创建表"执行 3 次? [英] why is 'create table' in sql script executing 3 times when only using 1 create statement?
问题描述
我有一个 SQL 脚本,我想在其中自动创建表.但是,当我执行它时,它似乎试图创建表 3 次.第一次,它创建表.接下来的 2 次,它通过抛出一个
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 creates the table. The next 2 times, it complains it already exists by throwing an
"ORA-00955: name is already used by an existing object"
这里是我的 sql 脚本(@/vagrant/scripts/db_tables_stubs.sql):
Here my sql script(@/vagrant/scripts/db_tables_stubs.sql):
CREATE TABLE IDA_RADIUS_USER(
CHECK_STRING VARCHAR2(30),
REPLY_STRING VARCHAR2(300),
RADIUS_USERNAME VARCHAR2(30),
ACCOUNT_STATUS VARCHAR2(30)
);
/
show errors;
这就是我得到的:
SQL> select * from IDA_RADIUS_USER;
no rows selected
SQL> drop table IDA_RADIUS_USER;
Table dropped.
SQL> @/vagrant/scripts/db_tables_stubs.sql
Table created.
CREATE TABLE IDA_RADIUS_USER(
*
ERROR at line 1:
ORA-00955: name is already used by an existing object
No errors.
CREATE TABLE IDA_RADIUS_USER(
*
ERROR at line 1:
ORA-00955: name is already used by an existing object
No errors.
Commit complete.
我想要的只是自动化创建该表的过程.
All I want is to automate the process of creating that table.
请帮帮我.我不明白为什么会这样.烦死了!
Please help me. I can't figure out why that's happening. It's annoying!
推荐答案
你说过你已经注释掉了代码.正是这些评论导致了问题.
You've said you have commented out code. It is those comments that are causing the problem.
SQL> create table t42(id number(38));
Table created.
SQL> /*insert into t42(id) values (1);*/
create table 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);*/
create table 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.
SQL*Plus 文档也说一个>:
The SQL*Plus documentation also says:
在脚本的不同行、SQL 命令的同一行或 PL/SQL 块的一行中输入 SQL 注释分隔符 /*...*/
.
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> create table 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>
这篇关于为什么只使用 1 个 create 语句时 sql 脚本中的“创建表"执行 3 次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!