帮忙用PL/SQL代码编写九九乘法表

分别用For loop循环和While loop循环编写,运行环境PL/SQL!
下面是用basic loop写的,供各位参考!
declare
v_num1 number;
v_num2 number;
v_str varchar2(200);
begin
v_num1:=1;
v_num2:=1;
loop
loop
v_str:=v_str||to_char(v_num2)||'*'||to_char(v_num1)||'='||substr(to_char((v_num1*v_num2)||' '),1,2);
v_num2:=v_num2+1;
v_str:=v_str||' ';
exit when v_num2>v_num1;
end loop;
dbms_output.put_line(v_str);
v_num1:=v_num1+1;
v_str:='';
v_num2:=1;
exit when v_num1>9;
end loop;
end;

#include <stdio.h>

void main()

{
int i=1,j;
while (i<=9)
{
j=i;
while (j<=i)
{
printf("%d*%d=%d",i,j,i*j);
j++; //j=j+1
}
}
printf("\n");
i++; //i=i+1
}
温馨提示:内容为网友见解,仅供参考
第1个回答  2013-05-15
select
max(case when a < 1 then '' else '1*'+cast(a as varchar)+'='+cast(a*1 as varchar) end) as [1],
max(case when a < 2 then '' else '2*'+cast(a as varchar)+'='+cast(a*2 as varchar) end) as [2],
max(case when a < 3 then '' else '3*'+cast(a as varchar)+'='+cast(a*3 as varchar) end) as [3],
max(case when a < 4 then '' else '4*'+cast(a as varchar)+'='+cast(a*4 as varchar) end) as [4],
max(case when a < 5 then '' else '5*'+cast(a as varchar)+'='+cast(a*5 as varchar) end) as [5],
max(case when a < 6 then '' else '6*'+cast(a as varchar)+'='+cast(a*6 as varchar) end) as [6],
max(case when a < 7 then '' else '7*'+cast(a as varchar)+'='+cast(a*7 as varchar) end) as [7],
max(case when a < 8 then '' else '8*'+cast(a as varchar)+'='+cast(a*8 as varchar) end) as [8],
max(case when a < 9 then '' else '9*'+cast(a as varchar)+'='+cast(a*9 as varchar) end) as [9]
from (
select 1 as a
union all
select 2
union all
select 3
union all
select 4
union all
select 5
union all
select 6
union all
select 7
union all
select 8
union all
select 9
) as t1
group by a

用pl\/sql 输出九九乘法表
第一、在Oracle9i下的脚本:SELECT to_char(flag)||'=1*'||to_char(flag) "1" ,CASE WHEN flag>1 THEN to_char(flag*2)||'=2*'||to_char(flag) ELSE '' END "2",CASE WHEN flag>2 THEN to_char(flag*3)||'=3*'||to_char(flag) ELSE '' END "3",CASE WHEN flag>3 T...

plsql输出九九乘法表如何换行?
你用dbms_output.put 输出,dbms_output.put_line 打印null换行 以下是我自己写的plsql 块 希望能对你有帮助!SQL> ho more 51.sql declare m number;begin for i in 1..9 loop for j in 1..i loop m := i*j;--dbms_output.put('*');dbms_output.put(i||'*'||j||'='||m...

用T-SQL语句怎样实现打印九九乘法表?
使用T-SQL语句打印九九乘法表的代码如下:--定义三个变量(行、列、输出字符串) 通过横竖 九行九列 进行循环输出 DECLARE @a smallint,@b smallint,@str varchar(1000)set @a=1 WHILE @a<=9 BEGIN SET @b=1 SET @str=''WHILE @b<=@a BEGIN SELECT @str=@str+convert(varchar(1),@...

oracle写一存储过程,实现九九乘法表,要求有一个输入函数p_num,它可以...
create or replace procedure test(innum in number) is m number;begin if (innum < 1 or innum > 9) then dbms_output.put_line('input number error,must between 1 to 9!');return;end if;for i in 1..innum loop for j in 1..i loop m:=j*i;dbms_output.put(''||j||...

编写程序,在屏幕上显示九九乘法表,并将九九乘法表按指定格式存储在指定...
编写程序,在屏幕上显示九九乘法表,并将九九乘法表按指定格式存储在指定文件中,文件名从键盘输入。 九九 10 r9000student | 浏览1371 次 |举报 我有更好的答案推荐于2017-12-16 20:33:17 最佳答案 以下是C++实现,具体思想就是两个循环嵌套#include <iostream> using namespace std; int main() { int i...

想深入学习C#语言,有没有达人知道C#的好的资料呢?
49. 编程输出九九乘法表。50. 定义一个行数和列数相等的二维数组,并执行初始化,然后计算该数级两条对角线上的元素值之和。51. 建立一个一维数组,使用该数组列出所学习的课程名称。52. 编写一个包含学生基本资料的结构类型数据(要求包括姓名,性别,年龄,身高,体重等)。53. 编写程序,将一年中12个月,建立一个...

用T-SQL语句怎样实现打印九九乘法表?
使用T-SQL语句打印九九乘法表的代码如下:--定义三个变量(行、列、输出字符串) 通过横竖 九行九列 进行循环输出 DECLARE @a smallint,@b smallint,@str varchar(1000)set @a=1 WHILE @a<=9 BEGIN SET @b=1 SET @str=''WHILE @b<=@a BEGIN SELECT @str=@str+convert(varchar(1),@...

相似回答