字符串的处理

heyu111 2013-08-08 03:12:39

怎么能在查询的时候把这列的值对应的转化成:

...全文
112 点赞 收藏 10
写回复
10 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
空心兜兜 2013-08-09
这个应该是很容易的啊
回复
hh7yx 2013-08-08
引用 7 楼 heyu111 的回复:
[quote=引用 6 楼 zhaoxiangchong 的回复:] [quote=引用 1 楼 u010412956 的回复:] 楼主问问题最好说明白一点,比如有2个-,就把-替换为4个0 之类的说明下。
with t as
 (select '1002-1-1' subject_id
    from dual
  union all
  select '1002-10' from dual)
select replace(subject_id,
               '-',
               rpad('0', regexp_count(subject_id, '-') * 2, '0'))
  from t;
很好,佩服[/quote] 不是我想要的啊!!![/quote] 11g
with t as
 (select '1002-1-3' subject_id
    from dual
  union all
  select '1002-10'
    from dual
  union all
  select '1002-2' from dual)
select listagg(subject_id1, '') within group(order by rownum)
  from (select subject_id,
               lpad(regexp_substr(subject_id, '[^-]+', 1, level), 4, '0') subject_id1
          from t
        connect by subject_id = prior subject_id
               and level <= regexp_count(subject_id, '-') + 1
               and prior dbms_random.value is not null)
 group by subject_id;
回复
hh7yx 2013-08-08
引用 7 楼 heyu111 的回复:
[quote=引用 6 楼 zhaoxiangchong 的回复:] [quote=引用 1 楼 u010412956 的回复:] 楼主问问题最好说明白一点,比如有2个-,就把-替换为4个0 之类的说明下。
with t as
 (select '1002-1-1' subject_id
    from dual
  union all
  select '1002-10' from dual)
select replace(subject_id,
               '-',
               rpad('0', regexp_count(subject_id, '-') * 2, '0'))
  from t;
很好,佩服[/quote] 不是我想要的啊!!![/quote] 我知道,开始理解错你意思了。 9i都不能用正则啊,我得想想
回复
heyu111 2013-08-08
引用 6 楼 zhaoxiangchong 的回复:
[quote=引用 1 楼 u010412956 的回复:] 楼主问问题最好说明白一点,比如有2个-,就把-替换为4个0 之类的说明下。
with t as
 (select '1002-1-1' subject_id
    from dual
  union all
  select '1002-10' from dual)
select replace(subject_id,
               '-',
               rpad('0', regexp_count(subject_id, '-') * 2, '0'))
  from t;
很好,佩服[/quote] 不是我想要的啊!!!
回复
善若止水 2013-08-08
引用 1 楼 u010412956 的回复:
楼主问问题最好说明白一点,比如有2个-,就把-替换为4个0 之类的说明下。
with t as
 (select '1002-1-1' subject_id
    from dual
  union all
  select '1002-10' from dual)
select replace(subject_id,
               '-',
               rpad('0', regexp_count(subject_id, '-') * 2, '0'))
  from t;
很好,佩服
回复
heyu111 2013-08-08
我是9i,在线等了 比如‘1002-10-2’输出为:1002-0010-0002,然后去掉‘-’
回复
heyu111 2013-08-08
就是把‘-’去掉,不足4位的补齐4位
回复
hh7yx 2013-08-08
引用 2 楼 heyu111 的回复:
就是把‘-’去掉替换为4个0 9i怎么办
我没看清楚。 你的需求应该是把-替换为2个0,然后数字部分,如果不足2位的,前面再补个0????
回复
heyu111 2013-08-08
就是把‘-’去掉替换为4个0 9i怎么办
回复
hh7yx 2013-08-08
楼主问问题最好说明白一点,比如有2个-,就把-替换为4个0 之类的说明下。
with t as
 (select '1002-1-1' subject_id
    from dual
  union all
  select '1002-10' from dual)
select replace(subject_id,
               '-',
               rpad('0', regexp_count(subject_id, '-') * 2, '0'))
  from t;
回复
相关推荐
发帖
Oracle
创建于2007-09-28

1.6w+

社区成员

Oracle开发相关技术讨论
申请成为版主
帖子事件
创建了帖子
2013-08-08 03:12
社区公告
暂无公告