01. 新建包
02. 加入/修改项
03. 删除项
04. 访问项
05. 查询包
06. 删除包
==============
01. 新建包
------------
进行创建:
SQL> CREATE PACKAGE ADDFUN_PKG
2 IS
3 END ADDFUN_PKG;
4 /
程序包已创建。
进行包对象查看:
SQL> SELECT SUBSTR(OBJECT_NAME,0,10),STATUS,OBJECT_TYPE
2 FROM USER_OBJECTS;
SUBSTR(OBJECT_NAME,0 STATUS OBJECT_TYPE
-------------------- ------- ------------------
ADDFUN_PKG VALID PACKAGE
SP_STUDENT VALID PROCEDURE
STUDENT VALID TABLE
V_STUDENT VALID VIEW
或:
SQL> SELECT SUBSTR(OBJECT_NAME,0,10),STATUS,OBJECT_TYPE
2 FROM USER_OBJECTS
3 WHERE OBJECT_TYPE='PACKAGE';
SUBSTR(OBJECT_NAME,0 STATUS OBJECT_TYPE
-------------------- ------- ------------------
ADDFUN_PKG VALID PACKAGE
02. 加入/修改项
----------------
SQL> CREATE OR REPLACE PACKAGE ADDFUN_PKG
2 AS
3 FUNCTION FN_ADDONE(ANUM NUMBER) RETURN NUMBER;
4 END;
5 /
程序包已创建。
SQL> CREATE OR REPLACE PACKAGE BODY ADDFUN_PKG
2 AS
3
4 FUNCTION FN_ADDONE(ANUM NUMBER) RETURN NUMBER
5 AS
6 BNUM NUMBER;
7 BEGIN
8 BNUM := ANUM + 1;
9 RETURN BNUM ;
10 END FN_ADDONE;
11
12 END ADDFUN_PKG;
13 /
程序包主体已创建。
03. 删除项
------------
需要重新定义包头及包体
需要查询包体:
04. 访问项
------------
SQL> SELECT USER1_ADB.ADDFUN_PKG.FN_ADDONE(2) AS VALUE FROM DUAL;
VALUE
----------
3
05. 查询包
----------
SQL> SELECT TEXT FROM USER_SOURCE
2 WHERE NAME='ADDFUN_PKG'
3 AND TYPE='PACKAGE BODY';
TEXT
----------------------------------------------------------
PACKAGE BODY ADDFUN_PKG
AS
FUNCTION FN_ADDONE(ANUM NUMBER) RETURN NUMBER
AS
BNUM NUMBER;
BEGIN
BNUM := ANUM + 1;
RETURN BNUM ;
END;
TEXT
----------------------------------------------------------
FUNCTION FN_ADDTWO(ANUM NUMBER) RETURN NUMBER
AS
BNUM NUMBER;
BEGIN
BNUM := ANUM + 2;
RETURN BNUM ;
END;
END ADDFUN_PKG;
已选择20行。
或:
SQL> SET LONG 1000
SQL> SET PAGES 1
SQL> SELECT DBMS_METADATA.GET_DDL('PACKAGE','ADDFUN_PKG') FROM DUAL;
06. 删除包
SQL> DROP PACKAGE ADDFUN_PKG;
程序包已丢弃。