Number of occurrences of the specified character in the SQL judgment field

Source: Internet
Author: User

Original address: The number of occurrences of a specified character in the SQL judgment field

Principle: Converts the specified character to null, the original length minus the converted length is the number of characters specified.

When doing data processing encountered a SQL operation problem is that there is a column of keywords field, the field contains a variety of messy characters, which has a double quotation mark "is not required in the keyword, so need to remove, and generally only with two" to remove, So first we have to find the double quotation marks and the double quotes two times, and then delete the values. This extracts the number of occurrences of the specified string in the field SQL is:

SELECT * FROM Google_keyword
where len (keyword)-len (replace (keyword, ' "', ')) =2


If you want to determine the number of occurrences of the specified string:

Select Count= (Len (field name)-len (replace (field name, ' Specify string ', '))/string length from TableName

Number of occurrences of the specified character in the SQL judgment field

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.