Special Character Processing in oracle

Source: Internet
Author: User


Oracle Special Character Processing if you have a project or product that supports fuzzy search, we recommend that you perform a test: Enter "_" in the search box (underline) or "%" (percentage), and then search to see what results will be obtained. Www.2cto.com, although you may not realize why. If your search results show many results that do not contain any "_" or "%" at all, it means that you have never considered this problem like me, this is exactly the problem to be solved in this article. In fact, this question is also simple, because most of our searches are SQL-based, and most people should know about fuzzy search, that is, LIKE % XX %, where % represents a string of any length, this is similar to the common wildcard. In addition to "%", there is also a wildcard that many people may not know: "_". Its role is similar to the common wildcard "?". The function is similar. For the above reason, if you do not do anything, it is impossible to directly search for keywords containing two special characters to get the correct result. For example, if you enter % or _ to search, all result sets are obtained. Is there no way to search for such special characters? Of course there are some methods, that is, using the little-known keyword 'escape '. For example, you can use the following statement: SQL code 1. select * from demo_table where keyword like '^ %' escape '^'; here '^' is a common character, but after escape, it becomes an escape character, the % after it is escaped as a normal character. In this way, you can query special characters. Some people may say that I have never considered this problem, but my system can query it normally. Why? This is because the background system you are dependent on has been taken into consideration for you. For example, the criteria of hibernate has made a special encapsulation for this. If you are interested, you can see how the LikeExpression class handles it. If you are not using hibernate, you need to handle the problem yourself.

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.