Collation of numbers and Chinese characters in oracle and introduction to REGEXP_SUBSTR, oracleregexpsubstr

Source: Internet
Author: User

Collation of numbers and Chinese characters in oracle and introduction to REGEXP_SUBSTR, oracleregexpsubstr

Requirement: There is a column NAME, varchar2 type, the content is as follows

The preceding statements are sorted by order by name, but they are not the expected results.

Now you only need to sort by number


Step 1: extract numbers
It is difficult to use substr to intercept a number that is one digit and two digits.

We can useREGEXP_SUBSTRFunction that uses regular expressions to extract substrings from strings.

REGEXP_SUBSTR (name, '[0-9] + ')

Step 2: convert a number of the varchar type to a number of the int type

Cast (yourcol as int)
For details, refer to: Convert the varchar type to the int type in SQL and then sort it.


So combine

Select * from test order by cast (REGEXP_SUBSTR (name, '[0-9] +') as int );
You can sort by number.



Author: itmyhome


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.