PL/SQL supports the deletion of packages and provides information about packages for management.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only MySQL-compatible mode.
Delete a package
You can run the DROP PACKAGE statement to delete an unnecessary package. The syntax is as follows:
DROP PACKAGE [BODY] [user.]package_name;
Here is an example:
obclient>DROP PACKAGE obdemo_pack1;
Query OK, 0 rows affected
Manage packages
You can query the following package-related views to obtain information about packages:
USER_OBJECTS: queries database objects. You can use this view to list the names, current statuses, and creation times of packages.Notice
A package (
PACKAGE) and a package body (PACKAGE BODY) are objects of different types.USER_SOURCE: queries the contents of a package and its body.USER_ERRORS: queries the error messages generated during the last compilation of a package or its body.
Example 1: Query the statuses and creation times of all packages under the current user.
obclient> SELECT OBJECT_NAME,OBJECT_TYPE,CREATED,STATUS
FROM USER_OBJECTS WHERE OBJECT_TYPE LIKE 'PACKAGE%';
+-------------+-------------+-----------+---------+
| OBJECT_NAME | OBJECT_TYPE | CREATED | STATUS |
+-------------+-------------+-----------+---------+
| DEMO_PACK | PACKAGE | 17-DEC-20 | INVALID |
+-------------+-------------+-----------+---------+
1 row in set
Example 2: Query the content of the package body of the package named OBDEMO_PACK .
obclient> SELECT TEXT FROM USER_SOURCE
WHERE TYPE='PACKAGE BODY'
AND NAME='OBDEMO_PACK'\G
*************************** 1. row ***************************
TEXT: PACKAGE BODY obdemo_pack
IS
FUNCTION add_obdept(dept_no NUMBER, dept_name VARCHAR2, location VARCHAR2)
RETURN NUMBER
IS
deptno_remaining EXCEPTION;
PRAGMA EXCEPTION_INIT(deptno_remaining, -1);
BEGIN
INSERT INTO obdept VALUES(dept_no, dept_name, location);
IF SQL%FOUND THEN
RETURN 1;
END IF;
EXCEPTION
WHEN deptno_remaining THEN
RETURN 0;
WHEN OTHERS THEN
RETURN -1;
END add_obdept;
FUNCTION remove_obdept(dept_no NUMBER)
RETURN NUMBER
IS
BEGIN
DELETE FROM obdept WHERE deptno=dept_no;
IF SQL%FOUND THEN
RETURN 1;
ELSE
RETURN 0;
END IF;
EXCEPTION
WHEN OTHERS THEN
RETURN -1;
END remove_obdept;
PROCEDURE query_obdept (dept_no IN NUMBER)
IS
BEGIN
SELECT * INTO obDeptRec FROM obdept WHERE deptno=dept_no;
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('Database does not contain a department with the code of'||dept_no||'.');
WHEN TOO_MANY_ROWS THEN
DBMS_OUTPUT.PUT_LINE('Runtime error!');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLCODE||'----'||SQLERRM);
END query_obdept;
BEGIN
Null;
END obdemo_pack
1 row in set
Example 3: Query the error messages and locations generated during the last compilation of the package PKG .
obclient> CREATE OR REPLACE PACKAGE pkg IS v vvv;
END;
/
Query OK, 0 rows affected, 1 warning
obclient> SELECT LINE,POSITION,TEXT FROM USER_ERRORS
WHERE NAME='PKG' AND TYPE='PACKAGE';
+------+----------+------------------------------------------------------------------------+
| LINE | POSITION | TEXT |
+------+----------+------------------------------------------------------------------------+
| 0 | 34 | OBE-00600: internal error code, arguments: -5544, Undeclared type: VVV |
+------+----------+------------------------------------------------------------------------+