楼主: newkid

[精华] 深夜独霸, 轮到我出个题目了——算24点的SQL解法

[复制链接]
论坛徽章:
10
八级虎吧徽章
日期:2008-12-28 14:00:47祖国60周年纪念徽章
日期:2009-10-09 08:28:00生肖徽章2007版:兔
日期:2009-03-30 16:21:12生肖徽章2007版:牛
日期:2009-03-10 21:33:00生肖徽章2007版:龙
日期:2009-03-10 21:27:46生肖徽章2007版:龙
日期:2009-03-10 21:14:14生肖徽章2007版:龙
日期:2009-02-27 11:34:09授权会员
日期:2009-01-05 12:32:292009新春纪念徽章
日期:2009-01-04 14:52:282011新春纪念徽章
日期:2011-02-18 11:43:34
101#
发表于 2008-11-11 15:56 | 只看该作者
占位

使用道具 举报

回复
论坛徽章:
2
ITPUB新首页上线纪念徽章
日期:2007-10-20 08:38:44CTO参与奖
日期:2009-01-15 11:42:46
102#
发表于 2008-11-14 23:07 | 只看该作者
崇拜了

使用道具 举报

回复
论坛徽章:
1
2011新春纪念徽章
日期:2011-02-18 11:43:35
103#
发表于 2008-11-19 17:32 | 只看该作者

使用道具 举报

回复
论坛徽章:
10
八级虎吧徽章
日期:2008-12-28 14:00:47祖国60周年纪念徽章
日期:2009-10-09 08:28:00生肖徽章2007版:兔
日期:2009-03-30 16:21:12生肖徽章2007版:牛
日期:2009-03-10 21:33:00生肖徽章2007版:龙
日期:2009-03-10 21:27:46生肖徽章2007版:龙
日期:2009-03-10 21:14:14生肖徽章2007版:龙
日期:2009-02-27 11:34:09授权会员
日期:2009-01-05 12:32:292009新春纪念徽章
日期:2009-01-04 14:52:282011新春纪念徽章
日期:2011-02-18 11:43:34
104#
发表于 2008-11-23 10:29 | 只看该作者
占位

使用道具 举报

回复
论坛徽章:
2
2010新春纪念徽章
日期:2010-03-01 11:08:29优秀写手
日期:2014-02-11 06:00:13
105#
发表于 2008-11-26 16:27 | 只看该作者
学习一下。。。。

使用道具 举报

