Oracle Package 1-The base of the package

Source: Internet
Author: User

Brief analysis of package

Packages in Oracle Brief analysis of the basic concept of a package
Packages can organize several functions or stored procedures to be stored as an object. The package is usually composed of two parts, specification (specification) and body (body).

Packages can also contain constants and variables, and all functions and stored procedures in a package can use these variables or constants.

A package is an encapsulation package of related procedures, functions, variables, cursors, and exceptions, consisting of two parts, the specification and the main body.

Two specifications
1 Creating a Specification (SQL window)
Create or replace package Pkg_staff as
Staffstring VARCHAR2 (500);
Stafftage number:=18;
function get_staff_string return varchar2;
Procedure Insert_staff (in_staff_id in Number,in_staff_name in varchar2);
Procedure Update_staff (in_staff_id in number);
Procedure Delete_staff (in_staff_id in number);
End Pkg_staff;
2 View information about package specifications in a data dictionary
Select Object_name,object_type,status from User_objects
where lower (object_name) = ' Pkg_staff '
Three main body
A specification, like an interface in object-oriented programming, must implement all the methods of the specification. Oracle automatically looks for specifications with the same name as the principal to see if all of the canonical functions or stored procedures are implemented. If not, compile the error.
1 Creating principals
Create or replace package body Pkg_staff as
function get_staff_string return VARCHAR2 as
Begin
Return ' staff ';
End get_staff_string;
Procedure Insert_staff (in_staff_id in Number,in_staff_name in varchar2) as
Begin
INSERT into staff values (in_staff_id,in_staff_name);
End Insert_staff;
Procedure Update_staff (in_staff_id in number) as
Begin
Update staff Set name = ' xy ' where num = in_staff_id;
End Update_staff;
Procedure Delete_staff (in_staff_id in number) as
Begin
Delete from the staff where num = ' 1 ';
End Delete_staff;
End Pkg_staff;
2 Viewing the information of the package body in a data dictionary
Select Object_name,object_type,status from User_objects
where lower (object_name) = ' Pkg_staff '
Www.2cto.com
Four calls to a function or stored procedure in a package
Call function (SQL window)
Select Pkg_staff.get_staff_string () as result from dual
Calling a stored procedure (Command window)
Begin
Pkg_staff.delete_staff (1);
End
/

Oracle Package 1-The base of the package

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.