楼主: lastwinner

[精华] 用至少三种不同的写法实现逐字重复

[复制链接]
招聘 : 多个岗位招聘
论坛徽章:
33
2010广州亚运会纪念徽章:跆拳道
日期:2010-11-22 15:42:39灰彻蛋
日期:2012-05-16 13:17:56参与WIN7挑战赛纪念
日期:2012-05-24 10:37:35茶鸡蛋
日期:2012-05-28 17:27:32灰彻蛋
日期:2012-06-13 18:48:14双黄蛋
日期:2012-06-14 14:32:02奥运会纪念徽章:帆船
日期:2012-07-10 09:43:29奥运会纪念徽章:足球
日期:2012-08-17 09:17:32奥运会纪念徽章:帆船
日期:2012-07-26 15:46:49奥运会纪念徽章:赛艇
日期:2012-08-20 16:23:58
11#
发表于 2012-3-4 12:32 | 只看该作者
都是高手~~~

使用道具 举报

回复
论坛徽章:
407
紫蛋头
日期:2012-05-21 10:19:41迷宫蛋
日期:2012-06-06 16:02:49奥运会纪念徽章:足球
日期:2012-06-29 15:30:06奥运会纪念徽章:排球
日期:2012-07-10 21:24:24鲜花蛋
日期:2012-07-16 15:24:59奥运会纪念徽章:拳击
日期:2012-08-07 10:54:50奥运会纪念徽章:羽毛球
日期:2012-08-21 15:55:33奥运会纪念徽章:蹦床
日期:2012-08-21 21:09:51奥运会纪念徽章:篮球
日期:2012-08-24 10:29:11奥运会纪念徽章:体操
日期:2012-09-07 16:40:00
12#
发表于 2012-3-4 12:51 | 只看该作者
居然忘记了最基本的写法,根据题意最多写20个substr
with t as (select rownum+64 n from dual connect by rownum<=3),
t2 as (select replace(sys_connect_by_path(chr(n),','),',') str from t where level>=2 start with n=65 connect by nocycle n!=prior n )
select substr(str,1,1)||substr(str,1,1)||
substr(str,2,1)||substr(str,2,1)||
substr(str,3,1)||substr(str,3,1)||
substr(str,4,1)||substr(str,4,1)s
from t2;

使用道具 举报

回复
论坛徽章:
548
生肖徽章2007版:猴
日期:2008-05-16 11:28:59生肖徽章2007版:马
日期:2008-10-08 17:01:01SQL大赛参与纪念
日期:2011-04-13 12:08:17授权会员
日期:2011-06-17 16:14:53ITPUB元老
日期:2011-06-21 11:47:01ITPUB官方微博粉丝徽章
日期:2011-07-01 09:45:27ITPUB十周年纪念徽章
日期:2011-09-27 16:30:472012新春纪念徽章
日期:2012-01-04 11:51:222012新春纪念徽章
日期:2020-11-30 22:13:24海蓝宝石
日期:2012-02-20 19:24:27
13#
发表于 2012-3-4 16:31 | 只看该作者

SQL> with t  as (select rownum+64 n from dual connect by rownum<=3),
  2       t2 as (select replace(sys_connect_by_path(chr(n),','),',') str
  3                from t
  4               where level>=2
  5               start with n=65
  6             connect by nocycle n!=prior n )
  7  select listagg(substr(str,rn,1)||substr(str,rn,1)) within group(order by id,rn)
  8    from (select rownum id,str from t2) a,
  9         (select level rn from dual connect by level <=(select max(length(str)) from t2)) b
10   where substr(str,rn,1) is not null
11   group by id
12  /