回复
论坛徽章:
0
106#
发表于 2008-11-27 16:58 | 只看该作者
1.
create table test1
(
  col1 number
)
;
2.insert into test1(col1) values(4,1,5,6);
commit;
3.
declare
  cursor get_express is
    select e.col1 || f.col1 || e.col2 || f.col2 || e.col3||f.col3 || e.col4 express
     from (
          select *
            from (select a.col1 col1,
                         b.col1 col2,
                         c.col1 col3,
                         d.col1 col4
                    from (select col1   col1,rownum row1 from test1) a,
                         (select col1   col1,rownum row1 from test1) b,
                         (select col1   col1,rownum row1 from test1) c,
                         (select col1   col1,rownum row1 from test1) d
                   where a.row1 <> b.row1
                     and a.row1 <> c.row1
                     and a.row1 <> d.row1
                     and b.row1 <> c.row1
                     and b.row1 <> d.row1
                     and c.row1 <> d.row1
          ) )e,
          (
            select distinct
                   c1.col1 col1,
                   c2.col1 col2,
                   c3.col1 col3
              from test2 c1,
                   test2 c2,
                   test2 c3,
                   test2 c4
          ) f
  union
    select '(' || e.col1 || f.col1 || e.col2 || ')' || f.col2 || e.col3||f.col3 || e.col4 express
     from (
          select *
            from (select a.col1 col1,
                         b.col1 col2,
                         c.col1 col3,
                         d.col1 col4
                    from (select col1   col1,rownum row1 from test1) a,
                         (select col1   col1,rownum row1 from test1) b,
                         (select col1   col1,rownum row1 from test1) c,
                         (select col1   col1,rownum row1 from test1) d
                   where a.row1 <> b.row1
                     and a.row1 <> c.row1
                     and a.row1 <> d.row1
                     and b.row1 <> c.row1
                     and b.row1 <> d.row1
                     and c.row1 <> d.row1
          ) )e,
          (
            select distinct
                   c1.col1 col1,
                   c2.col1 col2,
                   c3.col1 col3
              from test2 c1,
                   test2 c2,
                   test2 c3,
                   test2 c4
          ) f   
     union
    select '(' || e.col1 || f.col1 || e.col2 || f.col2 || e.col3|| ')' ||f.col3 || e.col4 express
     from (
          select *
            from (select a.col1 col1,
                         b.col1 col2,
                         c.col1 col3,
                         d.col1 col4
                    from (select col1   col1,rownum row1 from test1) a,
                         (select col1   col1,rownum row1 from test1) b,
                         (select col1   col1,rownum row1 from test1) c,
                         (select col1   col1,rownum row1 from test1) d
                   where a.row1 <> b.row1
                     and a.row1 <> c.row1
                     and a.row1 <> d.row1
                     and b.row1 <> c.row1
                     and b.row1 <> d.row1
                     and c.row1 <> d.row1
          ) )e,
          (
            select distinct
                   c1.col1 col1,
                   c2.col1 col2,
                   c3.col1 col3
              from test2 c1,
                   test2 c2,
                   test2 c3,
                   test2 c4
          ) f               
    union
    select e.col1 || f.col1 || '(' || e.col2 || f.col2 || e.col3|| ')' ||f.col3 || e.col4 express
     from (
          select *
            from (select a.col1 col1,
                         b.col1 col2,
                         c.col1 col3,
                         d.col1 col4
                    from (select col1   col1,rownum row1 from test1) a,
                         (select col1   col1,rownum row1 from test1) b,
                         (select col1   col1,rownum row1 from test1) c,
                         (select col1   col1,rownum row1 from test1) d
                   where a.row1 <> b.row1
                     and a.row1 <> c.row1
                     and a.row1 <> d.row1
                     and b.row1 <> c.row1
                     and b.row1 <> d.row1
                     and c.row1 <> d.row1
          ) )e,
          (
            select distinct
                   c1.col1 col1,
                   c2.col1 col2,
                   c3.col1 col3
              from test2 c1,
                   test2 c2,
                   test2 c3,
                   test2 c4
          ) f              
         
    union
    select e.col1 || f.col1 || '(' || e.col2 || f.col2 || e.col3 ||f.col3 || e.col4  || ')'express
     from (
          select *
            from (select a.col1 col1,
                         b.col1 col2,
                         c.col1 col3,
                         d.col1 col4
                    from (select col1   col1,rownum row1 from test1) a,
                         (select col1   col1,rownum row1 from test1) b,
                         (select col1   col1,rownum row1 from test1) c,
                         (select col1   col1,rownum row1 from test1) d
                   where a.row1 <> b.row1
                     and a.row1 <> c.row1
                     and a.row1 <> d.row1
                     and b.row1 <> c.row1
                     and b.row1 <> d.row1
                     and c.row1 <> d.row1
          ) )e,
          (
            select distinct
                   c1.col1 col1,
                   c2.col1 col2,
                   c3.col1 col3
              from test2 c1,
                   test2 c2,
                   test2 c3,
                   test2 c4
          ) f           

    union
    select e.col1 || f.col1 || e.col2 || f.col2 || '('|| e.col3 ||f.col3 || e.col4  || ')'express
     from (
          select *
            from (select a.col1 col1,
                         b.col1 col2,
                         c.col1 col3,
                         d.col1 col4
                    from (select col1   col1,rownum row1 from test1) a,
                         (select col1   col1,rownum row1 from test1) b,
                         (select col1   col1,rownum row1 from test1) c,
                         (select col1   col1,rownum row1 from test1) d
                   where a.row1 <> b.row1
                     and a.row1 <> c.row1
                     and a.row1 <> d.row1
                     and b.row1 <> c.row1
                     and b.row1 <> d.row1
                     and c.row1 <> d.row1
          ) )e,
          (
            select distinct
                   c1.col1 col1,
                   c2.col1 col2,
                   c3.col1 col3
              from test2 c1,
                   test2 c2,
                   test2 c3,
                   test2 c4
          ) f
    ;  
  vsql varchar2(200);
  vexpress varchar2(200);
  vresult number := 1;
begin
  open get_express;
  fetch get_express into vexpress;
  while get_express%found loop
    Begin
        EXECUTE IMMEDIATE 'select ' || vexpress || ' from dual' into vresult;
    exception
      when others then
        dbms_output.put_line('wrong express:' || vexpress);
    end ;
    if vresult = 24 then
       dbms_output.put_line(vexpress);
       close get_express;
       return;
    end if;
    fetch get_express into vexpress;
  end loop;
  close get_express;
