Day 6
Day 6
Day 6
->
SQL> DECLARE
2 PI NUMBER := 3.14;
3 nradius NUMBER;
4 narea NUMBER;
5 BEGIN
6 nradius := &enter_radius;
7 narea := PI * (nradius * nradius);
8 DBMS_OUTPUT.PUT_LINE('The area of the circle with radius ' || nradius || '
is: ' || narea);
9 END;
10 /
Enter value for enter_radius: 2
old 6: nradius := &enter_radius;
new 6: nradius := 2;
The area of the circle with radius 2 is: 12.56
3)Write a PL/SQL block that will accept number from the user , check if the users
balance is less than the minimum balance (5000), only deduct Rs. 100/- from the
balance. The process is fired on the account table.
->
SQL> DECLARE
2 accno NUMBER;
3 minbal NUMBER := 5000;
4 bal NUMBER;
5 BEGIN
6 accno := &enter_account_number;
7 SELECT bal INTO bal FROM Account WHERE ano = accno;
8 IF bal < minbal THEN
9 UPDATE Account SET bal = bal - 100 WHERE ano = accno;
10 COMMIT;
11 DBMS_OUTPUT.PUT_LINE('Rs. 100/- has been deducted from account number
' || accno);
12 ELSE
13 DBMS_OUTPUT.PUT_LINE('The balance for account number ' || accno || '
is greater than the minimum balance');
14 END IF;
15 END;
16 /
Enter value for enter_account_number: 103
old 6: accno := &enter_account_number;
new 6: accno := 103;
Rs. 100/- has been deducted from account number 103