1, Oracle special character escapes
keyword:oracle escape
Environment: Oracle9i plsql
Execute inside Plsql:
Update userinfo set pageurl= ' myjsp?page=1&pagesize=10 ' where id= ' test '
This SQL statement puts a URL address into the Pageurl field of the database, but does not perform as well, because there is an Oracle special character that needs to be escaped, which is the character ' & '. What does the
do with the special characters in the previous example?
Two ways:
1) Update userinfo setpageurl= ' myjsp?page=1 ' | | ' & ' | | ' pagesize=10 ' where id= ' test '
2 ' update userinfo setpageurl= ' Myjsp?page =1 ' | | Chr (38) | | pagesize=10 ' where id= ' Test '
where | | is a hyphen, Chr (38) is consistent with ASCII character transcoding. You can also set define off in
Plsql to turn off special characters, and you can use show define to see some special-defined characters.
2. How to escape special characters in Oracle
Q: How to escape the underscore _
SELECT * from ng_values where name like ' lady_% '
Jieguo results show lady_test,lady_test,lady1
The correct result should be: lady_test,lady_test
Not including lady1
Would you please give the escape method, 3ks
Answer
Select ... from ... where ... like '/_% ' escape '/';
3.
Insert into T (COL) VALUES (Chr (' & '));
(Method i)
Example: inserting special characters ' & '
Sql> SHOW DEFINE
Define "&" (Hex 26)? <---The default value of define is ' & '
sql> SET DEFINE OFF
Sql> SHOW DEFINE
Define OFF
Sql> INSERT into <table_name> VALUES (' t ');
/
1 row created
(Method Two)
Sql> SHOW ESCAPE
Escape off <---Escape's default value is OFF
Sql> SET ESCAPE on
Sql> SHOW ESCAPE
Escape "\" (Hex 5c)
Sql> INSERT into temp_table VALUES (' select * from emp where ename =\&1 ');
1 row created.
;
Several test methods:
SELECT ' myjsp?page=1&pagesize=10 ' from dual;
SELECT ' myjsp?page=1&pagesize=10 ' from dual;
Sql> CREATE Table A (b varchar2 (10));
Table created
Sql> INSERT into a values (' _a ');
1 row inserted
Sql> Select B from A where InStr (B, ' _a ') >0;
B
----------
_a
Select B from A where B like '%\_a% ' escape ' \ '
Start the escape character first
Set Escape on
Select B from A where B like '%\_a% ' escape ' \ ';
Select B from A where B like '%\_a% ' escape ' \ ';
Attention:
In Oracle, the double quote "is not an escape character, so the storage is stored directly, and it does not need to be escaped."
"Oracle" uses escape characters in Oracle