Variable substitution in Oracle's SQL statements

Source: Internet
Author: User
Tags chr

I. Description of the problem

The following sql:

INSERT  into TMP (val)VALUES('a&b');
View Code

The following prompts will appear during execution:

After clicking "OK", we look at the data in the table:

The string after B is not inserted.

Two. Reason Analysis-substitution variables

The default "&" in Sql*plus represents an alternative variable, and when writing &, the database requires it to be replaced with another value.

For example, you can define:

The value in this insert database is Ahellob.

Three. Workaround

Workaround 1: Turn off variable substitution

As shown below:

SET OFF ; INSERT  into TMP (val)VALUES('a&b'); COMMIT;
View Code

The value that is inserted in this way is a&b

Solution 2: Use the ASCII code of the & symbol Chr (38) to handle

string concatenation , as shown below:

INSERT  into TMP (val)VALUES('a'| | CHR| |  ' b ' ); COMMIT;
View Code

The string is translated as follows:

INSERT  into TMP (val)VALUES(Translate ('aiiib','III' , CHR)); COMMIT;
View Code

The string is replaced as follows:

INSERT  into TMP (val)VALUES(REPLACE('aiiib','III  ", CHR)); COMMIT;
View Code

Attached: ASCII code table

Baidu Encyclopedia: http://baike.baidu.com/view/15482.htm?fromid=99077

Variable substitution in Oracle's SQL statements

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.