0% found this document useful (0 votes)
3 views2 pages

Explanation Pract6 Plsql

The document explains how to create and use stored procedures in SQL, including examples for deleting an employee by ID and calculating an annual salary. It outlines parameter types (IN, OUT, IN OUT) and provides code snippets for creating, testing, and deleting procedures. Additionally, it demonstrates the use of DBMS_OUTPUT to display results from the procedures.

Uploaded by

swanandibagwe
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)
3 views2 pages

Explanation Pract6 Plsql

The document explains how to create and use stored procedures in SQL, including examples for deleting an employee by ID and calculating an annual salary. It outlines parameter types (IN, OUT, IN OUT) and provides code snippets for creating, testing, and deleting procedures. Additionally, it demonstrates the use of DBMS_OUTPUT to display results from the procedures.

Uploaded by

swanandibagwe
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/ 2

A stored Procedure is a reusable SQl code block that perform specific task.

Parameters type

IN
OUT
IN OUT
Ex. 1: Develop a stored procedure to delete an employee based on Employee ID. Test the procedure
with different input.

Ex 2: Develop a stored procedure to delete an employee based on employee ID and demonstrate the
same.

CREATE Table newemp as select * from emp;


This command will create a duplicate table same as emp.

Code:

Create or replace Procedure delete_emp (p_emp_id IN number)

AS

BEGIN

DELETE from newemp where empno=p_emp_id;

END;

CODE for TESTING the Procedure

BEGIN
delete_emp(7934);
END;
/
CODE FOR DELETING NON EXISTENT EMP

BEGIN
Delete_emp(999);
End;
/
To DELETE a Procedure:
DROP PROCEDURE delete_emp;
Another Example:
Create a procedure to calculate and return annual salary of an employee
CREATE OR REPLACE PROCEDURE Ann_SAL (
emp_sal In Number,
Asal OUT Number)
IS
Begin
Asal:=emp_sal*12;
END;
/
EXECUTE THE PROCEDURE
Set serveroutput ON
DECLARE
emp_salary Number:=&sal;
yearly_sal number;
BEGIN
Ann_sal(emp_salary,yearly_sal);
DBMS_OUTPUT.PUT_LINE('Annual Salary is ' || yearly_sal);
END;
/

You might also like