Fuzzy query in Oracle SQL -- wildcards following like

Source: Internet
Author: User


1, %: represents any 0 or multiple characters. It can match any type and length of characters. In some cases, if it is Chinese, use two percent signs (%.

For example, SELECT * FROM [user] WHERE u_name LIKE '% 3%'

We will find all records with "3", such as "3 Zhang", "3 Zhang", "3 Zhang Mao", and "3 Tang sanzang.

In addition, if you need to find records with "three" and "cat" in u_name, use the and condition.
SELECT * FROM [user] WHERE u_name LIKE '% 3%' AND u_name LIKE '% cat %'

If SELECT * FROM [user] WHERE u_name LIKE '% 3% cat %' is used'
Although three-legged cats can be searched, three-legged cats cannot be searched ".

2, _: represents any single character. Matches any character. It is often used to limit the character length of an expression:

For example, SELECT * FROM [user] WHERE u_name LIKE '_ 3 _'
Only find that the u_name such as "Tang sanzang" is three characters and the middle word is "three;

For example, SELECT * FROM [user] WHERE u_name LIKE 'three __';
Find out that the name of the "three-legged cat" is three characters and the first word is "three;

-- Query records whose names start with 1 and end with 60 in FieldName and whose length is 7 characters
Select * from fzq where FieldName like '1 ____ 60 ';
Select * from fzq where regexp_like (FieldName, '1... 60 ');
-- Query records whose names start with 60 and end with 1 in FieldName and whose length is 7 bits and all are numbers.
-- Using like is not a good implementation.
Select * from fzq where regexp_like (FieldName, '1 [0-9] {4} 60 ');
-- The character set can also be used.
Select * from fzq where regexp_like (FieldName, '1 [[: digit:] {4} 60 ');
-- Query records in FieldName that are not pure numbers
Select * from fzq where not regexp_like (FieldName, '^ [[: digit:] + $ ');
-- Query records whose FieldName does not contain any numbers.
Select * from fzq where regexp_like (FieldName, '^ [^ [: digit:] + $ ');
-- Query records starting with 12 or 1b. The records are case insensitive.
Select * from fzq where regexp_like (FieldName, '^ 1 [2b]', 'I ');
-- Query records starting with 12 or 1b. case sensitive.
Select * from fzq where regexp_like (FieldName, '^ 1 [2B]');
-- The query data contains blank records.
Select * from fzq where regexp_like (FieldName, '[[: space:]');
-- Query all records that contain lowercase letters or numbers.
Select * from fzq where regexp_like (FieldName, '^ ([a-z] + | [0-9] +) $ ');
-- Query any records containing punctuation marks.
Select * from fzq where regexp_like (FieldName, '[[: punct:]');

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.