end;
适用于一个括号

使用道具 举报

回复
论坛徽章:
0
107#
发表于 2008-11-27 17:05 | 只看该作者

回复 #2 cuicg 的帖子

declare
  cursor get_express is
    select e.col1 || f.col1 || e.col2 || f.col2 || e.col3||f.col3 || e.col4 express
     from (
          select *
            from (select a.col1 col1,
                         b.col1 col2,
                         c.col1 col3,
                         d.col1 col4
                    from (select col1   col1,rownum row1 from test1) a,
                         (select col1   col1,rownum row1 from test1) b,
                         (select col1   col1,rownum row1 from test1) c,
                         (select col1   col1,rownum row1 from test1) d
                   where a.row1 <> b.row1
                     and a.row1 <> c.row1
                     and a.row1 <> d.row1
                     and b.row1 <> c.row1
                     and b.row1 <> d.row1
                     and c.row1 <> d.row1
          ) )e,
          (
            select distinct
                   c1.col1 col1,
                   c2.col1 col2,
                   c3.col1 col3
              from test2 c1,
                   test2 c2,
                   test2 c3,
                   test2 c4
          ) f
  union
    select '(' || e.col1 || f.col1 || e.col2 || ')' || f.col2 || e.col3||f.col3 || e.col4 express
     from (
          select *
            from (select a.col1 col1,
                         b.col1 col2,
                         c.col1 col3,
                         d.col1 col4
                    from (select col1   col1,rownum row1 from test1) a,
                         (select col1   col1,rownum row1 from test1) b,
                         (select col1   col1,rownum row1 from test1) c,
                         (select col1   col1,rownum row1 from test1) d
                   where a.row1 <> b.row1
                     and a.row1 <> c.row1
                     and a.row1 <> d.row1
                     and b.row1 <> c.row1
                     and b.row1 <> d.row1
                     and c.row1 <> d.row1
          ) )e,
          (
            select distinct
                   c1.col1 col1,
                   c2.col1 col2,
                   c3.col1 col3
              from test2 c1,
                   test2 c2,
                   test2 c3,
                   test2 c4
          ) f   
     union
    select '(' || e.col1 || f.col1 || e.col2 || f.col2 || e.col3|| ')' ||f.col3 || e.col4 express
     from (
          select *
            from (select a.col1 col1,
                         b.col1 col2,
                         c.col1 col3,
                         d.col1 col4
                    from (select col1   col1,rownum row1 from test1) a,
                         (select col1   col1,rownum row1 from test1) b,
                         (select col1   col1,rownum row1 from test1) c,
                         (select col1   col1,rownum row1 from test1) d
                   where a.row1 <> b.row1
                     and a.row1 <> c.row1
                     and a.row1 <> d.row1
                     and b.row1 <> c.row1
                     and b.row1 <> d.row1
                     and c.row1 <> d.row1
          ) )e,
          (
            select distinct
                   c1.col1 col1,
                   c2.col1 col2,
                   c3.col1 col3
              from test2 c1,
                   test2 c2,
                   test2 c3,
                   test2 c4
          ) f               
    union
    select e.col1 || f.col1 || '(' || e.col2 || f.col2 || e.col3|| ')' ||f.col3 || e.col4 express
     from (
          select *
            from (select a.col1 col1,
                         b.col1 col2,
                         c.col1 col3,
                         d.col1 col4
                    from (select col1   col1,rownum row1 from test1) a,
                         (select col1   col1,rownum row1 from test1) b,
                         (select col1   col1,rownum row1 from test1) c,
                         (select col1   col1,rownum row1 from test1) d
                   where a.row1 <> b.row1
                     and a.row1 <> c.row1
                     and a.row1 <> d.row1
                     and b.row1 <> c.row1
                     and b.row1 <> d.row1
                     and c.row1 <> d.row1
          ) )e,
          (
            select distinct
                   c1.col1 col1,
                   c2.col1 col2,
                   c3.col1 col3
              from test2 c1,
                   test2 c2,
                   test2 c3,
                   test2 c4
          ) f              
         
    union
    select e.col1 || f.col1 || '(' || e.col2 || f.col2 || e.col3 ||f.col3 || e.col4  || ')'express
     from (
          select *
            from (select a.col1 col1,
                         b.col1 col2,
                         c.col1 col3,
                         d.col1 col4
                    from (select col1   col1,rownum row1 from test1) a,
                         (select col1   col1,rownum row1 from test1) b,
                         (select col1   col1,rownum row1 from test1) c,
                         (select col1   col1,rownum row1 from test1) d
                   where a.row1 <> b.row1
                     and a.row1 <> c.row1
                     and a.row1 <> d.row1
                     and b.row1 <> c.row1
                     and b.row1 <> d.row1
                     and c.row1 <> d.row1
          ) )e,
          (
            select distinct
                   c1.col1 col1,
                   c2.col1 col2,
                   c3.col1 col3
              from test2 c1,
                   test2 c2,
                   test2 c3,
                   test2 c4
          ) f           

    union
    select e.col1 || f.col1 || e.col2 || f.col2 || '('|| e.col3 ||f.col3 || e.col4  || ')'express
     from (
          select *
            from (select a.col1 col1,
                         b.col1 col2,
                         c.col1 col3,
                         d.col1 col4
                    from (select col1   col1,rownum row1 from test1) a,
                         (select col1   col1,rownum row1 from test1) b,
                         (select col1   col1,rownum row1 from test1) c,
                         (select col1   col1,rownum row1 from test1) d
                   where a.row1 <> b.row1
                     and a.row1 <> c.row1
                     and a.row1 <> d.row1
                     and b.row1 <> c.row1
                     and b.row1 <> d.row1
                     and c.row1 <> d.row1
          ) )e,
          (
            select distinct
                   c1.col1 col1,
                   c2.col1 col2,
                   c3.col1 col3
              from test2 c1,
                   test2 c2,
                   test2 c3,
                   test2 c4
          ) f
    ;  
  vsql varchar2(200);
  vexpress varchar2(200);
  vresult number := 1;
