Interception of special characters in SQL statements

Source: Internet
Author: User

These two days in the project encountered a problem, the data stored in the database and the user would like to display some inconsistent data, but the data deposited is correct. In this case, we need to do some processing when displaying the data. The problem is handled in the project by using a data dictionary to format the data when it is displayed. My problem is because the workflow is increased, so the data dictionary does not work and can only be processed in advance. The final choice is to process the data when the SQL statement is used.

First look at the data format stored in the database, company name + "*" + subkey name, as follows:

The data information that the user needs to display is just the name of the child behind, so we only need to intercept the "*" and the previous characters. You can use the following function to intercept special characters in sql:

SUBSTR (Subitem,instr (Subitem, ' * ', 1) +1)
Among them, the SUBSTR function and the InStr function are used.

1, substr (String,start_position,[length]) substring, return string

The first parameter represents the string to intercept, the second represents the starting position, and the third represents the length of the interception, which can be omitted.

2, InStr (string,substring,position,ocurrence) Find the location of the string

The first parameter represents the source string, the second is the character to look for, the third is the starting position to look for, and the fourth is the number of characters to find.

This way, after we have processed the data in the background, the data displayed in the foreground is as follows:

Summary:

There are other ways to handle the data, choose the right way, or get a temporary approach and then refine it. Through this study, the application of SQL statements has added a new understanding. Of course, there are still many places to learn and progress, and continue to fighting.

Interception of special characters in SQL statements

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.