为什么 ORACLE 不允许命令中出现连续的换行符?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/796089/
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-18 18:08:18  来源:igfitidea点击:

Why doesn't ORACLE allow consecutive newline characters in commands?

sqloraclelanguage-designwhitespacesqlplus

提问by Matt Boehm

I write:

我写的:

  • :CREATE TABLE Person (
  • :name CHAR(10),
  • :
  • :ssn INTEGER);
  • :创建表人(
  • :name CHAR(10),
  • :ssn 整数);

and save it to a file "a.sql" (colon represents beginning of line, is not in actual code.)

并将其保存到文件“a.sql”中(冒号代表行首,实际代码中没有。)

If I then run it by typing "@a" in the SQL*Plus command prompt, it will tell me that the line starting with "ssn" is not recognized as a command, and is ignored.

如果我然后通过在 SQL*Plus 命令提示符下键入“@a”来运行它,它会告诉我以“ssn”开头的行未被识别为命令,并被忽略。

From what I gather, it seems that sqlplus terminates a command if it encounters multiple newline characters in a row. Is this an accurate statement? If so, does anyone know if this is necessary/ why it chooses to do this?

从我收集的信息来看,如果 sqlplus 在一行中遇到多个换行符,它似乎会终止命令。这是一个准确的说法吗?如果是这样,有没有人知道这是否有必要/为什么选择这样做?

回答by Thilo

I don't know about the why, but a completely blank line terminates a command in SQL*Plus.

我不知道为什么,但是完全空白的行会终止 SQL*Plus 中的命令。

Quote from the SQL*Plus docs:

引自SQL*Plus 文档

Ending a SQL Command: You can end a SQL command in one of three ways:

结束 SQL 命令:您可以通过以下三种方式之一结束 SQL 命令:

  • with a semicolon (;)
  • with a slash (/) on a line by itself
  • with a blank line
  • 带分号 (;)
  • 在一行上单独加一个斜杠 (/)
  • 有一个空行

You can also change how blank lines are treated with SET SQLBLANKLINES

您还可以使用 SET SQLBLANKLINES 更改处理空行的方式

SQLBL[ANKLINES] {ON|OFF}

Controls whether SQL*Plus allows blank lines within a SQL command or script. ON interprets blank lines and new lines as part of a SQL command or script. OFF, the default value, does not allow blank lines or new lines in a SQL command or script or script.

Enter the BLOCKTERMINATOR to stop SQL command entry without running the SQL command. Enter the SQLTERMINATOR character to stop SQL command entry and run the SQL statement.

SQLBL[ANKLINES] {ON|OFF}

控制 SQL*Plus 是否允许在 SQL 命令或脚本中使用空行。ON 将空行和新行解释为 SQL 命令或脚本的一部分。默认值 OFF 不允许在 SQL 命令或脚本或脚本中出现空行或新行。

输入 BLOCKTERMINATOR 停止 SQL 命令输入而不运行 SQL 命令。输入 SQLTERMINATOR 字符以停止 SQL 命令输入并运行 SQL 语句。

回答by Gary Myers

By default, SQLPlus does terminate (but not execute) a statement when a blank line is entered. It has always done this. It probably seemed like a good idea in the days before screen editors and query tools.

默认情况下,当输入空行时,SQLPlus 会终止(但不执行)语句。它一直这样做。在屏幕编辑器和查询工具出现之前的日子里,这似乎是一个好主意。

You can change that default behaviour with

您可以更改默认行为

set SQLBLANKLINES on

将 SQLBLANKLINES 设置为

In which case you'd have to enter a line with just a full stop to terminate (but not execute) a statement.

在这种情况下,您必须输入一个只有句号的行才能终止(但不执行)语句。

回答by Abhijit Singh

But if you are wanting to insert multiline text in a varchar2 or a clob field, you may use chr(10)

但是如果你想在 varchar2 或 clob 字段中插入多行文本,你可以使用 chr(10)

 insert into t values ('Hello,'||chr(10)||chr(10)||' How are you?');

 insert into t values (
 'Hello,

 How are you');   

will not work for reasons explained above.

由于上述原因将不起作用。