Oracle SQL 劈开字符串
一、数据样例

二、劈开单行
SELECT id_,REGEXP_SUBSTR(name_, '[^,]+', 1, rownum) h2
FROM (select id_,name_ from test_reg_count t
where t.id_ =2 )
CONNECT BY level <= length(name_)-length(replace(name_,',',''))+1; --或者
SELECT id_,REGEXP_SUBSTR(name_, '[^,]+', 1, rownum) h2
FROM (select id_,name_ from test_reg_count t
where t.id_ =2 )
CONNECT BY REGEXP_SUBSTR(name_, '[^,]+', 1, rownum) is not null;

三、劈开多行
SELECT id_,REGEXP_SUBSTR(name_, '[^,]+', 1, level) name_
FROM test_reg_count
CONNECT BY level <= length(name_)-length(replace(name_,',',''))+1
AND name_ = PRIOR name_
AND PRIOR dbms_random.value <1; --或者
SELECT id_,REGEXP_SUBSTR(name_, '[^,]+', 1, level) name_
FROM test_reg_count
CONNECT BY level <= length(name_)-length(replace(name_,',',''))+1
AND name_ = PRIOR name_
AND PRIOR SYS_GUID() is not null;

这里最重要的是 prior操作符,关于prior的解释Oracle的官方文档是这么描述的:
In a hierarchical query, one expression in the CONNECT BY condition must be qualified by the PRIOR operator. If the CONNECT BY condition is compound, then only one condition requires the PRIOR operator, although you can have multiple PRIOR conditions. PRIOR evaluates the immediately following expression for the parent row of the current row in a hierarchical query.
PRIOR is most commonly used when comparing column values with the equality operator. (The PRIOR keyword can be on either side of the operator.) PRIOR causes Oracle to use the value of the parent row in the column. Operators other than the equal sign (=) are theoretically possible in CONNECT BY clauses. However, the conditions created by these other operators can result in an infinite loop through the possible combinations. In this case Oracle detects the loop at run time and returns an error.
Oracle SQL 劈开字符串的更多相关文章
- Oracle sql 子字符串长度判断
Oracle sql 子字符串长度判断 select t.* from d_table t ,) ,instr(t.col,; 字符串的前两位都是数字: select * from d_table t ...
- Oracle SQL判断字符串是否在目标字符串中的函数
转自:http://dacoolbaby.iteye.com/blog/1772156 根据需求,写了一段方法. 用于识别以下的情况: 判断 字符串A 在用逗号分隔的字符串B中是否存在 如: v_s ...
- 处理 Oracle SQL in 超过1000 的解决方案
处理oracle sql 语句in子句中(where id in (1, 2, ..., 1000, 1001)),如果子句中超过1000项就会报错.这主要是oracle考虑性能问题做的限制.如果要解 ...
- Oracle SQL 优化原则(实用篇)
由于SQL优化优化起来比较复杂,并且还受环境限制,在开发过程中,写SQL必须遵循以下几点原则: 1.Oracle 采用自下而上的顺序解析WHERE子句,根据这个原理,表之间的连接必须写在其他Where ...
- [Oracle] SQL*Loader 详细使用教程(2)- 命令行参数
sqlldr工具 SQL*Loader的客户端工具是sqlldr,在操作系统的命令行下输入sqlldr,后面不接任何参数,将显示帮助信息如下所示(所有命令行参数的简单描述及其默认值),所以你并不需 ...
- oracle sql日期比较
oracle sql日期比较:在今天之前: select * from up_date where update < to_date('2007-09-07 00:00:00','yyyy-mm ...
- oracle中一个字符串包含另一个字符串中的所有字符
oracle中一个字符串包含另一个字符串中的所有字符 --解决监理报告中所勾选的标段信息,与该用户所管理的标段字符串不匹配的问题. select * from a where instr(a,b)&g ...
- oracle 插入含&字符串
1.创建表 SQL> create table t(id number,name varchar2(20)); 表已创建. 2.常规方式插入 SQL> insert into t valu ...
- Oracle SQL in 超过1000 的解决方案
处理 Oracle SQL in 超过1000 的解决方案 处理oracle sql 语句in子句中(where id in (1, 2, ..., 1000, 1001)),如果子句中超过1000项 ...
随机推荐
- PreparedStatement和Statement的区别
转自:http://blog.sina.com.cn/s/blog_77eba18f01019csh.html 1. PreparedStatement接口继承Statement, PreparedS ...
- Python中的字符串处理
Python转义字符 在需要在字符中使用特殊字符时,python用反斜杠(\)转义字符.如下表: 转义字符 描述 \(在行尾时) 续行符 \\ 反斜杠符号 \' 单引号 \" 双引号 \a ...
- CF 118E Bertown roads 桥
118E Bertown roads 题目:把无向图指定边的方向,使得原图变成有向图,问能否任意两点之间互达 分析:显然如果没有桥的话,存在满足题意的方案.输出答案时任意从一个点出发遍历一遍即可. 求 ...
- spring(三)----大概是最简单的面向切面了
面向切面编程,是spring的一大特点,可以说是spring最独特的特点了(个人认为). 记得当初学习面向切面编程的时候,可能是面向对象思想根深蒂固了,怎么也理解不了什么叫面向切面... 其实对于面向 ...
- 关于使用AIDL出现空指针的解决办法
使用AIDL进行远程调用的时候出现的空指针异常,解决过程稍微有点小曲折.具体安下 1.先贴异常信息 ERROR/AndroidRuntime(9435): FATAL EXCEPTION: main ...
- sql 计算两时间或日期 的相差的 年、 月、 日、时、分、秒,年、月、日分别的提取
--年.月.日.时.分.秒 datediff(yy,date1,date2) datediff(m,date1,date2) datediff(d,date1,date2) datediff(hh,d ...
- 编程Tips
三元运算符 Vb中的iif(expr,truepart,falsepart)和C#中的expr?truepart:falsepart. 无论expr的结果是true还是false,true/false ...
- ThinkPHP控制器
ThinkPHP控制器Controller 1.什么是控制器 在MVC框架中,其核心就是C(Controller)控制器.主要用于接收用户请求,处理业务逻辑. 2.控制器的定义 在一个ThinkPHP ...
- 济南学习 Day2 T2 am
[问题描述]有N个数,随机选择一段区间,如果这段区间的所有数的平均值在[l,r]中则你比较厉害.求你比较厉害的概率.[输入格式]第一行有三个数N,l,r,含义如上描述.接下来一行有
- 内核中读取UTC时间
记录这个知识点的原因是因为项目中需要保存充电日志,因此,趁着这个机会,深入了解一下Linux的时间系统. UTC:(Universal Time Coordinated) 协调世界时的缩写 ...