The content (string reversal) after the last occurrence of a symbol in SQL Server by reverse _mssql

Source: Internet
Author: User
SQL statement
Copy Code code as follows:

Reverse (substring reverse (path), 1,charindex ('/', reverse (path))-1)


How SQL takes out the character to the right of the last special character in a string, for example: 10*20*300, how do I get 300?

Use reverse with charindex to achieve.

Reverse is to invert the string, and then through the charindex to get the position of the first * after the inversion, and then use the SUBSTRING function to intercept the string, intercept and then use reverse inverted back.
Here is an example
DECLARE @str varchar (20)
Set @str = ' 10*20*300 '
Select reverse (substring (reverse (@str), 1,charindex (' * ', reverse (@str))-1)
The result is 300.
The above is SQL Server syntax.
Oracle database also has reverse functions, but substring to change to substr,charindex function to InStr function
SELECT Reverse (substr (reverse (' 10*20*300 '), 1,instr (reverse (' 10*20*300 '), ' * ')-1)) from DUAL;
The result is 300.
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.