"Oracle" uses escape characters in Oracle

Source: Internet
Author: User
Tags chr

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.