You are on page 1of 7

1.

Write a PL/SQL program to find a given number is positive,


negative or zero.

DECLARE
num1 NUMBER := &get_num;
BEGIN
IF num1 < 0 THEN
DBMS_OUTPUT.PUT_LINE ('The number '||num1||' is a negative number');
ELSIF num1 = 0 THEN
DBMS_OUTPUT.PUT_LINE ('The number '||num1||' is equal to zero');
ELSE
DBMS_OUTPUT.PUT_LINE ('The number '||num1||' is a positive number');
END IF;
END;
/
2. Write a PL/SQL program to display the day of the date (17-
03-2020)

DECLARE
GDATE DATE := TO_DATE('&ENTER_DATE', 'DD-MM-YYYY');
DAY VARCHAR2(1);
BEGIN
DAY := TO_CHAR(GDATE, 'D');
CASE DAY
WHEN '1' THEN
DBMS_OUTPUT.PUT_LINE ('THE DATE YOU ENTERED IS SUNDAY.');
WHEN '2' THEN
DBMS_OUTPUT.PUT_LINE ('THE DATE YOU ENTERED IS MONDAY.');
WHEN '3' THEN
DBMS_OUTPUT.PUT_LINE ('THE DATE YOU ENTERED IS TUESDAY.');
WHEN '4' THEN
DBMS_OUTPUT.PUT_LINE ('THE DATE YOU ENTERED IS WEDNESDAY.');
WHEN '5' THEN
DBMS_OUTPUT.PUT_LINE ('THE DATE YOU ENTERED IS THURSDAY.');
WHEN '6' THEN
DBMS_OUTPUT.PUT_LINE ('THE DATE YOU ENTERED IS FRIDAY.');
WHEN '7' THEN
DBMS_OUTPUT.PUT_LINE ('THE DATE YOU ENTERED IS SATURDAY.');
END CASE;
END;
/
3. Write a PL/SQL program to display the following pattern
*
**
***
****
*****
DECLARE
N NUMBER:=5;
I NUMBER;
J NUMBER;
BEGIN
FOR I IN 1..N
LOOP
FOR J IN 1..I
LOOP
DBMS_OUTPUT.PUT('*');
END LOOP;

DBMS_OUTPUT.NEW_LINE;
END LOOP;
END;
/

4. Write a PL/SQL program to calculate the average salary for


all the employees working in department 30.
DECLARE
SALARY NUMBER(5);
BEGIN
SELECT AVG(SALARY) INTO SALARY FROM EMPLOYEES WHERE
DEPARTMENT_ID =30;
DBMS_OUTPUT.PUT_LINE('AVERAGE SALARY FOR ALL THE
EMPLOYEES ' ||SALARY);
END;
/
5. Write a PL/SQL program to display the employee details in
the following format

Deptid Number of Total salary


employees

6. Write a PL/SQL program to display all the employee details


along with year of experience
Ex: King’s working in dept 100 for 10 years
Declare
V_emp_rec employees%hcwtype;
Cursor cur_emp_name is
Select * from employees;
Begin
Open cur_emp_name;
Loop
Fetch cur_emp_name into v_emp_rec;
Exit when cur emp name%NOTFOUND;
Dbms_output.put_line(v_emp-rec.first_name||’working in
dept’||v_emp_rec.department_id);
End loop;
Close cur_emp_name;
End;
/
7. Write a PL/SQL procedure to display the age of all the
employees working in dept 10.
Use the possible exceptions to handle errors (Minimum 4
exceptions)
8. Write a PL/SQL function to calculate the 10%tax for all the
employees earning salary more than 30000.

9. Write a PL/SQL procedure to insert the records in the


employee table if the current date is not Sunday
10. Write a PL/SQL procedure for the following
Input value: 1234567890
Output value: (123)-45-67890

DECLARE
NUM VARCHAR(10) := '&VAL';

NUM1 VARCHAR(6);

NUM2 VARCHAR(6);

NUM3 VARCHAR(6);

BEGIN

NUM1 := SUBSTR(NUM,1,3);

NUM2 := SUBSTR(NUM,4,2);

NUM3 := SUBSTR (NUM,6,5);

DBMS_OUTPUT.PUT_LINE('('||NUM1||')'||'-'||NUM2||'-'||NUM3);

END;

You might also like