Saturday, December 3, 2016

package

package is a schema object that groups logically related PL/SQL types, variables, constants, subprograms, cursors, and exceptions. A package is compiled and stored in the database, where many applications can share its contents.

First step package specification
Second step package body

/*table*/
Create table customers(id int,name varchar(60),age int,address varchar(60),salary number(6,2))
/* insert value*/
insert into customers(id,name,age,address,salary)values(200,'prakash',12,'lko',1200.90);
insert into customers(id,name,age,address,salary)values(210,'manoj',13,'kan',1435.90);
insert into customers(id,name,age,address,salary)values(220,'raj',14,'lko',12567.90);
insert into customers(id,name,age,address,salary)values(230,'rohan',15,'kan',15460.90);
insert into customers(id,name,age,address,salary)values(240,'rakesh',16,'unnao',120000.90);
insert into customers(id,name,age,address,salary)values(250,'puneet',17,'kan',1289.90);
select * from CUSTOMERS;
/*package specification*/
CREATE or replace PACKAGE cust_sal AS
   PROCEDURE find_sal(c_id customers.id%type);
END cust_sal;

/*package body*/

CREATE OR REPLACE PACKAGE BODY cust_sal AS
   PROCEDURE find_sal(c_id customers.id%TYPE) IS
   c_sal customers.salary%TYPE;
   BEGIN
      SELECT salary INTO c_sal
      FROM customers
      WHERE id = c_id;
      dbms_output.put_line('Salary: '|| c_sal);
   END find_sal;
END cust_sal;
/*working packge*/
DECLARE
   code customers.id%type := &cc_id;
BEGIN
   cust_sal.find_sal(code);
END;


No comments:

Post a Comment