oracle的轉義字元需要用escape函式來定義,小小學習一下:
sql> create table t_char(a varchar2(20));
sql> insert into t_char values('a_b');
sql> insert into t_char values('acb');
sql> insert into t_char values('a%b');
sql> insert into t_char values('a''b');
sql> insert into t_char values('a/b');
sql> insert into t_char values('a\b');
sql> insert into t_char values('%');
sql> insert into t_char values('_');
sql> insert into t_char values('a');
sql> commit;
1.sql> select * from t_char; a
--------------------
a_b
acba%b
a'ba/b
a\b%
_a
2.sql> select * from t_char where a like'a_b'; a
--------------------
a_bacb
a%ba'b
a/ba\b
3.sql> select * from t_char where alike 'a\_b' escape '\'; a
--------------------
a_b
--可見要查詢含有通配字元的字串,必須要使用escape函式
4.sql> select * from t_char where a like 'a\'b' escape '\';
error:
ora-01756: quoted string not properly terminated
5.sql> select * from t_char where alike 'a''b' escape '\'; a
--------------------
a'b
--但是字元 ' 還是需要用兩個 '' 來代替字串中的單引號
6.sql> select * from t_char where alike 'ax_b' escape 'x'; a
--------------------
a_b
7.sql> select * from t_char where alike 'a''_b' escape ''''; a
--------------------
a_b
8.sql> select * from t_char where alike 'a_%b' escape '_'; a
--------------------
a%b
--可以用其他字元,甚至是「'」、「_」、「%」來用作轉義字元,但是一般都使用\,以免發生邏輯錯誤
9.sql> select * from t_char where a like 'a\/b' escape '\';
select * from t_char where a like 'a\/b' escape '\'
*error at line 1:
ora-01424: missing or illegal character following the escape character
10.sql> select * from t_char where a like 'a_/b' escape '_';
select * from t_char where a like 'a_/b' escape '_'
*error at line 1:
ora-01424: missing or illegal character following the escape character
11.sql> select * from t_char where a like 'a//b' escape '/'; a
--------------------
a/b
12.sql> select * from t_char where a like 'a/\b' escape '/';
select * from t_char where a like 'a/\b' escape '/'
*error at line 1:
ora-01424: missing or illegal character following the escape character
13.sql> select * from t_char where alike 'a\\b' escape '\'; a
--------------------
a\b
--要搜尋"/"或者"\"則必須使用與之相同的符號作為轉義字元,否則無效
基本上的使用方法就是這些了,還需要注意一點,這裡的escape函式,和sqlplus中的escape環境引數·毫·無·關·系·
oracle 預設轉義字元 Oracle轉義字元
1 oracle 特殊字元 轉義 在plsql裡邊執行 update userinfo set pageurl myjsp?page 1 pagesize 10 where id test 1 update userinfo set pageurl myjsp?page 1 pagesize 10 ...
oracle 預設轉義字元 oracle轉義字元
sql select from test where test like sdd escape test sdd kk 轉義字元為 sql select from test where test like sdd escape test sdd kk 轉義字元為 sql select from te...
oracle的轉義字元
xdoclet在hibernate中的用法總結 linux 刪除指定日期之前的檔案 oracle的轉義字元 2009 08 03 13 35 51 分類 sql 標籤 字型大小大 中小 訂閱 oracle的轉義字元需要用escape函式來定義,小小學習一下 sql create table t ch...