Use the Oracle function to determine if the string contains Chinese __ static functions

Source: Internet
Author: User

We know that in the database, the Chinese character occupies two bytes, while the other characters occupy a byte, so the comparison of two functions can determine whether there is Chinese,

Length calculates character lengths, LENGTHB calculates byte lengths;

Select LENGTHB (' A Love China '), Length (' A Love China ') from dual;

The first one returns 7, and the second returns 4, which makes it possible to determine the Chinese language.

Another method using the ASCII method

oracle--Determine if the field is Chinese

On the internet to find a way to implement, try it is OK, the following statement can be found with Chinese characters in a field record
Oracle_sql Code SELECT * FROM A where ASCIISTR (a) Like '%\% ' and InStr (A, ' \ ') <= 0;

SELECT * from A where ASCIISTR (a) Like '%\% ' and InStr (A, ' \ ') <= 0;


Character function Asciistr function: Returns the ASCII code corresponding to the character, converting non-ASCII code to Unicode and preceding symbol ' \ '


The format of the InStr method is
INSTR (source string, target string, start position, match ordinal)

For example: INSTR (' CORPORATE FLOOR ', ' or ', 3, 2), the source string is ' CORPORATE FLOOR ', the target string is ' OR ', the starting position is 3, and the position of the 2nd match is taken.

The default lookup order is left to right. When the starting position is a negative number, start looking from the right.

So
Oracle_sql Code SELECT INSTR (' CORPORATE FLOOR ', ' OR ',-1, 1) "Instring" from DUAL

Select INSTR (' CORPORATE FLOOR ', ' OR ',-1, 1) "Instring" from DUAL


The display result is

Instring
——————
14

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.