oracle SQL*Plus 不执行 SQL Developer 执行的 SQL 脚本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10406810/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 00:46:25  来源:igfitidea点击:

SQL*Plus does not execute SQL scripts that SQL Developer does

sqloracleoracle11gsqlplusoracle-sqldeveloper

提问by rapt

I am facing a very annoying problem. I have written (in Notepad++) some SQL scripts. Now when I try to execute them by SQL*Plus (through the command line, on Windows 7), I am getting errors like ORA-00933: SQL command not properly ended.

我正面临一个非常烦人的问题。我已经(在 Notepad++ 中)编写了一些 SQL 脚本。现在,当我尝试通过 SQL*Plus(通过命令行,在 Windows 7 上)执行它们时,我收到类似ORA-00933: SQL command not properly ended.

Then I copy & paste the script into the SQL Developer worksheet window, hit the Run button, and the script executes without any problem/errors.

然后我将脚本复制并粘贴到 SQL Developer 工作表窗口中,点击“运行”按钮,脚本就会执行而没有任何问题/错误。

After a long investigation, I came to think that SQL*Plus has a problem with some whitespaces (including newline characters and tabs) that it does not understand.

经过长时间的调查,我开始认为 SQL*Plus 存在一些它不理解的空格(包括换行符和制表符)的问题。

Since I assume that SQL Developer knows how to get rid of the weird whitespaces, I have tried this: paste the script into the SQL Developer worksheet window, then copy it from there and paste it back in the SQL script. That solved the problem for some files, but not all the files. Some files keep showing errors in places for no apparent reason.

因为我假设 SQL Developer 知道如何去除奇怪的空格,所以我尝试了这个:将脚本粘贴到 SQL Developer 工作表窗口中,然后从那里复制并粘贴回 SQL 脚本中。这解决了某些文件的问题,但不是所有文件的问题。某些文件无缘无故地不断在某些地方显示错误。

Have you ever had this problem? What should I do to be able to run these scripts by SQL*Plus through the command line?

你有没有遇到过这个问题?我应该怎么做才能通过命令行由 SQL*Plus 运行这些脚本?

UPDATE:

更新:

An example of a script that did not work with SQL*Plus but did work with SQL Developer:

一个不能用于 SQL*Plus 但可以用于 SQL Developer 的脚本示例:

SET ECHO ON;

INSERT INTO MYDB.BOOK_TYPE (
    BOOK_TYPE_ID, UNIQUE_NAME, DESCRIPTION, VERSION, IS_ACTIVE, DATE_CREATED, DATE_MODIFIED
)
SELECT MYDB.SEQ_BOOK_TYPE_ID.NEXTVAL, 'Book-Type-' || MYDB.SEQ_BOOK_TYPE_ID.NEXTVAL, 'Description-' || MYDB.SEQ_BOOK_TYPE_ID.NEXTVAL, A.VERSION, B.IS_ACTIVE, SYSDATE, SYSDATE FROM

    (SELECT (LEVEL-1)+0 VERSION FROM DUAL CONNECT BY LEVEL<=10) A,
    (SELECT (LEVEL-1)+0 IS_ACTIVE FROM DUAL CONNECT BY LEVEL<=2) B

;

The error I get:

我得到的错误:

SQL> SQL> SET ECHO ON;
SQL>
SQL> INSERT INTO MYDB.BOOK_TYPE (
  2      BOOK_TYPE_ID, UNIQUE_NAME, DESCRIPTION, VERSION, IS_ACTIVE, DATE_CREATED, DATE_MODIFIED
  3  )
  4  SELECT MYDB.SEQ_BOOK_TYPE_ID.NEXTVAL, 'Book-Type-' || MYDB.SEQ_BOOK_TYPE_ID.NEXTVAL, 'Description-' || MYDB.SEQ_BOOK_TYPE_ID.NEXTVAL, A.VERSION, B.IS_ACTIVE, SYSDATE, SYSDATE FROM
  5  
SQL>         (SELECT (LEVEL-1)+0 VERSION FROM DUAL CONNECT BY LEVEL<=10) A,
  2          (SELECT (LEVEL-1)+0 IS_ACTIVE FROM DUAL CONNECT BY LEVEL<=2) B
  3  
SQL> ;
  1     (SELECT (LEVEL-1)+0 VERSION FROM DUAL CONNECT BY LEVEL<=10) A,
  2*    (SELECT (LEVEL-1)+0 IS_ACTIVE FROM DUAL CONNECT BY LEVEL<=2) B

As you see the error is on (SELECT (LEVEL-1)+0 IS_ACTIVE FROM DUAL CONNECT BY LEVEL<=2) B(for some reason in all the files that get this error, the error appears on the last line before the concluding semicolon.)

如您所见,错误已打开(SELECT (LEVEL-1)+0 IS_ACTIVE FROM DUAL CONNECT BY LEVEL<=2) B(出于某种原因,在所有出现此错误的文件中,错误出现在结束分号之前的最后一行。)

回答by A.B.Cade

Remove the empty lines.
In sqlplus an empty line means stop previous statement and start a new one.

删除空行。
在 sqlplus 中,空行表示停止上一条语句并开始新的语句。

or you can set blank lines:

或者您可以设置空行:

set sqlbl on

回答by Gerard Reid

Alternatively you can use "Ctrl F7" in sqldeveloper to format your script. I had a similar issue and tried removing blanks etc. but I was obviously missing something. Found the Ctrl F7 function and the script worked.

或者,您可以在 sqldeveloper 中使用“Ctrl F7”来格式化您的脚本。我有一个类似的问题,并尝试删除空白等,但我显然错过了一些东西。找到 Ctrl F7 功能并且脚本有效。