[Oracle]Simple Package 指令集
宣告
1: DROP PACKAGE ABC;
2:
3: CREATE OR REPLACE PACKAGE ABC
4: AS
5: PROCEDURE SP
6: (
7: PARAM IN varchar2,
8: RESULT OUT NUMBER
9: ) ;
10:
11: FUNCTION FN
12: (
13: PARAM IN varchar2
14: ) RETURN NUMBER ;
15:
16: END ABC;
建立
1: CREATE OR REPLACE PACKAGE BODY ABC
2: AS
3:
4: PROCEDURE SP
5: (
6: PARAM IN varchar2,
7: RESULT OUT NUMBER
8: )
9: IS
10:
11: BEGIN
12: RESULT := LENGTH(PARAM);
13: END SP;
14:
15:
16: FUNCTION FN
17: (
18: PARAM IN varchar2
19: ) RETURN NUMBER
20: IS
21: BEGIN
22: RETURN LENGTH(PARAM);
23: END FN;
24:
25: END ABC;
執行
1: set serveroutput on;
2:
3: DECLARE
4: PARAM varchar2(10);
5: RESULT NUMBER(10);
6: BEGIN
7: PARAM:='Hector' ;
8: ABC.SP(PARAM,RESULT);
9: DBMS_OUTPUT.PUT_LINE(RESULT);
10: PARAM:='Lee' ;
11: SELECT ABC.FN(PARAM) INTO RESULT FROM DUAL;
12: DBMS_OUTPUT.PUT_LINE(RESULT);
13:
14: END;
1: SELECT * FROM USER_ERRORS;
修改
沒有指令可以對 Package 加入 Procedure / Function. 但有幾個重新編譯指令會經常性使用.
1: ALTER PACKAGE ABC COMPILE PACKAGE ;
2: ALTER PACKAGE ABC COMPILE BODY ;