begin
  open get_express;
  fetch get_express into vexpress;
  while get_express%found loop
    Begin
        EXECUTE IMMEDIATE 'select ' || vexpress || ' from dual' into vresult;
    exception
      when others then
        dbms_output.put_line('wrong express:' || vexpress);
    end ;
    if vresult = 24 then
       dbms_output.put_line(vexpress);
       close get_express;
       return;
    end if;
    fetch get_express into vexpress;
  end loop;
  close get_express;
end;

使用道具 举报

回复
论坛徽章:
0
108#
发表于 2008-11-27 17:35 | 只看该作者
刚才的那个程序忘记的round一下了;
declare
  cursor get_express is
    select e.col1 || f.col1 || e.col2 || f.col2 || e.col3||f.col3 || e.col4 express
     from (
          select *
            from (select a.col1 col1,
                         b.col1 col2,
                         c.col1 col3,
                         d.col1 col4
                    from (select col1   col1,rownum row1 from test1) a,
                         (select col1   col1,rownum row1 from test1) b,
                         (select col1   col1,rownum row1 from test1) c,
                         (select col1   col1,rownum row1 from test1) d
                   where a.row1 <> b.row1
                     and a.row1 <> c.row1
                     and a.row1 <> d.row1
                     and b.row1 <> c.row1
                     and b.row1 <> d.row1
                     and c.row1 <> d.row1
          ) )e,
          (
            select distinct
                   c1.col1 col1,
                   c2.col1 col2,
                   c3.col1 col3
              from test2 c1,
                   test2 c2,
                   test2 c3,
                   test2 c4
          ) f
  union
    select '(' || e.col1 || f.col1 || e.col2 || ')' || f.col2 || e.col3||f.col3 || e.col4 express
     from (
          select *
            from (select a.col1 col1,
                         b.col1 col2,
                         c.col1 col3,
                         d.col1 col4
                    from (select col1   col1,rownum row1 from test1) a,
                         (select col1   col1,rownum row1 from test1) b,
                         (select col1   col1,rownum row1 from test1) c,
                         (select col1   col1,rownum row1 from test1) d
                   where a.row1 <> b.row1
                     and a.row1 <> c.row1
                     and a.row1 <> d.row1
                     and b.row1 <> c.row1
                     and b.row1 <> d.row1
                     and c.row1 <> d.row1
          ) )e,
          (
            select distinct
                   c1.col1 col1,
                   c2.col1 col2,
                   c3.col1 col3
              from test2 c1,
                   test2 c2,
                   test2 c3,
                   test2 c4
          ) f   
     union
    select '(' || e.col1 || f.col1 || e.col2 || f.col2 || e.col3|| ')' ||f.col3 || e.col4 express
     from (
          select *
            from (select a.col1 col1,
                         b.col1 col2,
                         c.col1 col3,
                         d.col1 col4
                    from (select col1   col1,rownum row1 from test1) a,
                         (select col1   col1,rownum row1 from test1) b,
                         (select col1   col1,rownum row1 from test1) c,
                         (select col1   col1,rownum row1 from test1) d
                   where a.row1 <> b.row1
                     and a.row1 <> c.row1
                     and a.row1 <> d.row1
                     and b.row1 <> c.row1
                     and b.row1 <> d.row1
                     and c.row1 <> d.row1
          ) )e,
          (
            select distinct
                   c1.col1 col1,
                   c2.col1 col2,
                   c3.col1 col3
              from test2 c1,
                   test2 c2,
                   test2 c3,
                   test2 c4
          ) f               
    union
    select e.col1 || f.col1 || '(' || e.col2 || f.col2 || e.col3|| ')' ||f.col3 || e.col4 express
     from (
          select *
            from (select a.col1 col1,
                         b.col1 col2,
                         c.col1 col3,
                         d.col1 col4
                    from (select col1   col1,rownum row1 from test1) a,
                         (select col1   col1,rownum row1 from test1) b,
                         (select col1   col1,rownum row1 from test1) c,
                         (select col1   col1,rownum row1 from test1) d
                   where a.row1 <> b.row1
                     and a.row1 <> c.row1
                     and a.row1 <> d.row1
                     and b.row1 <> c.row1
                     and b.row1 <> d.row1
                     and c.row1 <> d.row1
          ) )e,
          (
            select distinct
                   c1.col1 col1,
                   c2.col1 col2,
                   c3.col1 col3
              from test2 c1,
                   test2 c2,
                   test2 c3,
                   test2 c4
          ) f              
         
    union
    select e.col1 || f.col1 || '(' || e.col2 || f.col2 || e.col3 ||f.col3 || e.col4  || ')'express
     from (
          select *
            from (select a.col1 col1,
                         b.col1 col2,
                         c.col1 col3,
                         d.col1 col4
                    from (select col1   col1,rownum row1 from test1) a,
                         (select col1   col1,rownum row1 from test1) b,
                         (select col1   col1,rownum row1 from test1) c,
                         (select col1   col1,rownum row1 from test1) d
                   where a.row1 <> b.row1
                     and a.row1 <> c.row1
                     and a.row1 <> d.row1
                     and b.row1 <> c.row1
                     and b.row1 <> d.row1
                     and c.row1 <> d.row1
          ) )e,
          (
            select distinct
                   c1.col1 col1,
                   c2.col1 col2,
                   c3.col1 col3
              from test2 c1,
                   test2 c2,
                   test2 c3,
                   test2 c4
          ) f           

    union
    select e.col1 || f.col1 || e.col2 || f.col2 || '('|| e.col3 ||f.col3 || e.col4  || ')'express
     from (
          select *
            from (select a.col1 col1,
                         b.col1 col2,
                         c.col1 col3,
                         d.col1 col4
                    from (select col1   col1,rownum row1 from test1) a,
                         (select col1   col1,rownum row1 from test1) b,
                         (select col1   col1,rownum row1 from test1) c,
                         (select col1   col1,rownum row1 from test1) d
                   where a.row1 <> b.row1
                     and a.row1 <> c.row1
                     and a.row1 <> d.row1
                     and b.row1 <> c.row1
                     and b.row1 <> d.row1
                     and c.row1 <> d.row1
          ) )e,
          (
            select distinct
                   c1.col1 col1,
                   c2.col1 col2,
                   c3.col1 col3
              from test2 c1,
                   test2 c2,
                   test2 c3,
                   test2 c4
          ) f
    ;  
  vsql varchar2(200);
  vexpress varchar2(200);
  vresult number := 1;
