0% found this document useful (0 votes)
469 views

PL SQL Exercises Questions On PL SQL

The document contains 6 programming exercises: 1) Declare variables of different data types and display their values. 2) Check a salary value and display grade based on salary range using IF conditions. 3) Same as #2 but using CASE condition instead of IF. 4) Display values from 200 to 300 using a WHILE loop. 5) Display values from 200 to 300 using a FOR loop. 6) Declare a variable, check its value, and perform different actions like displaying ranges using loops or text based on the variable value.

Uploaded by

Vivek Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
469 views

PL SQL Exercises Questions On PL SQL

The document contains 6 programming exercises: 1) Declare variables of different data types and display their values. 2) Check a salary value and display grade based on salary range using IF conditions. 3) Same as #2 but using CASE condition instead of IF. 4) Display values from 200 to 300 using a WHILE loop. 5) Display values from 200 to 300 using a FOR loop. 6) Declare a variable, check its value, and perform different actions like displaying ranges using loops or text based on the variable value.

Uploaded by

Vivek Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Exercise # 1

1) Write a program to declare 3 variables with datatype as below and display their values.

 Number
 Varchar
 Date

2) Write a program to check for a salary value and display the output based on the salary
range (use IF condition)

 if salary is greater than 100000 then display the output as 'Grade A'
 if salary is between 50000 and 100000 then display the output as 'Grade B'
 if salary is between 25000 and 50000 then display the output as 'Grade C'
 if salary is between 10000 and 25000 then display the output as 'Grade D'
 otherwise display the output as 'Grade E'

3) Write a program using the same conditions as in the #1 question, but use CASE
condition instead of IF condition.

4) Write a program to display values from 200 to 300 using a WHILE loop.

5) Write a program to display values from 200 to 300 using a FOR loop.

6) Write a program to perform below steps

 Declare a variable
 If the variable value is 1 then display values from 300 to 400 using a WHILE loop
 If the variable value is 2 then display values from 400 to 800 using a FOR loop
 If the variable value is 3 then just display “wrong choice”
Answers

1)

DECLARE
A NUMBER := 10;
B VARCHAR2 (100) := 'Training course';
C DATE := TO_DATE ('01-JAN-2016', 'dd-mon-yyyy');
BEGIN
DBMS_OUTPUT.PUT_LINE (A);
DBMS_OUTPUT.PUT_LINE (B);
DBMS_OUTPUT.PUT_LINE (C);
END;

2)

DECLARE
SAL NUMBER := 10000;
BEGIN
IF SAL > 100000 THEN
DBMS_OUTPUT.PUT_LINE ('Grade A');
ELSIF SAL BETWEEN 50000 AND 100000 THEN
DBMS_OUTPUT.PUT_LINE ('Grade B');
ELSIF SAL BETWEEN 25000 AND 50000 THEN
DBMS_OUTPUT.PUT_LINE ('Grade C');
ELSIF SAL BETWEEN 10000 AND 25000 THEN
DBMS_OUTPUT.PUT_LINE ('Grade D');
ELSE
DBMS_OUTPUT.PUT_LINE ('Grade E');
END IF;
END;

3)

DECLARE
SAL NUMBER := 10000;
BEGIN
CASE WHEN SAL > 100000 THEN
DBMS_OUTPUT.PUT_LINE ('Grade A');
WHEN SAL BETWEEN 50000 AND 100000 THEN
DBMS_OUTPUT.PUT_LINE ('Grade B');
WHEN SAL BETWEEN 25000 AND 50000 THEN
DBMS_OUTPUT.PUT_LINE ('Grade C');
WHEN SAL BETWEEN 10000 AND 25000 THEN
DBMS_OUTPUT.PUT_LINE ('Grade D');
ELSE
DBMS_OUTPUT.PUT_LINE ('Grade E');
END CASE;
END;
4)

DECLARE
I NUMBER := 200;
BEGIN
WHILE I <= 300
LOOP
DBMS_OUTPUT.PUT_LINE (I);
I:=I+1;
END LOOP;
END;

5)

DECLARE
I NUMBER;
BEGIN
FOR I IN 200..300
LOOP
DBMS_OUTPUT.PUT_LINE (I);
END LOOP;
END;

6)

DECLARE
CHOICE NUMBER:=3;
I NUMBER:=300;
J NUMBER;
BEGIN
IF CHOICE = 1 THEN
WHILE I <= 300
LOOP
DBMS_OUTPUT.PUT_LINE (I);
I:=I+1;
END LOOP;
ELSIF CHOICE = 2 THEN
FOR J IN 400..800
LOOP
DBMS_OUTPUT.PUT_LINE (J);
END LOOP;
ELSIF CHOICE = 3 THEN
DBMS_OUTPUT.PUT_LINE ('Wrong Choice');
END IF;
END;

You might also like