LISTAGG(SUBSTR(STR,RN,1)||SUBS
--------------------------------------------------------------------------------
AABB
AABBCC
AACC
AACCBB

使用道具 举报

回复
论坛徽章:
484
ITPUB北京香山2007年会纪念徽章
日期:2007-01-24 14:35:02ITPUB北京九华山庄2008年会纪念徽章
日期:2008-01-21 16:50:24ITPUB北京2009年会纪念徽章
日期:2009-02-09 11:42:452010新春纪念徽章
日期:2010-03-01 11:04:552010数据库技术大会纪念徽章
日期:2010-05-13 10:04:272010系统架构师大会纪念
日期:2010-09-04 13:35:54ITPUB9周年纪念徽章
日期:2010-10-08 09:28:512011新春纪念徽章
日期:2011-02-18 11:43:32ITPUB十周年纪念徽章
日期:2011-11-01 16:19:412012新春纪念徽章
日期:2012-01-04 11:49:54
14#
 楼主| 发表于 2012-3-4 16:49 | 只看该作者
xgghxkhuang 发表于 2012-3-4 10:24
select regexp_REPLACE('ABBCBABC','(.)','\1\1') FROM DUAL;
--1        AABBBBCCBBAABBCC
newkid的方法可行呀 ...

我是回的00的
你的疑问是正则的疑问,字符.代表的是很多字符,但并不是任意字符,\n他就代表不了

使用道具 举报

回复
论坛徽章:
548
生肖徽章2007版:猴
日期:2008-05-16 11:28:59生肖徽章2007版:马
日期:2008-10-08 17:01:01SQL大赛参与纪念
日期:2011-04-13 12:08:17授权会员
日期:2011-06-17 16:14:53ITPUB元老
日期:2011-06-21 11:47:01ITPUB官方微博粉丝徽章
日期:2011-07-01 09:45:27ITPUB十周年纪念徽章
日期:2011-09-27 16:30:472012新春纪念徽章
日期:2012-01-04 11:51:222012新春纪念徽章
日期:2020-11-30 22:13:24海蓝宝石
日期:2012-02-20 19:24:27
15#
发表于 2012-3-4 16:50 | 只看该作者
SQL> create or replace function f_str(p_str in varchar2)
  2  return varchar2
  3  is
  4    l_res varchar2(32767);
  5  begin
  6    for i in 1 .. length(p_str) loop
  7      l_res := l_res||substr(p_str,i,1)||substr(p_str,i,1);
  8    end loop;
  9    return l_res;
10  end;
11  /

Function created

SQL>
SQL> with t  as (select rownum+64 n from dual connect by rownum<=3),
  2       t2 as (select replace(sys_connect_by_path(chr(n),','),',') str
  3                from t
  4               where level>=2
  5               start with n=65
  6             connect by nocycle n!=prior n )
  7  select f_str(str) from t2
  8  /

F_STR(STR)
--------------------------------------------------------------------------------
AABB
AABBCC
AACC
AACCBB

使用道具 举报

回复
论坛徽章:
484
ITPUB北京香山2007年会纪念徽章
日期:2007-01-24 14:35:02ITPUB北京九华山庄2008年会纪念徽章
日期:2008-01-21 16:50:24ITPUB北京2009年会纪念徽章
日期:2009-02-09 11:42:452010新春纪念徽章
日期:2010-03-01 11:04:552010数据库技术大会纪念徽章
日期:2010-05-13 10:04:272010系统架构师大会纪念
日期:2010-09-04 13:35:54ITPUB9周年纪念徽章
日期:2010-10-08 09:28:512011新春纪念徽章
日期:2011-02-18 11:43:32ITPUB十周年纪念徽章
日期:2011-11-01 16:19:412012新春纪念徽章
日期:2012-01-04 11:49:54
16#
 楼主| 发表于 2012-3-4 16:52 | 只看该作者
〇〇 发表于 2012-3-4 12:51
居然忘记了最基本的写法,根据题意最多写20个substr
with t as (select rownum+64 n from dual connect by ...


真细致

使用道具 举报

回复
论坛徽章:
32
祖国60周年纪念徽章
日期:2009-10-09 08:28:002013年新春福章
日期:2013-02-25 14:51:24迷宫蛋
日期:2013-06-28 11:09:23ITPUB季度 技术新星
日期:2013-07-30 16:04:58优秀写手
日期:2013-12-18 09:29:132014年新春福章
日期:2014-02-18 16:43:09马上有钱
日期:2014-02-18 16:43:09红孩儿
日期:2014-03-04 16:40:38美羊羊
日期:2015-02-16 16:36:28懒羊羊
日期:2015-03-04 14:52:11
17#
发表于 2012-3-4 18:02 | 只看该作者
SQL> with tmp as(
  2  select 'AB' a from dual union all
  3  select 'ABC' a from dual union all
  4  select 'AC' a from dual union all
  5  select 'BC' a from dual)
  6  select a.a, replace(b.column_value,',') cv
  7    from tmp a, table(cast(multiset(select wmsys.wm_concat(substr(a.a, ceil(rownum/2),1)) from dual connect by rownum <= 2*length(a.a)) as sys.odcivarchar2list)) b
  8  /

A   CV
--- --------------------------------------------------------------------------------
AB  AABB
ABC AABBCC
AC  AACC
BC  BBCC

使用道具 举报

回复
论坛徽章:
7
ITPUB9周年纪念徽章
日期:2010-10-08 09:28:52数据库板块每日发贴之星
日期:2010-11-28 01:01:012011新春纪念徽章
日期:2011-02-18 11:43:35ITPUB十周年纪念徽章
日期:2011-11-01 16:25:22灰彻蛋
日期:2012-04-22 15:50:51紫蛋头
日期:2012-12-27 15:05:08茶鸡蛋
日期:2013-07-17 11:24:34
18#
发表于 2012-3-4 19:22 | 只看该作者
with t as (select rownum+64 n from dual connect by rownum<=3),
tb as (select replace(sys_connect_by_path(chr(n),','),',') str from t where level>=2 start with n=65 connect by nocycle n!=prior n ),

  tb2 as
  (select level rn from dual connect by level<(select max(length(str))+1 from tb))
  select str,max(strres) strres
  from(
  select str,wm_concat(substr(str,rn,1)||substr(str,rn,1)) over(partition by str order by str,rn) strres
  from tb2,tb
    where length(str)>=rn
    )
group by str

使用道具 举报

回复
论坛徽章:
548
生肖徽章2007版:猴
日期:2008-05-16 11:28:59生肖徽章2007版:马
日期:2008-10-08 17:01:01SQL大赛参与纪念
日期:2011-04-13 12:08:17授权会员
日期:2011-06-17 16:14:53ITPUB元老
日期:2011-06-21 11:47:01ITPUB官方微博粉丝徽章
日期:2011-07-01 09:45:27ITPUB十周年纪念徽章
日期:2011-09-27 16:30:472012新春纪念徽章
日期:2012-01-04 11:51:222012新春纪念徽章
日期:2020-11-30 22:13:24海蓝宝石
日期:2012-02-20 19:24:27
19#
发表于 2012-3-4 22:11 | 只看该作者
SQL> with t  as (select rownum+64 n from dual connect by rownum<=3),
  2       t2 as (select replace(sys_connect_by_path(chr(n),','),',') str
  3                from t
  4               where level>=2
  5               start with n=65
  6             connect by nocycle n!=prior n )
  7  select listagg(dup) within group (order by rn) res
  8    from (
  9          select id,level rn,substr(str,level,1)||substr(str,level,1) dup
10            from (select rownum id ,str from t2)
11          connect by prior id = id and level <= length(str) and prior dbms_random.value is not null
12         )
13   group by id
14   order by id
15  /

RES
--------------------------------------------------------------------------------
AABB
AABBCC
AACC
AACCBB

使用道具 举报

回复
论坛徽章:
548
生肖徽章2007版:猴
日期:2008-05-16 11:28:59生肖徽章2007版:马
日期:2008-10-08 17:01:01SQL大赛参与纪念
日期:2011-04-13 12:08:17授权会员
日期:2011-06-17 16:14:53ITPUB元老
日期:2011-06-21 11:47:01ITPUB官方微博粉丝徽章
日期:2011-07-01 09:45:27ITPUB十周年纪念徽章
日期:2011-09-27 16:30:472012新春纪念徽章
日期:2012-01-04 11:51:222012新春纪念徽章
日期:2020-11-30 22:13:24海蓝宝石
日期:2012-02-20 19:24:27
20#
发表于 2012-3-4 22:23 | 只看该作者
SQL> with t  as (select rownum+64 n from dual connect by rownum<=3),
  2       t2 as (select replace(sys_connect_by_path(chr(n),','),',') str
  3                from t
  4               where level>=2
  5               start with n=65
  6             connect by nocycle n!=prior n )
  7  select replace(max(con),',',null) res
  8  from (
  9  select id,wm_concat(dup) over (partition by id order by rn) con
10    from (
11          select id,level rn,substr(str,level,1)||substr(str,level,1) dup
12            from (select rownum id ,str from t2)
13          connect by prior id = id and level <= length(str) and prior dbms_random.value is not null
14         )
15       )
16  group by id
17  order by id
18  /

RES
--------------------------------------------------------------------------------
AABB
AABBCC
AACC
AACCBB

使用道具 举报

回复

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

本版积分规则 发表回复

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