Oracle中打印99乘法表的13种方法
--实现1:
select r1 || '*' || r1 || '=' || r1 * r1 A,
decode(r2, '', '', r2 || '*' || r1 || '=' || r2 * r1) b,
decode(r3, '', '', r3 || '*' || r1 || '=' || r3 * r1) C,
decode(r4, '', '', r4 || '*' || r1 || '=' || r4 * r1) D,
decode(r5, '', '', r5 || '*' || r1 || '=' || r5 * r1) E,
decode(r6, '', '', r6 || '*' || r1 || '=' || r6 * r1) F,
decode(r7, '', '', r7 || '*' || r1 || '=' || r7 * r1) G,
decode(r8, '', '', r8 || '*' || r1 || '=' || r8 * r1) H,
decode(r9, '', '', r9 || '*' || r1 || '=' || r9 * r1) I
from (select level r1,
lag(level, 1) over(order by level) r2,
lag(level, 2) over(order by level) r3,
lag(level, 3) over(order by level) r4,
lag(level, 4) over(order by level) r5,
lag(level, 5) over(order by level) r6,
lag(level, 6) over(order by level) r7,
lag(level, 7) over(order by level) r8,
lag(level, 8) over(order by level) r9
from dual
connect by level < 10
); --实现2:
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 order by product; --实现3:
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; --实现4:
select reverse(ltrim((sys_connect_by_path(reverse(rownum || 'x' || lv || '=' ||
lpad(rownum * lv, 2, '')),
' ')))) "乘法口诀"
from (select level lv from dual connect by level < 10)
where lv = 1
connect by prior lv = lv + 1; --实现5:
with x as
(select level n from dual connect by level < 10)
select
max(decode(a, 1, cnt)) as a,
max(decode(a, 2, cnt)) as b,
max(decode(a, 3, cnt)) as c,
max(decode(a, 4, cnt)) as d,
max(decode(a, 5, cnt)) as e,
max(decode(a, 6, cnt)) as f,
max(decode(a, 7, cnt)) as g,
max(decode(a, 8, cnt)) as h,
max(decode(a, 9, cnt)) as i
from
(
select c0.n a, c1.n b, c0.n || '*' ||c1.n || '=' || c0.n*c1.n cnt
from x c0, x c1
where c0.n <= c1.n
)
group by b; --实现6:
select ltrim(sys_connect_by_path
(rownum - rn1+1||'*'||rownum || '=' || rpad(rownum * (rownum - rn1+1), 2) ,' '))
from
(select rownum rn1 from dual connect by rownum <=9)
where rn1 = 1
connect by rn1+1 = prior rn1; --实现7:
select max(decode(rowrn, 1, vresult, null)) A,
max(decode(rowrn, 2, vresult, null)) B,
max(decode(rowrn, 3, vresult, null)) C,
max(decode(rowrn, 4, vresult, null)) D,
max(decode(rowrn, 5, vresult, null)) E,
max(decode(rowrn, 6, vresult, null)) F,
max(decode(rowrn, 7, vresult, null)) G,
max(decode(rowrn, 8, vresult, null)) H,
max(decode(rowrn, 9, vresult, null)) J
from (select rn,
row_number() over(partition by rn order by vresult) rowrn,
vresult
from (select b.rn rn,
a.rn || '*' || b.rn || ' = ' || a.rn * b.rn vresult
from (select rownum rn from dual connect by rownum <= 9) a,
(select rownum rn from dual connect by rownum <= 9) b
where a.rn <= b.rn))
group by rn; --方法8:
select a.rn, substr(max( sys_connect_by_path(
case when a.rn*b.rn >= 10 then substr(translate(b.rn
||'*'
||a.rn
||'='
||a.rn*b.rn,'1234567890*=','一二三四五六七八九十'),1,
case when mod(a.rn*b.rn,10) = 0 or a.rn*b.rn > 20 then 3 else 2 end)
||'十'
|| translate(mod(a.rn*b.rn,10),'','一二三四五六七八九')
else translate(b.rn
||'*'
||a.rn
||'='
||a.rn*b.rn,'123456789=*','一二三四五六七八九得')
end ,',')),2) 口诀
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
connect by prior a.rn = a.rn
and prior b.rn = b.rn-1
start with b.rn = 1
group by a.rn
order by 1; --方法10:
declare
v_result varchar2(200);
begin
for i in 1..9 loop
select wmsys.wm_concat(rownum||'*'||i||'='||rownum*i) into v_result from dual connect by rownum<=i;
dbms_output.put_line(v_result);
end loop;
end; --方法11:
declare
i int;
j int;
begin
i:=1;
j:=1;
while i < 10
loop
while j <= i
loop
dbms_output.put(j||'*'||i||'=');
if length(i*j) = 1 and j!=1 then
dbms_output.put(' ');
end if;
dbms_output.put(i*j||' ');
j:=j+1;
end loop;
j:=1;
i:=i+1;
dbms_output.put_line(' ');
end loop;
end;
/ --方法12:
declare
begin
for i in 1..9 loop
for j in 1 .. i loop
dbms_output.put(j||'*'||i||'=');
if length(i*j) = 1 and j!=1 then
dbms_output.put(' ');
end if;
dbms_output.put(i*j);
dbms_output.put(' ');
end loop;
dbms_output.put_line(' ');
end loop;
end; select decode(r1,null,null,r1 || '*' || rownum ||'='|| r1* rownum) a,
decode(r2,null,null,r2 || '*' || rownum ||'='|| r2* rownum) b,
decode(r3,null,null,r3 || '*' || rownum ||'='|| r3* rownum) c,
decode(r4,null,null,r4 || '*' || rownum ||'='|| r4* rownum) d,
decode(r5,null,null,r5 || '*' || rownum ||'='|| r5* rownum) e,
decode(r6,null,null,r6 || '*' || rownum ||'='|| r6* rownum) f,
decode(r7,null,null,r7 || '*' || rownum ||'='|| r7* rownum) g,
decode(r8,null,null,r8 || '*' || rownum ||'='|| r8* rownum) h,
decode(r9,null,null,r9 || '*' || rownum ||'='|| r9* rownum) i
from ( select 1 r1,
decode(sign(level - 2), -1, null, 2) r2,
decode(sign(level - 3), -1, null, 3) r3,
decode(sign(level - 4), -1, null, 4) r4,
decode(sign(level - 5), -1, null, 5) r5,
decode(sign(level - 6), -1, null, 6) r6,
decode(sign(level - 7), -1, null, 7) r7,
decode(sign(level - 8), -1, null, 8) r8,
decode(sign(level - 9), -1, null, 9) r9
from dual
connect by level < 10
) --方法13:
select max(case when a < 1 then '' else '1*'+cast(a as varchar)+'='+cast(a*1 as varchar) end) as [],
max(case when a < 2 then '' else '2*'+cast(a as varchar)+'='+cast(a*2 as varchar) end) as [],
max(case when a < 3 then '' else '3*'+cast(a as varchar)+'='+cast(a*3 as varchar) end) as [],
max(case when a < 4 then '' else '4*'+cast(a as varchar)+'='+cast(a*4 as varchar) end) as [],
max(case when a < 5 then '' else '5*'+cast(a as varchar)+'='+cast(a*5 as varchar) end) as [],
max(case when a < 6 then '' else '6*'+cast(a as varchar)+'='+cast(a*6 as varchar) end) as [],
max(case when a < 7 then '' else '7*'+cast(a as varchar)+'='+cast(a*7 as varchar) end) as [],
max(case when a < 8 then '' else '8*'+cast(a as varchar)+'='+cast(a*8 as varchar) end) as [],
max(case when a < 9 then '' else '9*'+cast(a as varchar)+'='+cast(a*9 as varchar) end) as []
from (select rownum as a from dual connect by rownum <= 9)
Oracle中打印99乘法表的13种方法的更多相关文章
- Java流程控制:增强for循环,break&continue,打印99乘法表
增强for循环:java5引入了一种主要用于数组或集合的增强for循环for(声明语句:表达式){//代码句子} 声明语句:声明新的局部变量,该变量的类型必须和数组元素的类型匹配.其作用域限定在循环语 ...
- Python之打印99乘法表
本脚本实现打印99乘法表 #!/usr/bin/python #9*9 for i in range(1,10): print for j in range(1,i+1): print "% ...
- 使用for循环打印9×9乘法表
请使用for循环,倒序打印9×9乘法表. 打印结果如下图所示: 使用for循环打印9×9乘法表 #include <stdio.h> int main() { int i, j, resu ...
- 用JS,打印99乘法表
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...
- JS基础_打印99乘法表
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- JAVA基础编程之打印99乘法表
需求:打印9*9乘法表 技术考核: 1.for嵌套循环 代码: // 打印99乘法表 public static void print99Table() { System.out.println(&q ...
- python中使用for循环,while循环,一条命令打印99乘法表
用for循环打印九九乘法表: 1 2 3 4 5 6 for i in range (1,10): for j in range(1,10): print(j,"x& ...
- 打印99乘法表-python
题目:如何打印出阶梯状的99乘法表? 题解: #coding:utf-8def multiplication_tables(num):#for i in range(1,10): for j in r ...
- python中打印金字塔和九九乘法表的几种方法
# 打印九九乘法表for i in range(1,10): for j in range(1,i+1): # x=i*j # print(i,'*',j,'=',x,end=' ') print(' ...
随机推荐
- python当中的生成器
最近身边的朋友都在问我迭代器是什么回事,经常跟大家一起讨论python的迭代器,一点点的我觉着自己有了更深一层的理解.我写下这篇文章,希望能对懵懵懂懂的好伙伴有些帮助~ 我也不是什么能人,难免说错一些 ...
- 前端学习之jquery
前端学习之jquery 1. 什么是jQuery对象? jQuery对象就是通过jQuery包装DOM对象后产生的对象.jQuery对象是jQuery独有的.如果一个对象是jQuery对象,那么它 ...
- vue-router动态路由 刷新页面 静态资源没有加载的原因
在做项目的时候,发现刷新页面的时候,静态路由没有加载,度娘了一圈,终于解决了. vue-router使用history模式+使用嵌套路由: 访问路由和嵌套路由页面,显示正常,但是刷新页面的时候,嵌套路 ...
- 深入理解.net - 1.继承的本质
最近偶然看到这个博客你必须知道的.net,作者6的飞起啊,干货十足,还是07年写的...写的也很赞,评论更精彩,在此强烈推荐一波,看的感觉就像沙漠里发现了绿洲一样,很兴奋,意犹未尽,迫不及待的看完一篇 ...
- ABP框架 - 我的第一个Web API
本文示例源代码地址https://github.com/lcyhjx/abp-training 上一篇我们已经对ABP是什么,能做什么.有了一个印象.那么接下来我们将动手使用ABP框架快速开发一个AP ...
- Node.js系列文章:如何进行代码调试
使用任何一门编程语言,都少不了代码调试这一功能.我们在使用JavaScript编写浏览器端代码时,Chrome提供了强大的调试工具Dev Tools,但是在编写Node.js代码时,大多数人最开始都使 ...
- C#之FTP上传下载(二)
这个类几乎包含了对FTP常用的方法,有不对的地方,欢迎批评指正 public class FtpClient { #region 构造函数 /// <summary> /// 创建FTP工 ...
- java String的各种方法及操作
No. 方法名称 功能 字符与字符串 01 public String(char[] value) 将字符数组中所有内容变为字符串 02 public String(char[] value,int ...
- MySQL之存储过程和函数
存储过程和函数: 1.创建存储过程和函数: 存储过程: delimiter $$ create procedure proc_name() BEGIN 查询语句; // 记得加分号 END $$ de ...
- [TJOI 2016&HEOI 2016]排序
Description 在2016年,佳媛姐姐喜欢上了数字序列.因而他经常研究关于序列的一些奇奇怪怪的问题,现在他在研究一个难题 ,需要你来帮助他.这个难题是这样子的:给出一个1到n的全排列,现在对这 ...