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项 ...
随机推荐
- 【阿里云产品公测】消息队列服务MQS java SDK 机器人应用初体验
[阿里云产品公测]消息队列服务MQS java SDK 机器人应用初体验 作者:阿里云用户啊里新人 初体验 之 测评环境 由于MQS支持外网访问,因此我在本地做了一些简单测试(可能有些业余),之后 ...
- 【开源项目4】Android ExpandableListView
如果你对Android提供的Android ExpandableListView并不满意,一心想要实现诸如Spotify应用那般的效果,那么SlideExpandableListView绝对是你最好的 ...
- Android学习笔记⑤——UI组件的学习TextView相关
TextView是一个强大的视图组件,直接继承了View,同时也派生出了很多子类,TextView其作用说白了就是在布局中显示文本,有点像Swing编程中的JLabel标签,但是他比JLabel强大的 ...
- Unslider--使用手册系列(一)
Unslider--入门篇 背景:因工作需求,需要完成一个图片轮播效果,因博主不是专业的前端开发人员,so google之,经过挑选最终选择使用Unslider插件完成工作. 一.Unslider插件 ...
- IE兼容性问题列表及解决办法
目录 概述 2 第一章:HTML 3 第一节:IE7-IE8更新 31. 如果缺少结束标记的 P 元素后跟 TABLE.FORM.NOFRAMES 或 NOSCRIPT 元素,会自动添加结束标记. 3 ...
- jQuery选择器之表单对象属性过滤选择器Demo
测试代码: 08-表单对象属性过滤选择器.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...
- Entityframework Code First 系列之项目搭建
Entityframework(以下简称EF)是微软推出的一个ORM(Object Relational Mapping)框架. 优缺点 优点: 易上手,语法简单,查询容易 更新快,不断补足 缺点: ...
- 关于div 浮动在select,或table控件之上
<div style="position:absolute; display:none; z-index:99999" id="d3" onmouseov ...
- CSS之全屏背景图
吐槽啦:Yeah 明天就是国庆了o(* ̄▽ ̄*)o!哈哈,提前祝福各位园友国庆快乐.假期愉快.生活美满.天天开心!国庆我要回家一趟,把一些不用的东西带回家,走访一下亲朋好友,在家打几天酱油~~~ 言 ...
- java 获取数组(二维数组)长度实例程序
我们可能知道 js有个length函数,java也有啊length函数 例 如果数组是data[],则data.length 代码如下 复制代码 byte[] phone =new byte[81]; ...