Oracle字段中使用 |或者其他符合分割后数据的取值

本文介绍了如何在Oracle数据库中处理字段中使用管道符号(|)或其他分隔符分隔的数据,通过实例01和实例02展示了有效的取值方法。

实例01:

CREATE TABLE T3 (
 LX VARCHAR2(10),
 DM VARCHAR2(20),
 QX VARCHAR2(3000)
 );
 insert into T3 values('CK09','mp702','about|accept|cancel|controlg|controlp');
 
select LX, DM, regexp_substr(QX, '[^|]+',1,level) new_item
from t3 connect by level <= regexp_count(qx,'|') + 1 
and prior rowid = rowid 
and prior dbms_random.value is not null
and regexp_substr(QX, '[^|]+',1,level) is not null

实例02:

create table a (
 cid number,
 num number);
insert into a (CID, NUM) values (101, 30);
insert into a (CID, NUM) values (102, 34);
insert into a (CID, NUM) values (185, 34);
insert into a (CID, NUM) values (230, 224);
insert into a (CID, NUM) values (345, 12);
create table b (
 id number,
 cid varchar2(100));
insert into b (ID, CID) values (1, '101|102|103|104');
insert into b (ID, CID) values (2, '201|223|432|235');
insert into b (ID, CID) values (3, '102|345|999|234|230');
with tmp as
 (select id, regexp_substr(cid, '[^|]+', 1, level) new_cid
    from b
  connect by level <= regexp_count(cid, '|') + 1
         and prior rowid = rowid
         and prior dbms_random.value is not null
         and regexp_substr(cid, '[^|]+', 1, level) is not null)
select * from a where a.cid not in (select new_cid from tmp);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值