您可以使用login.sql来完成大多数操作。login.sql在登录期间执行-令人惊讶-在登录时从您的SQLPATH或当前目录加载。对于您给出的示例,您确实选择了最坏的情况。
问题是sqlterminator。无论您在其中放置什么,正斜杠都将保留为免费的sqlterminator。紧接着,sqlplus首先扫描sqlterminator,然后在扫描到字符串终止符之前执行此操作。如果您问我一个错误。只要不是单独出现在一行上,就可以在字符串中使用正斜杠。一旦sqlplus找到指定为sqlterminator的字符,它将忽略所有其他内容并停止读取。
只要不是一个斜线就可以处理正斜杠。
login.sql包含:
prompt run login.sql
show sqlterminator
show sqlblanklines
set sqlblanklines on
set sqlterminator ';'
show sqlterminator
show sqlblanklines
prompt ready login.sql
set echo on
leigh.sql包含:
INSERT INTO t1 VALUES ('fail bc semicolon
a;a
/
');
INSERT INTO t1 VALUES ('fail bc solo /
aa
/
');
INSERT INTO t1 VALUES ('ok / not solo
aa
/a
');
DELETE FROM t1 WHERE a = 'c
a/
';
运行脚本:
sqlplus leigh/leigh@orcl @leigh
SQL*Plus: Release 10.2.0.4.0 - Production on Thu Aug 9 22:36:20 2012
Copyright (c) 1982, 2007, Oracle. All Rights Reserved.
Connected to:
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
With the Partitioning, Real Application Clusters, Automatic Storage Management, OLAP,
Data Mining and Real Application Testing options
run login.sql
sqlterminator ";" (hex 3b)
sqlblanklines OFF
sqlterminator ";" (hex 3b)
sqlblanklines ON
ready login.sql
SQL> INSERT INTO t1 VALUES ('fail bc semicolon
2 a;a
3 /
ERROR:
ORA-01756: quoted string not properly terminated
SQL> ');
SP2-0042: unknown command "')" - rest of line ignored.
SQL>
SQL> INSERT INTO t1 VALUES ('fail bc solo /
2
3
4 aa
5 /
ERROR:
ORA-01756: quoted string not properly terminated
SQL> ');
SP2-0042: unknown command "')" - rest of line ignored.
SQL>
SQL> INSERT INTO t1 VALUES ('ok / not solo
2
3
4 aa
5 /a
6 ');
1 row created.
SQL>
SQL> DELETE FROM t1 WHERE a = 'c
2
3
4 a/
5 ';
0 rows deleted.
无需摆弄开始/结束块。无论命令在何处,无论在字符串中与否,都无法处理sqlterminator命令,不能在字符串中仅使用正斜杠的行进行处理。