oracle截取最后一个字符
简单明了实用,废话不多说:
select substr("a,",2,1) from dual;
substr("要截取的字符",字符的长度,字符长度-1)
延伸:
select substr(t.province,length(t.province),length(t.province)-1) from t_d_Sysnotice t where t.province is not null
=============================================================================================
【补充 2014-06-30 17:12:48】根据某个特定的字符截取,比如:“/”
数据库中的数据:/res/upload/interface/apptutorials/country/fb3749d1-0621-423d-95e5-095bfce417e5.png
目标结果:fb3749d1-0621-423d-95e5-095bfce417e5.png
即从最后一个"/"截取,取到图片的名称,原本的路径+名称
执行sql语句,得到原本的数据结果:
select p.countryname,p.countrypic from t_d_Country p where p.s_isdeleted = 0 order by nlssort(trim(p.countryname),"NLS_SORT=SCHINESE_PINYIN_M") asc
目标sql语句:
select p.countryname, substr(p.countrypic, length(p.countrypic) - instr(p.countrypic, "/",-1,1)+4, length(p.countrypic)) from t_d_Country p where p.s_isdeleted = 0;
关键的sql语句: substr(p.countrypic,
length(p.countrypic) - instr(p.countrypic, "/",-1,1)+4,
length(p.countrypic))
substr(“要截取的字符串”,"开始的位置",“截取的长度”)
select substr("abcdae", 1,1)from dual;
结果:a
select substr("abcdae", -1,1)from dual;
结果:e
oracle中的substr延伸:http://www.cnblogs.com/suding1188/archive/2012/05/25/2517901.html
instr(“字符串”,“字符”,“开始的位置”,“取的位置”)
select instr("abcdae","a",1,1) from dual;
结果:1
select instr("abcdae","a",1,2) from dual;
结果:5
select instr("abcdae","a",-1,1) from dual;
结果:5
oracle中instr延伸:http://blog.163.com/liu_yang1234/blog/static/2447431020112290109559/
【“开始的位置”为正数:顺着取;负数,倒着取】
- 上一篇: MySQL无法存储Emoji表情问题
- 下一篇: linux查看服务器【有效】连接数