truncate table output / -------------------------------------------------------------------------------- -- Create a nested procedure -- The main procedure (which could also be an anonymous block) contains: -- function: rand which generates a random number -- procedure: mult which actually produces the multiplication table -------------------------------------------------------------------------------- CREATE or REPLACE PROCEDURE mult_table AS -- MAIN procedure v_row int; v_col int; v_ok char(1) := 'N'; line varchar2(60); -------------------------------------------------------- FUNCTION rand(p_min int, p_max int) RETURN int IS -- inner function r int; -- to compute random BEGIN r := dbms_random.value(p_min, p_max); return r; END; -------------------------------------------------------- PROCEDURE mult(p_row int, p_col int, p_ok OUT char) IS -- inner procedure tot int :=0; -- to multiply BEGIN for i in 1..p_row loop for j in 1..p_col loop tot := i*j; line := line || tot || ' '; end loop; insert into output values(line); line := null; end loop; p_ok := 'Y'; END; -------------------------------------------------------- BEGIN delete from output; v_row := rand(1,10); v_col := rand(1,10); insert into output values('multiplication table for '||v_row ||' x '||v_col ); mult(v_row, v_col, v_ok); insert into output values('completed successfully? '|| v_ok); END; / call mult_table() -- call the main procedure / select * from output