当前位置:数据库 > DB2 >>

db2递归截取字符串

 with n(str, ori, pos) as (
values ('aa,bb,cc,dd,', 1, posstr('aa,bb,cc,dd,', ','))
union all
select str, pos+1, locate(',', str, pos+1)
from n
where locate(',', str, pos+1)>0)
select str, ori, pos, substr(str, ori, pos-ori) as result from n order by pos desc fetch first 1 rows only;
//其实我只是要取一个字符串中用','分割的最后一段。。。 
 

Oracle
MySQL
Access
SQLServer
DB2
Excel
SQLite
SYBASE
Postgres
如果你遇到数据库难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,