日期:2014-05-16  浏览次数:20593 次

包实例

?

?

SQL> col object_name format a20;
SQL> col object_type format a20;
SQL> select object_name,object_type from user_objects
  2  order by object_type asc;

OBJECT_NAME          OBJECT_TYPE
-------------------- --------------------
TAX                  FUNCTION
BIN$kHmZTqomReyTGf6x INDEX
Gpa9GQ==$2

BIN$gtl8hEtDTwyJSJRw INDEX
zqxFjQ==$0

BIN$lBwhR7ckQVmBoQJC INDEX
jyJTxg==$2

AVGSALARYFORDEPT     PROCEDURE

OBJECT_NAME          OBJECT_TYPE
-------------------- --------------------
RAISEDSALARYBYEMPNOP PROCEDURE
ROC

ADD_DEPT_PROC        PROCEDURE
EMPCOPY              TABLE
TMP                  TABLE
DEPT                 TABLE
SALGRADE             TABLE
BONUS                TABLE
EMP                  TABLE
EMP_VW               VIEW

已选择14行。

SQL> set linesize 200;
SQL> /

OBJECT_NAME          OBJECT_TYPE
-------------------- --------------------
TAX                  FUNCTION
BIN$kHmZTqomReyTGf6x INDEX
Gpa9GQ==$2

BIN$gtl8hEtDTwyJSJRw INDEX
zqxFjQ==$0

BIN$lBwhR7ckQVmBoQJC INDEX
jyJTxg==$2

AVGSALARYFORDEPT     PROCEDURE

OBJECT_NAME          OBJECT_TYPE
-------------------- --------------------
RAISEDSALARYBYEMPNOP PROCEDURE
ROC

ADD_DEPT_PROC        PROCEDURE
EMPCOPY              TABLE
TMP                  TABLE
DEPT                 TABLE
SALGRADE             TABLE
BONUS                TABLE
EMP                  TABLE
EMP_VW               VIEW

已选择14行。

SQL> set pagesize 100;
SQL> /

OBJECT_NAME          OBJECT_TYPE
-------------------- --------------------
TAX                  FUNCTION
BIN$kHmZTqomReyTGf6x INDEX
Gpa9GQ==$2

BIN$gtl8hEtDTwyJSJRw INDEX
zqxFjQ==$0

BIN$lBwhR7ckQVmBoQJC INDEX
jyJTxg==$2

AVGSALARYFORDEPT     PROCEDURE
RAISEDSALARYBYEMPNOP PROCEDURE
ROC

ADD_DEPT_PROC        PROCEDURE
EMPCOPY              TABLE
TMP                  TABLE
DEPT                 TABLE
SALGRADE             TABLE
BONUS                TABLE
EMP                  TABLE
EMP_VW               VIEW

已选择14行。

SQL> create or replace package employee_pkg is
  2  
  3    -- Author  : ADMINISTRATOR
  4    -- Created : 2010-6-17 上午 09:19:27
  5    -- Purpose : This is a demo.
  6    
  7  end employee_pkg;
  8  /

程序包已创建。

SQL> create or replace package body employee_pkg is
  2  
  3  
  4  end employee_pkg;
  5  /

程序包体已创建。

SQL> select object_name,object_type from user_objects
  2  order by object_type asc;

OBJECT_NAME          OBJECT_TYPE
-------------------- --------------------
TAX                  FUNCTION
BIN$gtl8hEtDTwyJSJRw INDEX
zqxFjQ==$0

BIN$lBwhR7ckQVmBoQJC INDEX
jyJTxg==$2

BIN$kHmZTqomReyTGf6x INDEX
Gpa9GQ==$2

EMPLOYEE_PKG         PACKAGE
EMPLOYEE_PKG         PACKAGE BODY
RAISEDSALARYBYEMPNOP PROCEDURE
ROC

AVGSALARYFORDEPT     PROCEDURE
ADD_DEPT_PROC        PROCEDURE
EMPCOPY              TABLE
SALGRADE             TABLE
EMP                  TABLE
BONUS                TABLE
TMP                  TABLE
DEPT                 TABLE
EMP_VW               VIEW

已选择16行。

SQL> create or replace package employee_pkg is
  2  
  3    -- Author  : ADMINISTRATOR
  4    -- Created : 2010-6-17 上午 09:19:27
  5    -- Purpose : This is a demo.
  6    
  7    procedure   print_ename(p_empno emp.empno%type);
  8    
  9    --编写一个函数,用户校验输入的用户编号是否有效
 10    function    isValiad(p_empno emp.empno%type) return  boolean;
 11    
 12  end employee_pkg;
 13  /

程序包已创建。

SQL> create or replace package body employee_pkg is
  2  
  3    procedure   print_ename(p_empno emp.empno%type)
  4    is
  5    begin
  6        null;
  7    end print_ename;
  8    
  9    --编写一个函数,用户校验输入的用户编号是否有效
 10    function    isValiad(p_empno emp.empno%type) return  boolean
 11    is 
 12    begin
 13      
 14        return false;
 15    
 16    end isValiad;
 17  
 18  end employee_pkg;
 19  /

程序包体已创建。

SQL>  select object_name,object_type from user_objects
  2   order by object_type asc;

OBJECT_NAME          O