User Tools

Site Tools


HPL/SQL is included to Apache Hive since version 2.0


This is an old revision of the document!

A PCRE internal error occured. This might be caused by a faulty plugin

====== CREATE PACKAGE Statement ====== CREATE PACKAGE statement allows you to define a collection of related variables, procedures and functions. **Syntax** Package specification: <code language=sql> [CREATE [OR REPLACE] | REPLACE] PACKAGE package_name AS | IS package_spec END package_spec: variable declaration | function declaration | procedure declaration </code> Package body: <code language=sql> [CREATE [OR REPLACE] | REPLACE] PACKAGE BODY package_name AS | IS package_body END package_body: private variable declaration | function definition | procedure definition </code> **Example**: Define a package and then call its members. Package specification: <code language=sql> create or replace package users as session_count int := 0; function get_count() return int; procedure add(name varchar(100)); end; </code> Package body: <code language=sql> create or replace package body users as function get_count() return int is return session_count; end; procedure add(name varchar(100)) is -- ... session_count = session_count + 1; end; end; </code> Using the package: <code language=sql> users.add('John'); users.add('Sarah'); users.add('Paul'); print 'Number of users: ' || users.get_count(); </code> **Compatibility:** Oracle **Version**: HPL/SQL 0.3.13 See also: * [[udf-sproc|User-Defined Functions and Stored Procedures]] * [[call|CALL]] * [[create-function|CREATE FUNCTION]] * [[create-procedure|CREATE PROCEDURE]] * [[include|INCLUDE]]