SQL statement
Copy codeThe Code is as follows: reverse (substring (reverse (Path), 1, charindex ('/', reverse (Path)-1 ))
How can I retrieve the right character of the last special character in a string, for example, 10*20*300? How can I get 300?
Use reverse with charindex.
Reverse is to put the string upside down, and then use charindex to obtain the first * position after the inversion, then use the substring function to intercept the string, and then use the reverse to put it back.
The following is an example
Declare @ str varchar (20)
Set @ str = '10*20*300'
Select reverse (substring (reverse (@ str), 1, charindex ('*', reverse (@ str)-1 ))
Result 300
The above is the SQL Server syntax.
The ORACLE database also has the REVERSE function, but the SUBSTRING should be changed to SUBSTR, And the CHARINDEX function should be changed to the INSTR function.
SELECT reverse (substr (reverse ('10*20*300 '), 1, INSTR (reverse ('10*20*300'), '*')-1 )) from dual;
Result 300