How to extract Chinese character strings from Oracle

Source: Internet
Author: User

How to extract Chinese character strings from Oracle

In actual work, we often need to use the function of removing special characters, especially the data inserted into the database. To ensure the data quality, we often need to clean the data, that is, remove special characters, the solution is to determine whether each character in the string is Chinese. If it is Chinese, connect them in order. If not, do not.

Based on actual business needs, there are two solutions:

Solution 1:

Use the database's built-in function length and lengthb.

In Chinese, length returns the number of characters, Chinese occupies 1 character, lengthb returns the number of bytes, and Chinese occupies 2 bytes. This can be solved based on Chinese features, but the actual situation is often not ideal, there are often some special characters, which are consistent with the number of Chinese characters and the number of Chinese characters, so we cannot accurately judge the Chinese characters in the database. To solve this problem, solution 2 is recommended.

Solution 2:

Use ASCII codes to distinguish Chinese characters from other characters. The value range of Chinese ASCII codes is 45217 ~ 63486. Based on this implementation, we need to use the Oracle function ASCII to return the ASCII value.

This method perfectly distinguishes Chinese characters from other characters.

Create or replace function getCustText (custName varchar2) return varchar2 is
Result varchar2 (100 );
Tmp_custName varchar2 (100 );
Count_str number;
I number: = 1;
Str_ascii number;
Current_char varchar2 (10 );
Begin
Select length (custName) into count_str from dual;
While I <count_str loop
Current_char: = substr (custName, I, 1 );
Select ASCII (current_char) into str_ascii from dual;
If str_ascii> 45216 then
Tmp_custName: = tmp_custName | current_char;
End if;
I: = I + 1;
End loop;
Result: = tmp_custName;
Return (Result );
End getCustText;

The above is an implementation method in Oracle, which can quickly and accurately recognize Chinese characters.

Install Oracle 11gR2 (x64) in CentOS 6.4)

Steps for installing Oracle 11gR2 in vmwarevm

Install Oracle 11g XE R2 In Debian

Install Oracle 11.2.0.4 x64 in Oracle Linux 6.5

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.