全部博文(136)
分类: Oracle
2009-04-23 19:29:26
SQL> select * from v$version;
BANNER
----------------------------------------------------------------
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production SQL> select substr('asdf&yuechaotian', 1, 1) from dual;
输入 yuechaotian 的值:
原值 1: select substr('asdf&yuechaotian', 1, 1) from dual
新值 1: select substr('asdf', 1, 1) from dual
S
-
a |
SQL> select substr('asdf&yuechaotian', 5, 1) from dual;
输入 yuechaotian 的值:
原值 1: select substr('asdf&yuechaotian', 5, 1) from dual
新值 1: select substr('asdf', 5, 1) from dual
S
-
|
-- 默认情况下,escape是关闭的
SQL> show escape
escape OFF
-- 打开escape,默认使用'\'作为转义字符
SQL> set escape on
SQL> show escape
escape "\" (hex 5c)
-- 此时使用'\'将字符'&'转义
SQL> select substr('asdf\&yuechaotian', 1, 1) from dual;
S
-
a
-- 转义字符只是用来转义,本身是不占字符位置的
SQL> select substr('asdf\&yuechaotian', 5, 1) from dual;
S
-
& |
-- 此时第一个'\'将第二个'\'转义,&表示后面的子串yuechaotian是变量,不输入任何值,得到子串'asdf\'
SQL> select substr('asdf\\&yuechaotian', 5, 1) from dual;
输入 yuechaotian 的值:
原值 1: select substr('asdf\\&yuechaotian', 5, 1) from dual
新值 1: select substr('asdf\', 5, 1) from dual
S
-
\
-- 此时第一个'\'将第二个'\'转义,第三个'\'将'&'转义,得到子串'asdf\&yuechaotian'
SQL> select substr('asdf\\\&yuechaotian', 5, 1) from dual;
S
-
\
SQL> select substr('asdf\\\&yuechaotian', 5) from dual;
SUBSTR('ASDF\
-------------
\&yuechaotian |
SQL> set escape #
SQL> show escape
escape "#" (hex 23)
SQL> select substr('asdf\\\#&yuechaotian', 5) from dual;
SUBSTR('ASDF\\\
---------------
\\\&yuechaotian |