ORACLE PL-SQL如何使用功能分割字符串并返回列表 [英] ORACLE PL-SQL How to SPLIT a string and RETURN the list using a Function

查看:311
本文介绍了ORACLE PL-SQL如何使用功能分割字符串并返回列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何为给定的分隔符拆分给定的字符串.

How to Split the given String for the given Delimiter.

例如:

字符串=>'1,2,3,4,5' 分隔符=>','

String => '1,2,3,4,5' Delimiter => ','

1 2个 3 4 5

1 2 3 4 5

推荐答案

这是怎么回事?正则表达式也允许使用null列表元素.

What about this? The regular expression allows for null list elements too.

SQL> with tbl(str) as (
  2    select '1,2,,4,5' from dual
  3  )
  4  select regexp_substr(str, '(.*?)(,|$)', 1, level, null, 1) element
  5  from tbl
  6  connect by level <= regexp_count(str, ',')+1;

ELEMENT
--------
1
2

4
5

SQL>

有关返回列表元素的函数,请参见此帖子:

See this post for a function that returns a list element: REGEX to select nth value from a list, allowing for nulls

这篇关于ORACLE PL-SQL如何使用功能分割字符串并返回列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