Sample PLSQL Packages
Sample PLSQL Packages
The following program provides a more complete package. We will use the CUSTOMERS table stored in our
database with the following records:
Select * from customers;
+----+----------+-----+-----------+----------+
| ID | NAME
| AGE | ADDRESS
| SALARY
+----+----------+-----+-----------+----------+
|
1 | Ramesh
32 | Ahmedabad |
3000.00 |
2 | Khilan
25 | Delhi
3000.00 |
3 | kaushik
23 | Kota
3000.00 |
4 | Chaitali |
25 | Mumbai
7500.00 |
5 | Hardik
27 | Bhopal
9500.00 |
6 | Komal
22 | MP
5500.00 |
+----+----------+-----+-----------+----------+
customers.id%type,
customers.name%type,
customers.age%type,
c_addr customers.address%type,
c_sal
customers.salary%type);
-- Removes a customer
PROCEDURE delCustomer(c_id
customers.id%TYPE);
END c_package;
/
When the above code is executed at SQL prompt, it creates the above package and displays the following result:
Package created.
customers.id%type,
c_name customers.name%type,
c_age
customers.age%type,
c_addr
customers.address%type,
c_sal
customers.salary%type)
IS
BEGIN
INSERT INTO customers (id,name,age,address,salary)
VALUES(c_id, c_name, c_age, c_addr, c_sal);
END addCustomer;
PROCEDURE delCustomer(c_id
customers.id%type) IS
BEGIN
DELETE FROM customers
WHERE id = c_id;
END delCustomer;
PROCEDURE listCustomer IS
CURSOR c_customers is
SELECT
:= n.name;
Above example makes use of nested table which we will discuss in the next chapter. When the above code is
executed at SQL prompt, it produces the following result:
Package body created.
Ramesh
Khilan
kaushik
Chaitali
Hardik
Komal
Rajnish
Subham
Ramesh
Khilan
kaushik
Chaitali
Hardik
Komal
Rajnish