-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9.sql
46 lines (39 loc) · 1.12 KB
/
9.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
DECLARE
n NUMBER;
i NUMBER := 1;
CURSOR c1 IS SELECT * FROM SQUARES;
CURSOR c2 IS SELECT * FROM CUBES;
BEGIN
DBMS_OUTPUT.PUT_LINE('Enter a positive integer n:');
n := :n;
EXECUTE IMMEDIATE 'CREATE TABLE SQUARES (num NUMBER)';
EXECUTE IMMEDIATE 'CREATE TABLE CUBES (num NUMBER)';
FOR i IN 0..n LOOP
FOR j IN 0..CEIL(i/2) LOOP
IF j*j = i THEN
INSERT INTO SQUARES VALUES(i);
END IF;
IF j*j*j = i THEN
INSERT INTO CUBES VALUES(i);
END IF;
END LOOP;
END LOOP;
dbms_output.put_line('Square Numbers from table');
OPEN c1;
LOOP
FETCH c1 INTO snum;
EXIT WHEN c1%NOTFOUND;
dbms_output.put_line(snum);
END LOOP;
dbms_output.put_line('Cube Numbers from table');
OPEN c2;
LOOP
FETCH c2 INTO cnum;
EXIT WHEN c2%NOTFOUND;
dbms_output.put_line(cnum);
END LOOP;
CLOSE c1;
CLOSE c2;
EXECUTE IMMEDIATE 'DROP TABLE SQUARE';
EXECUTE IMMEDIATE 'DROP TABLE CUBE';
END;