和shell脚本九九乘法表一样,只是语法有少出入
先看看效果图先:
利用for循环:
SET SERVEROUTPUT ON
DECLARE
x INT :=1;
y INT :=1;
BEGIN
FOR x IN 1 .. 9 LOOP
FOR y IN 1 .. x LOOP
dbms_output.put(y || ' x '|| x || ' = ' || x*y || ' ');
END LOOP;
dbms_output.put_line(' ');
END LOOP;
END;
利用while:
SET SERVEROUTPUT ON
DECLARE
x INT := 1;
y INT;
BEGIN
WHILE x <= 9 LOOP
y := 1;
WHILE y <= x LOOP
dbms_output.put(y || ' x '|| x || ' = ' || x*y || ' ');
y := y + 1;
END LOOP;
x := x + 1;
dbms_output.put_line('');
END LOOP;
END;