Oracle函数,按分隔符截取字符串 [问题点数
2016-01-29 10:49
501 查看
今天因工作需要,写了一个小函数,按分隔符截取字符串的,分享出来,希望有需要的朋友能用到。
功能实例: substrbysep('aaa,bb,ccccc,ddd,vvv',',',3)返回结果 'ccccc'.
函数:
create or replace function substrbysep(sourceString varchar2,
destString varchar2,
appearPosition number)
return varchar2 is
substring varchar2(255);
--作者:Alex Liu
--功能:按分隔符截取字符串
--参数:1、原始字符串;2、分隔符;3、截取第几段
begin
substring := substr(destString || sourceString || destString,
instr(destString || sourceString || destString,
destString,
1,
appearPosition) + 1,
instr(destString || sourceString || destString,
destString,
1,
appearPosition + 1) -
instr(destString || sourceString || destString,
destString,
1,
appearPosition) - 1);
return(substring);
end substrbysep;
/
另外一种方法正则表达式
SQL code
用正则表达式,一步就出来了
select regexp_substr('aaa,bb,ccccc,ddd,vvv','[^,]+',1,3)
from dual
;
REGEX
-----
ccccc
功能实例: substrbysep('aaa,bb,ccccc,ddd,vvv',',',3)返回结果 'ccccc'.
函数:
create or replace function substrbysep(sourceString varchar2,
destString varchar2,
appearPosition number)
return varchar2 is
substring varchar2(255);
--作者:Alex Liu
--功能:按分隔符截取字符串
--参数:1、原始字符串;2、分隔符;3、截取第几段
begin
substring := substr(destString || sourceString || destString,
instr(destString || sourceString || destString,
destString,
1,
appearPosition) + 1,
instr(destString || sourceString || destString,
destString,
1,
appearPosition + 1) -
instr(destString || sourceString || destString,
destString,
1,
appearPosition) - 1);
return(substring);
end substrbysep;
/
另外一种方法正则表达式
SQL code
用正则表达式,一步就出来了
select regexp_substr('aaa,bb,ccccc,ddd,vvv','[^,]+',1,3)
from dual
;
REGEX
-----
ccccc
相关文章推荐
- ORACLE进程占用CPU情况分析
- oracle-审计导数
- oracle 表空间和表 read…
- oracle 表迁移方法 (一)
- oracle 表迁移方法 (二…
- Oracle 将普通表转换为分区表
- Oracle表结构转换SqlSERVER表结构&…
- Oracle redo 日志切换时间频率
- Oracle private dblink…
- Oracle DBLINK 抽数以及…
- Oracle数据迁移至MySQL
- ORACLE RAC crs 无法启动
- Oracle11g Install Bbed
- oracle 临时表空间
- oracle 谁在用undo
- oracle11g 数据文件误删恢复(…
- oracle11g rman验证备份有效性
- oracle11g 重新配置em
- oracle 约束
- oracle 11g 表空间使用率