begin
  open get_express;
  fetch get_express into vexpress;
  while get_express%found loop
    Begin
        EXECUTE IMMEDIATE 'select ' || vexpress || ' from dual' into vresult;
    exception
      when others then
        dbms_output.put_line('wrong express:' || vexpress);
    end ;
    if round(vresult) = 24 then
       dbms_output.put_line(vexpress);
       close get_express;
       return;
    end if;
    fetch get_express into vexpress;
  end loop;
  close get_express;
end;

使用道具 举报

回复
论坛徽章:
1
优秀写手
日期:2014-11-07 06:00:13
109#
发表于 2008-11-30 18:46 | 只看该作者
create or replace type T_TBL_CHARS is table of varchar2(50);
/
CREATE OR REPLACE FUNCTION FML(A INT, B INT, C INT, D INT) RETURN T_tbl_CHARS
    PIPELINED IS
    t  T_tbl_CHARS := T_tbl_CHARS('', '', '', '', '', '', '');
    t2 T_tbl_CHARS;
    FUNCTION eval(p_expression VARCHAR2) RETURN VARCHAR2 IS
        v_Result NUMBER;
        v_Exps   VARCHAR2(50) := p_expression;
    BEGIN
        FOR i IN 120 .. 122 LOOP
            v_Exps := REPLACE(v_Exps, chr(i), t(i-115));
        END LOOP;
        BEGIN
            EXECUTE IMMEDIATE 'BEGIN :x:= Round(' || v_Exps || ',2);END;'
                USING OUT v_Result, t(1), t(2), t(3), t(4);
        EXCEPTION
            WHEN OTHERS THEN
                NULL;
        END;
        FOR i IN 1 .. 4 LOOP
            v_Exps := REPLACE(v_Exps, ':' || (i), t(i));
        END LOOP;
        RETURN v_Exps || ' = ' || v_Result || ' ';
    END;
