--创建一个包(SP_PACKAGE1):包括包头和包体,名字均为包名
--创建一个包头:SP_PACKAGE1
--该包体申明有一个存储过程:UPDATESALBYNO(根据empno修改该雇员的sal)
--该包体申明有一个函数:ANNUA_INCOME(根据ename查询该雇员的年薪)
CREATE OR REPLACE PACKAGE SP_PACKAGE1 IS
PROCEDURE UPDATESALBYNO(NEWSALARY NUMBER(4),EMPNUBER NUMBER(4));
FUNCTION ANNUA_INCOME(NAME VARCHAR2) RETURN NUMBER(7,2);
END;
--创建包体,即定义好在包头中申明的存储过程以及函数
CREATE OR REPLACE PACKAGE BODY SP_PACKAGE1 IS
PROCEDURE UPDATESALBYNO(NEWSALARY NUMBER(4),EMPNUBER NUMBER(4)) IS
BEGIN
UPDATE EMP SET SAL = NEWSALARY WHERE EMPNO = EMPNUBER;
END;
FUNCTION ANNUA_INCOME(NAME VARCHAR2)
RETURN NUMBER(7,2) IS ANNUA_SAL NUMBER(7,2);
BEGIN
SELECT SAL*12+NVL(COMM,0) INTO ANNUA_SAL FROM EMP WHERE ENAME = NAME;
RETURN ANNUA_SAL;
END;
END;
--调用包中的存储过程
EXEC SP_PACKAGE1.UPDATESALBYNO(120,886);
怎么会报错呢?!感觉是对的啊,
PACKAGE SP_PACKAGE1 compiled
Errors: check compiler log
PACKAGE BODY SP_PACKAGE1 compiled
Errors: check compiler log
Error starting at line : 83 in command -
EXEC SP_PACKAGE1.UPDATESALBYNO(120,886)
Error report -
ORA-06550: line 1, column 7:
PLS-00905: object SCOTT.SP_PACKAGE1 is invalid
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
------解决方案--------------------
兄弟你看下这个对不对
--创建一个包(SP_PACKAGE1):包括包头和包体,名字均为包名
--创建一个包头:SP_PACKAGE1
--该包体申明有一个存储过程:UPDATESALBYNO(根据empno修改该雇员的sal)
--该包体申明有一个函数:ANNUA_INCOME(根据ename查询该雇员的年薪)
CREATE OR REPLACE PACKAGE SP_PACKAGE1 IS
PROCEDURE UPDATESALBYNO(NEWSALARY NUMBER,EMPNUBER NUMBER);
FUNCTION ANNUA_INCOME(NAME VARCHAR2) RETURN NUMBER;
END;
--创建包体,即定义好在包头中申明的存储过程以及函数
CREATE OR REPLACE PACKAGE BODY SP_PACKAGE1 IS
PROCEDURE UPDATESALBYNO(NEWSALARY NUMBER,EMPNUBER NUMBER)
IS
BEGIN
UPDATE EMP SET SAL = NEWSALARY WHERE EMPNO = EMPNUBER;
END;
FUNCTION ANNUA_INCOME(NAME VARCHAR2)
RETURN NUMBER IS ANNUA_SAL NUMBER;
BEGIN
SELECT SAL*12+NVL(COMM,0) INTO ANNUA_SAL FROM EMP WHERE ENAME = NAME;
RETURN ANNUA_SAL;
END;
END;
--调用包中的存储过程
EXEC SP_PACKAGE1.UPDATESALBYNO(1020,886);
------解决方案--------------------