趣味的字符配对,CSDN网友问题
2009-11-12 16:58
274 查看
--question
问题是这样的,我得到一个字符串,3c,有两个栏位里有如下信息3a,3b,3c,11,12,13,4a,4b,4c,另一个栏位里是1,2,3,4,5,6,7,8,9
也就是说通过字符串3c找到栏位一里3c对应的,号在第几个位置上,然后在第二个栏位里取该位置,号前的字符串,我想了一下用instr取到的位置不准,不知道应该怎么弄,大侠指点一下!!
--solute:
如是两位数的话,是有规律的!
可以用以下的操作:
select distinct a,trunc((b/3)+1) b from
(
select substr(a,mod(rownum,3)*rownum,2) a,
mod(rownum,3)*rownum b from
(
select '3a,3b,3c,11,12,13,4a,4b,4c' a from dual
)
connect by rownum <length(a)
) where b <>0 and a is not null
--and a='3c'
order by b
--result:
3a 1
3b 2
3c 3
11 4
12 5
13 6
4a 7
4b 8
4c 9
--other method:
写了一个不管中间有多少个字符的,位数不固定的!
select case when c=0 then substr(a,b+1,length(a)-1) else substr(a,b+1,c-b-1) end b,rownum from
(
select a,b,
nvl(lead(b) over(partition by a order by b),0) c,
lag(b) over(partition by a order by b) d
from
(
select distinct a, instr(a,',',rownum) b
from
(
select '3a,3b3,3c,11,12,11111113,4a111,114b,4c' a from dual
)
connect by rownum <length(a)
)
)
--result:
3a 1
3b3 2
3c 3
11 4
12 5
11111113 6
4a111 7
114b 8
4c 9
问题是这样的,我得到一个字符串,3c,有两个栏位里有如下信息3a,3b,3c,11,12,13,4a,4b,4c,另一个栏位里是1,2,3,4,5,6,7,8,9
也就是说通过字符串3c找到栏位一里3c对应的,号在第几个位置上,然后在第二个栏位里取该位置,号前的字符串,我想了一下用instr取到的位置不准,不知道应该怎么弄,大侠指点一下!!
--solute:
如是两位数的话,是有规律的!
可以用以下的操作:
select distinct a,trunc((b/3)+1) b from
(
select substr(a,mod(rownum,3)*rownum,2) a,
mod(rownum,3)*rownum b from
(
select '3a,3b,3c,11,12,13,4a,4b,4c' a from dual
)
connect by rownum <length(a)
) where b <>0 and a is not null
--and a='3c'
order by b
--result:
3a 1
3b 2
3c 3
11 4
12 5
13 6
4a 7
4b 8
4c 9
--other method:
写了一个不管中间有多少个字符的,位数不固定的!
select case when c=0 then substr(a,b+1,length(a)-1) else substr(a,b+1,c-b-1) end b,rownum from
(
select a,b,
nvl(lead(b) over(partition by a order by b),0) c,
lag(b) over(partition by a order by b) d
from
(
select distinct a, instr(a,',',rownum) b
from
(
select '3a,3b3,3c,11,12,11111113,4a111,114b,4c' a from dual
)
connect by rownum <length(a)
)
)
--result:
3a 1
3b3 2
3c 3
11 4
12 5
11111113 6
4a111 7
114b 8
4c 9
相关文章推荐
- 答一网友csdn中一问题:
- 整理在CSDN上回答网友的问题,温故知新(一)
- CSDN论坛常见初级问题(陆续更新)
- lua中的魔法字符转义问题
- 数据库原理课本中模糊匹配 like 下划线匹配多字符问题
- 英特尔拒绝召回问题芯片引争议 网友:应被欧盟狠罚
- csdn code git下载运行的问题
- C语言字符数组的赋值问题及比较
- 回文字符,最小删除问题
- 关于 MySQL UTF8 编码下生僻字符插入失败/假死问题的分析
- 【Vegas原创】url传中文字符乱码问题~
- Oracle11g创建表空间、创建用户、角色授权、导入导出表以及中文字符乱码问题
- Asp.net中处理请求中含有&字符的解析报400错误的问题
- Num 15: NYOJ: 题目0002 : 括号配对问题 [ 栈(stack) ]
- 关于网友flex自定义组件问题的答复
- 非常郁闷的一点,csdn博客的排版问题
- [MIT6.828]LAB1输入输出TAB字符的若干问题及总结
- CSDN向诸位网友诚征有关"SOA"的话题和建议
- 关于文件输出空字符问题(C语言)
- 拦截EDIT控件中的消息问题(上次提问过,我自己找了些资料,虽然拦截到消息,可得到的是空白字符)