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

发布于 2024-07-18 06:57:13 字数 278 浏览 8 评论 0原文

我写:

CREATE TABLE Person ( 
name CHAR(10),

ssn INTEGER);

并将其保存到文件“a.sql”中。

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

据我所知,如果 sqlplus 在一行中遇到多个换行符,它似乎会终止命令。 这是一个准确的说法吗? 如果是这样,有谁知道这是否有必要/为什么选择这样做?

I write:

CREATE TABLE Person ( 
name CHAR(10),

ssn INTEGER);

and save it to a file "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.

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

软糖 2024-07-25 06:57:13

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

引自SQL*Plus 文档

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

  • 使用分号 (;)
  • 在一行上使用斜杠 (/)
  • 使用空行

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

SQLBL[ANKLINES] {ON|OFF}

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

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

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

Quote from the SQL*Plus docs :

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

  • 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

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.

随波逐流 2024-07-25 06:57:13

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

更改默认行为,

您可以使用set SQLBLANKLINES on

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

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.

You can change that default behaviour with

set SQLBLANKLINES on

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

浅笑轻吟梦一曲 2024-07-25 06:57:13

但是如果您想在 varchar2 或 clob 字段中插入多行文本,您可以使用
由于上述原因, chr(10)

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

 insert into t values (
 'Hello,

 How are you');   

将不起作用。

But if you are wanting to insert multiline text in a varchar2 or a clob field, you may use
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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文