You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- 2. WAP in PL/SQL for addition of 1 to 100 numbers.
17
-
18
10
sql
19
-
DECLARE
20
-
a INT :=100;
11
+
DECLARE a INT :=100;
21
12
b INT :=1;
22
13
c INT;
23
-
BEGIN
24
-
LOOP
25
-
c := a + b;
14
+
BEGIN LOOP c := a + b;
26
15
b := b +1;
27
16
DBMS_OUTPUT.PUT_LINE(c);
28
-
EXIT WHEN b > a;
17
+
EXIT
18
+
WHEN b > a;
29
19
END LOOP;
30
20
END;
31
-
32
-
33
21
-- 3. WAP in PL/SQL to check the given number is even or odd.
34
-
35
22
sql
36
-
DECLARE
37
-
a INT :=2;
23
+
DECLARE a INT :=2;
38
24
b INT :=1;
39
25
c INT;
40
-
BEGIN
41
-
c := a % b;
42
-
IF c =0 THEN
43
-
DBMS_OUTPUT.PUT_LINE('Even');
44
-
ELSE
45
-
DBMS_OUTPUT.PUT_LINE('Odd');
26
+
BEGIN c := a % b;
27
+
IF c =0 THEN DBMS_OUTPUT.PUT_LINE('Even');
28
+
ELSE DBMS_OUTPUT.PUT_LINE('Odd');
46
29
END IF;
47
30
END;
48
-
49
-
50
31
-- 4. WAP in PL/SQL to inverse a number, eg. Number 5639 when inverted must be display output 9365.
51
-
52
32
sql
53
-
DECLARE
54
-
a INT :=5639;
33
+
DECLARE a INT :=5639;
55
34
b INT :=0;
56
35
c INT;
57
-
BEGIN
58
-
LOOP
59
-
c := a % 10;
36
+
BEGIN LOOP c := a % 10;
60
37
b := b *10+ c;
61
38
a := a /10;
62
39
DBMS_OUTPUT.PUT_LINE(b);
63
-
EXIT WHEN a =0;
40
+
EXIT
41
+
WHEN a =0;
64
42
END LOOP;
65
43
END;
66
-
67
-
68
44
-- 5. WAP in PL/SQL for changing the price of product ‘P00001’ to 4000 if the price is less than 4000 in product_master table. The change is recorded in the old_price_table along with product_no and the date on which the price was changed last.
69
-
70
45
sql
71
-
DECLARE
72
-
a INT :=4000;
46
+
DECLARE a INT :=4000;
73
47
b INT;
74
48
c INT;
75
49
d VARCHAR2(20) :='P00001';
76
50
BEGIN
77
-
SELECT price INTO b FROM product_master WHERE product_no = d;
51
+
SELECT price INTO b
52
+
FROM product_master
53
+
WHERE product_no = d;
78
54
IF b < a THEN
79
-
UPDATE product_master SET price = a WHERE product_no = d;
80
-
INSERT INTO old_price_table VALUES (d, b, SYSDATE);
0 commit comments