库表结构如下:create table demotab(oid number, namelist varchar2(5000));
里面数据格式如下:
oid|namelist
1|a,b,c
2|d,e,f
...许多行============================
希望写一个函数,能返回以下两列oid, name
1, a
1, b
1, c
2, d
2, e
2, f
...许多行
===========================
不知道是否可行,网上有一个split函数(http://www.cnblogs.com/linbaoji/archive/2009/09/17/1568252.html),只能处理固定的字符串,而且只能返回一列
无法两列多行
里面数据格式如下:
oid|namelist
1|a,b,c
2|d,e,f
...许多行============================
希望写一个函数,能返回以下两列oid, name
1, a
1, b
1, c
2, d
2, e
2, f
...许多行
===========================
不知道是否可行,网上有一个split函数(http://www.cnblogs.com/linbaoji/archive/2009/09/17/1568252.html),只能处理固定的字符串,而且只能返回一列
无法两列多行
解决方案 »
- oracle如何复制表空间?
- who 推荐oracle管理时间的书籍
- Oracle Client 连接报错 ORA-12170: TNS:Connect timeout occurred
- 紧急:oracle我的一个包里面的过程出现死循环了,怎么停止
- oracle字符串的连接
- oracle可以看数据库里的表么??
- oracle 如何创建一个新的用户,并复制一个已有用户的所有表和数据
- The process termination failed for JRE. %2.?
- 请问ORACLE的启动问题???
- oracle数据完整导入导出
- 求教在一个字符串中查找另一个字符串中子串的集合的高效的方法
- ORACLE 10G 怎么通过正则表达式去除重复值?
2 (
3 select '1|a,b,c' str from dual union all
4 select '2|d,e,f' str from dual
5 )
6 select distinct id, regexp_substr(name,'[^,]+',1,level) name
7 from (select substr(str,1,instr(str,'|')-1) id,
8 substr(str,instr(str,'|')+1) name
9 from tmp
10 )
11 connect by level<=length(name)-length(replace(name,',',''))+1
12 order by id, name;
ID NAME
-------------- --------------
1 a
1 b
1 c
2 d
2 e
2 f
6 rows selected
2 (
3 select '1|a,b,c' str from dual union all
4 select '2|d,e,f' str from dual
5 )
6 select distinct id, regexp_substr(name,'[^,]+',1,level) name
7 from (select substr(str,1,instr(str,'|')-1) id,
8 substr(str,instr(str,'|')+1) name
9 from tmp
10 )
11 connect by level<=length(name)-length(replace(name,',',''))+1
12 order by id, name;
ID NAME
-------------- --------------
1 a
1 b
1 c
2 d
2 e
2 f
6 rows selected
--建立对象类型
CREATE or replace TYPE mytype AS OBJECT (
field1 NUMBER,
field2 VARCHAR2 (50)
);
--建立复合类型
CREATE TYPE mytypelist AS TABLE OF mytype;
--建立函数
CREATE OR REPLACE FUNCTION pipelineme2(v_cur sys_refcursor)
RETURN mytypelist PIPELINED
IS
希望对你有用。