1 . Write a program in PL/SQL to check given number is Positive or Negative. Declare num Number(2) := 30; Begin if ( num > 0) then DBMS_OUTPUT.PUT_LINE('positive'); else DBMS_OUTPUT.PUT_LINE('Negative'); end if; End; /
2 . Write a program in PL/SQL to print +, - , *, / operations. Declare num1 Number(2) := 30; num2 Number(2) := 20; operator Varchar (2):= &operator; sum number(5); Div number(5); Mul number(5); Sub number(5); Begin if operator = '+' then sum := num1 + num2; DBMS_OUTPUT.PUT_LINE('sum');
elsif operator = '-' then Sub := num1 - num2; DBMS_OUTPUT.PUT_LINE('Sub'); elsif operator = '*' then Mul := num1 * num2; DBMS_OUTPUT.PUT_LINE(' Mul '); else Div := num1 / num2; DBMS_OUTPUT.PUT_LINE(' Div '); end if; End; /
3. Write a program in PL/SQL to show the functioning of loop. Declare n Number(4) := 1 ; Begin loop DBMS_OUTPUT.PUT_LINE(n); n:= n+1; end loop; End; /
4. Write a program in PL/SQL to show the functioning of loop. Declare n Number(4) := 2; limit Number:= &limit; Begin LOOP if (n mod 2 = 0 AND n <= limit) then DBMS_OUTPUT.PUT_LINE(n); Exit; n:= n+1; End if; End loop; End; /
5. Write a program in PL/SQL to check given number is Positive or Negative. Declare i Number(4) := 1; a Number(2); Begin while i<=10 LOOP a:= i*2; DBMS_OUTPUT.PUT_LINE(a); i:= i+1; End loop; End; /
6. Write a program in PL/SQL to check given number is Positive or Negative. DECLARE a number(2); BEGIN FOR a in 10 .. 20 LOOP dbms_output.put_line ('value of a: ' || a); END LOOP; END; /
7. Write a program in PL/SQL to check given number is Positive or Negative. DECLARE a number(2) ; BEGIN FOR a IN REVERSE 10 .. 20 LOOP dbms_output.put_line ('value of a: ' || a); END LOOP; END; /
8. Write a program in PL/SQL to print prime numbers. DECLARE i number(3); j number(3); BEGIN i := 2; LOOP j:= 2; LOOP exit WHEN ((mod(i, j) = 0) or (j = i)); j := j +1; END LOOP; IF (j = i ) THEN dbms_output.put_line (i ); END IF; i := i + 1; exit WHEN i = 50; END LOOP; END; /
8. Write a program in PL/SQL to show Nested loop functioning. DECLARE BEGIN FOR i IN REVERSE 1 ..5 LOOP FOR j IN REVERSE 1 .. 5 LOOP DBMS_OUTPUT.PUT_LINE(j); END LOOP; DBMS_OUTPUT.New_LINE (); END LOOP; END;
9. Write a program in PL/SQL to print table of given number. Declare n Number(4) := &n; multiple Number(2) := &multiple; result Number(8); Begin FOR I in 1..multiple LOOP result:= i*n; DBMS_OUTPUT.PUT_LINE(result); i:= i+1; End loop; End; /