ITPub博客

首页 > 数据库 > Oracle > 乘法表

乘法表

原创 Oracle 作者:yaoronghui2005 时间:2009-12-17 13:11:49 0 删除 编辑
http://203.208.39.132/search?q=cache:s5p3bQJqhicJ:hi.baidu.com/pzhu/blog/item/069cd03901b243f23b87ce67.html+oracle+%E4%B9%98%E6%B3%95%E5%8F%A3%E8%AF%80&cd=3&hl=zh-CN&ct=clnk&gl=cn&client=aff-360homepage&st_usg=ALhdy2-NaNw4D7eIHAVBG2aqku8EuZfcRQ[@more@]
用SQL语句实现乘法口诀(ORACLE)
2007-04-30 15:37

1、select rn, ltrim(max(sys_connect_by_path(product, ',')), ',') product
from
(
select rn, product, min(product) over(partition by rn) product_min
,(row_number() over(order by rn, product)) + (dense_rank() over(order by rn)) numId
from
(
select b.rn, a.rn || '*' || b.rn || '=' || a.rn * b.rn product
from (select rownum rn from all_objects where rownum <= 9) a,
(select rownum rn from all_objects where rownum <= 9) b
where a.rn <= b.rn
order by b.rn, product
)
)
start with product = product_min
connect by numId - 1 = prior numId
group by rn;

2、select ltrim(sys_connect_by_path
(rownum || '*' || lv || '=' || rpad(rownum * lv, 2),' ')
)
from (select level lv from dual connect by level < 10)
where lv = 1
connect by lv + 1 = prior lv;

3、select reverse(sys_connect_by_path
(reverse(rpad(rownum * lv, 2)) || '=' || rownum || '*' || lv ,' ')
)
from (select level lv from dual connect by level < 10)
where lv = 1
connect by lv + 1 = prior lv;

4、with t as (select level as n from dual connect by level <=9)
select max(substr(sys_connect_by_path(b.n || '*' || a.n || '=' || a.n * b.n, ', '),3)) as val
from t a, t b
where a.n >= b.n
start with b.n=1
connect by a.n=prior a.n and b.n=prior b.n+1
group by a.n;

5、with t as (select level as n from dual connect by level <=9)
select substr(sys_connect_by_path(b.n || '*' || a.n || '=' || a.n * b.n, ' '),2) as val
from t a, t b
where a.n >= b.n and level = a.n
start with b.n=1
connect by a.n=prior a.n and b.n=prior b.n+1;

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/450962/viewspace-1029761/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: trigger对应的事件
下一篇: 初步学习
请登录后发表评论 登录
全部评论
  • 博文量
    153
  • 访问量
    176620