BEGIN
    SELECT DISTINCT sys_connect_by_path(x, ',') ||
                    substr(sys_connect_by_path(r, ','), 1, 7) || '-'
    BULK COLLECT INTO   T2
    FROM   (SELECT decode(rownum, 1, a, 2, b, 3, c, d) x, rownum r1
            FROM   dual
            CONNECT BY rownum <= 4),
           (SELECT decode(ROWNUM, 1, '+', 2, '-', 3, '*', '/') r
            FROM   dual
            CONNECT BY ROWNUM <= 4)
    WHERE  LEVEL = 4
    CONNECT BY NOCYCLE PRIOR r1 != r1;

    FOR r IN 1 .. T2.COUNT LOOP
        FOR i IN 1 .. 7 LOOP
            t(i) := rtrim(regexp_substr(T2(R), '[^,]+,', 1, i), ',');
        END LOOP;
   
        PIPE ROW(eval('((:1x:2)y:3)z:4'));
        IF t(5) = '/' THEN
            IF t(6) IN ('+', '-')oR t(7) IN ('+', '-') THEN
                PIPE ROW(eval(':1x(:2y:3z:4)'));
            END IF;
            IF t(6) IN ('+', '-') THEN
                PIPE ROW(eval('(:1x(:2y:3))z:4'));
            END IF;
        END IF;
   
        IF t(6) IN ('*', '/') AND t(7) NOT IN ('*', '/')oR
           t(7) IN ('*', '/') AND t(6) NOT IN ('*', '/') THEN
            PIPE ROW(eval('(:1x:2)y(:3z:4)'));
        END IF;
    END LOOP;
    RETURN;
END;
/
SQL> SELECT * FROM TABLE(fml(1,2,3,4)) WHERE COLUMN_VALUE LIKE '%= 24 ';

COLUMN_VALUE
--------------------------------------------------
(1+3)*(4+2) = 24
((2+1)+3)*4 = 24
(2+4)*(1+3) = 24
((2*3)*1)*4 = 24
((2*4)*1)*3 = 24
((3*2)*1)*4 = 24
(4+2)*(3+1) = 24
((1+2)+3)*4 = 24
((1*3)*4)*2 = 24

...........
1)绑定变量
2)execute immediate执行PL/SQL表达式,而不是动态SQL
因为用到了正则表达式,所以仅能用于10G以上版本

[ 本帖最后由 hyee 于 2008-12-2 11:33 编辑 ]

使用道具 举报

回复
论坛徽章:
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
110#
 楼主| 发表于 2008-12-2 05:03 | 只看该作者
to hyee:
SELECT decode(ROWNUM, 1, '+', 2, '-', 3, '*', '-') r
最后一个应该是 '/' 吧?这里是笔误。

你只考虑了
((a b) c) d
(a b) (c d)
这两种顺序,还有其他顺序没有覆盖到。

用绑定变量的PL/SQL比较有趣,我不知道和SELECT...FROM DUAL比较哪个更好。

使用道具 举报

回复

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

本版积分规则 发表回复

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