Oracle intercepts the last character ____oracle

Source: Internet
Author: User

Simple and practical, not much nonsense said:


[SQL] view plain copy Select Substr (' A, ', 2,1) from dual;
substr (' character to intercept ', length of character, character length-1)


Extended:

[SQL] view plain copy Select substr (T.province,length (t.province), Length (t.province)-1) from T_d_sysnotice t Where t.province is not null


=============================================================================================

"Add 2014-06-30 17:12:48" to intercept according to a particular character, such as: "/"

Data in the database:/res/upload/interface/apptutorials/country/fb3749d1-0621-423d-95e5-095bfce417e5.png

Target Result: fb3749d1-0621-423d-95e5-095bfce417e5.png

That is, from the last "/" intercept, take the name of the picture, the original path + name


Execute the SQL statement to get the original data result:

[SQL] view plain copy select P.countryname,p.countrypic from T_d_country p where p.s_isdeleted = 0 ORDER by NLS Sort (Trim (p.countryname), ' Nls_sort=schinese_pinyin_m ') ASC



Target SQL statement:

[SQL] view plain copy Select P.countryname, substr (p.countrypic, Length (p.countrypic)-ins TR (p.countrypic, '/', -1,1) +4, Length (p.countrypic)) from T_d_country p here p.s_isdeleted = 0;




Key SQL statement: substr (P.countrypic,
Length (P.countrypic)-InStr (P.countrypic, '/', -1,1) +4,
Length (P.countrypic))


SUBSTR ("String to intercept", "Start position","length of interception")

Select substr (' Abcdae ', 1,1) from dual;

Result: A


Select substr (' Abcdae ', -1,1) from dual;

Result: E


SUBSTR Extensions in Oracle: http://www.cnblogs.com/suding1188/archive/2012/05/25/2517901.html


InStr ("string", "character", "Start position", "position taken")

Select InStr (' Abcdae ', ' a ', 1,1) from dual;

Results: 1


Select InStr (' Abcdae ', ' a ', 1,2) from dual;

Results: 5


Select InStr (' Abcdae ', ' a ', -1,1) from dual;

Results: 5


Oracle InStr Extension: http://blog.163.com/liu_yang1234/blog/static/2447431020112290109559/


"Start position" is a positive number: Follow the take, negative, reverse.

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.