Modul ProgDB 11 Package
Modul ProgDB 11 Package
PEMROGRAMAN
SISTEM BASIS DATA
DAN SQL
Abstract Kompetensi
Apex adalah salah satu software tool Mahasiswa dapat menjelaskan isi pokok
yang dikembangkan oleh Oracle inc. dari mata kuliah teori dan aplikasi dari
Dalam pembuatan web aplication Apex & SQL serta membuat Aplikasi
yang sudah include di dalam oracle dari tool Apex.
10Gexpress
.
Silabus :
Penggunaan Package
Package specification
Package Specification
The specification is the interface to the package. It just DECLARES the
types, variables, constants, exceptions, cursors, and subprograms that
can be referenced from outside the package. In other words, it contains
all information about the content of the package, but excludes the code
for the subprograms.
All objects placed in the specification are called public objects. Any
subprogram not in the package specification but coded in the package
body is called a private object.
END emp_sal; /
When the above code is executed at the SQL prompt, it produces the
following result −
Package created.
Package Body
The package body has the codes for various methods declared in the
package specification and other private declarations, which are hidden
from the code outside the package.
c_sal EMPLOYEES.SALARY%TYPE;
BEGIN
FROM EMPLOYEES
END find_sal;
END emp_sal;
When the above code is executed at the SQL prompt, it produces the
following result −
Package body created.
2016 Programan Sistem Database dan SQL Pusat Bahan Ajar dan eLearning
10 Abdul Khaliq Arrachman,S.Kom,M.Kom. http://www.mercubuana.ac.id
DECLARE
BEGIN
EMP_SAL.FIND_SAL(code);
END;
When the above code is executed at the SQL prompt, it prompts to enter
the customer ID and when you enter an ID, it displays the corresponding
salary as follows −
Enter value for cc_id: 1
Salary: 3000
Example
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 |
+----+----------+-----+-----------+----------+
-- Adds a customer
c_name customerS.No.ame%type,
c_age customers.age%type,
c_addr customers.address%type,
c_sal customers.salary%type);
2016 Programan Sistem Database dan SQL Pusat Bahan Ajar dan eLearning
10 Abdul Khaliq Arrachman,S.Kom,M.Kom. http://www.mercubuana.ac.id
-- Removes a customer
PROCEDURE listCustomer;
END c_package;
When the above code is executed at the SQL prompt, it creates the
above package and displays the following result −
Package created.
c_name customerS.No.ame%type,
c_age customers.age%type,
c_addr customers.address%type,
c_sal customers.salary%type)
IS
BEGIN
END addCustomer;
BEGIN
WHERE id = c_id;
END delCustomer;
2016 Programan Sistem Database dan SQL Pusat Bahan Ajar dan eLearning
10 Abdul Khaliq Arrachman,S.Kom,M.Kom. http://www.mercubuana.ac.id
PROCEDURE listCustomer IS
CURSOR c_customers is
BEGIN
name_list.extend;
name_list(counter) := n.name;
END LOOP;
END listCustomer;
END c_package;
The above example makes use of the nested table. We will discuss the
concept of nested table in the next chapter.
When the above code is executed at the SQL prompt, it produces the
following result −
Package body created.
DECLARE
code customers.id%type:= 8;
BEGIN
2016 Programan Sistem Database dan SQL Pusat Bahan Ajar dan eLearning
10 Abdul Khaliq Arrachman,S.Kom,M.Kom. http://www.mercubuana.ac.id
c_package.addcustomer(8, 'Subham', 32, 'Delhi', 7500);
c_package.listcustomer;
c_package.delcustomer(code);
c_package.listcustomer;
END;
When the above code is executed at the SQL prompt, it produces the
following result −
Customer(1): Ramesh
Customer(2): Khilan
Customer(3): kaushik
Customer(4): Chaitali
Customer(5): Hardik
Customer(6): Komal
Customer(7): Rajnish
Customer(8): Subham
Customer(1): Ramesh
Customer(2): Khilan
Customer(3): kaushik
Customer(4): Chaitali
Customer(5): Hardik
Customer(6): Komal
Customer(7): Rajnish
DAFTAR PUSTAKA
1.abdkhaliq.com
2. www.tutorialspoint.com
3.www.plsqltutorial.com
Ak9
2016 Programan Sistem Database dan SQL Pusat Bahan Ajar dan eLearning
10 Abdul Khaliq Arrachman,S.Kom,M.Kom. http://www.mercubuana.ac.id