12
返回列表 发新帖
楼主: tam509

[SQL] 请教一个更新sql的写法!

[复制链接]
论坛徽章:
2
奥运会纪念徽章:足球
日期:2012-08-01 13:42:492014年世界杯参赛球队: 加纳
日期:2014-05-28 10:58:53
11#
发表于 2017-5-12 15:28 | 只看该作者
本帖最后由 diaokewei 于 2017-5-12 15:31 编辑

with a as  
(select 'fbiuref384e3432<fjsduf>hgmdfig094<tgfe24f9>fn98awfmw' a from dual)
select to_char(replace(wm_concat(decode(str||r,'f0','X',str)), ','))
  from (select str,
               sum(decode(str, '<', 1, '>', -1, 0)) over(order by a range between unbounded preceding and current row) r
          from (select regexp_substr(a, '.', 1, level) str, level a
                  from a
                connect by level <= length(a)))

使用道具 举报

回复
论坛徽章:
4
目光如炬
日期:2015-11-01 22:00:00目光如炬
日期:2015-11-01 22:00:00秀才
日期:2017-05-17 11:34:12秀才
日期:2017-05-17 11:39:09
12#
发表于 2017-5-12 17:18 | 只看该作者
diaokewei 发表于 2017-5-12 15:28
with a as  
(select 'fbiuref384e3432hgmdfig094fn98awfmw' a from dual)
select to_char(replace(wm_c ...

66666

使用道具 举报

回复
论坛徽章:
41
2010广州亚运会纪念徽章:橄榄球
日期:2011-01-11 06:17:26红孩儿
日期:2012-12-19 11:07:13玉石琵琶
日期:2012-12-19 11:07:13九尾狐狸
日期:2012-12-19 11:07:13嫦娥
日期:2012-12-19 11:07:13玉兔
日期:2012-12-19 11:07:13紫蜘蛛
日期:2012-12-19 11:07:13蓝色妖姬
日期:2012-12-19 11:07:13紫蛋头
日期:2013-01-23 09:04:49SQL大赛参与纪念
日期:2013-12-06 14:03:45
13#
发表于 2017-5-13 04:08 | 只看该作者
Model的写法:

with t0 as (
            select 'fbiuref384e3432<fjsduf>hgmdfig094<tgfe24f9>fn98awfmw' str from dual union all
                        select '<fjsduf>hgmdfig094<tgfe24f9>fn98awfmw' str from dual union all
                        select 'fbiuref384e3432<fjsduf>hgmdfig094<tgfe24f9>' str from dual union all
                        select '<fjsduf>hgmdfig094<tgfe24f9>' str from dual union all
                        select 'asdfasfd<saff>f><f<fd>' str from dual union all
                        select 'fbiuref384e3432<fjsduf>hgmdfig094<>fn98awfmw' str from dual                         
          )
select  str0, replace(replace(str,'f','X'),chr(10),'f') str1
  from  t0 model  partition by(row_number() over(order by 1) rn)
    dimension by(0 d)   measures(str str0, str,str str1)
    rules iterate (10000) until (str1[0] is null)
      (  str1[0] = regexp_substr(str[0],'\<[[:alnum:]]+\>',1,1),
             str[0]  = replace(str[0],str1[0],replace(str1[0],'f',chr(10)))
      )
/

使用道具 举报

回复
论坛徽章:
520
奥运会纪念徽章:垒球
日期:2008-09-15 01:28:12生肖徽章2007版:鸡
日期:2008-11-17 23:40:58生肖徽章2007版:马
日期:2008-11-18 05:09:48数据库板块每日发贴之星
日期:2008-11-29 01:01:02数据库板块每日发贴之星
日期:2008-12-05 01:01:03生肖徽章2007版:虎
日期:2008-12-10 07:47:462009新春纪念徽章
日期:2009-01-04 14:52:28数据库板块每日发贴之星
日期:2009-02-08 01:01:03生肖徽章2007版:蛇
日期:2009-03-09 22:18:532009日食纪念
日期:2009-07-22 09:30:00
14#
发表于 2017-5-13 09:31 | 只看该作者
xqmei 发表于 2017-5-13 04:08
Model的写法:

with t0 as (

把MODEL当循环用了,相当于一截一截取出来处理,不知道速度能否比得上PLSQL。

使用道具 举报

回复
论坛徽章:
16
蛋疼蛋
日期:2012-04-27 23:09:45罗罗诺亚·索隆
日期:2016-11-04 21:04:09懒羊羊
日期:2015-06-23 09:05:532015年新春福章
日期:2015-04-01 14:21:232015年新春福章
日期:2015-03-06 11:58:39慢羊羊
日期:2015-03-04 14:53:33青年奥林匹克运动会-击剑
日期:2014-08-29 15:44:44马上加薪
日期:2014-02-18 16:48:492014年新春福章
日期:2014-02-18 16:48:49一汽
日期:2013-12-24 18:12:09
15#
发表于 2017-5-17 15:51 | 只看该作者
SQL> select * from t;

ID
------------------------------------------------------------
fbiuref384e3432<fjsduf>hgmdfig094<tgfe24f9>fn98awfmw

SQL> select listagg(s2, '') within group(order by id) s3
  2    from (select id,
  3                 case
  4                   when instr(s1, '<') > 0 then
  5                    s1
  6                   else
  7                    replace(s1, 'f', 'X')
  8                 end s2
  9            from (select level as id, regexp_substr(s, '[^#]+', 1, level) s1
10                    from (select replace(replace(id, '>', '>#'), '<', '#<') s
11                            from t)
12                  connect by level <= regexp_count(s, '#') + 1));

S3
------------------------------------------------------------
XbiureX384e3432<fjsduf>hgmdXig094<tgfe24f9>Xn98awXmw

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表