PL / SQL“SQL命令未正确结束”错误

时间:2021-08-21 06:31:05

I am currently working on developing some SQL scripts in PL/SQL Developer and I am getting an:

我目前正在开发PL / SQL Developer中的一些SQL脚本,我得到一个:

SQL Command not properly ended

SQL命令未正确结束

error that I am unsure how to solve.

错误,我不确定如何解决。

The code I am using looks something like this

我使用的代码看起来像这样

CREATE TABLE temp_table as
    SELECT * FROM table_x

INSERT INTO temp_table
    SELECT * FROM table_y

If I execute the two pieces (create table and the insert) as separate pieces everything runs fine, i.e. select each code block and execute. However if I try to execute everything, select all code and execute, I get an error saying that:

如果我将两个部分(创建表和插入)作为单独的部分执行,一切运行正常,即选择每个代码块并执行。但是,如果我尝试执行所有操作,选择所有代码并执行,我会收到一条错误消息:

SQL Command not properly ended

SQL命令未正确结束

I don't mind dealing with this when I am dealing with very small tables but when I have a significant number of operations I need to execute sequentially and when each operation takes a long time to run I would like to be to execute the code and walk away.

当我处理非常小的表时,我不介意处理这个问题,但是当我有大量的操作时,我需要按顺序执行,当每个操作需要很长时间才能运行时,我希望执行代码和走开。

Adding a semicolon raises a new error which is an error:

添加分号会引发新错误,这是一个错误:

invalid character

This is the code that raises the invalid character error.

这是引发无效字符错误的代码。

CREATE TABLE temp_table as 
    SELECT * FROM table_x where x > 1; 

INSERT INTO temp_table 
    ( 
    SELECT * FROM table_y where x > 1; 
    )

4 个解决方案

#1


Put a semicolon at the end of each statement.

在每个语句的末尾加一个分号。

#2


Try this:

CREATE TABLE temp_table as
SELECT * FROM table_x;

INSERT INTO temp_table
SELECT * FROM table_y;

I think the parentheses were messing you up.

我认为括号让你搞砸了。

#3


The parenthesis can be used to specify the columns on which you want to insert the data as in:

括号可用于指定要在其中插入数据的列,如下所示:

INSERT INTO temp_table ( col1,col2,...coln) SELECT ...

INSERT INTO temp_table(col1,col2,... coln)SELECT ...

You get an error because instead of a list of columns, the parser finds a select expression between parenthesis

您会收到错误,因为解析器会在括号之间找到一个select表达式,而不是列列表

#4


If you're running the script in one step in PL/SQL Developer, you may need to convert it to a "SQL*Plus" script - i.e. the semicolons are required to delimit the statement, then the / (forward slash) is required to run the statement, e.g.:

如果您在PL / SQL Developer中的一步中运行脚本,则可能需要将其转换为“SQL * Plus”脚本 - 即分号需要分隔语句,然后需要/(正斜杠)运行语句,例如:

CREATE TABLE temp_table as 
    SELECT * FROM table_x where x > 1;
/

INSERT INTO temp_table 
    SELECT * FROM table_y where x > 1;
/

#1


Put a semicolon at the end of each statement.

在每个语句的末尾加一个分号。

#2


Try this:

CREATE TABLE temp_table as
SELECT * FROM table_x;

INSERT INTO temp_table
SELECT * FROM table_y;

I think the parentheses were messing you up.

我认为括号让你搞砸了。

#3


The parenthesis can be used to specify the columns on which you want to insert the data as in:

括号可用于指定要在其中插入数据的列,如下所示:

INSERT INTO temp_table ( col1,col2,...coln) SELECT ...

INSERT INTO temp_table(col1,col2,... coln)SELECT ...

You get an error because instead of a list of columns, the parser finds a select expression between parenthesis

您会收到错误,因为解析器会在括号之间找到一个select表达式,而不是列列表

#4


If you're running the script in one step in PL/SQL Developer, you may need to convert it to a "SQL*Plus" script - i.e. the semicolons are required to delimit the statement, then the / (forward slash) is required to run the statement, e.g.:

如果您在PL / SQL Developer中的一步中运行脚本,则可能需要将其转换为“SQL * Plus”脚本 - 即分号需要分隔语句,然后需要/(正斜杠)运行语句,例如:

CREATE TABLE temp_table as 
    SELECT * FROM table_x where x > 1;
/

INSERT INTO temp_table 
    SELECT * FROM table_y where x > 1;
/