标签:ini main -- 没有 others 错误 func line proc
CREATE OR REPLACE PACKAGE demo_pack --创建包定义 IS DeptRec dept%ROWTYPE; FUNCTION add_dept( --声明一个方法 dept_no NUMBER, dept_name VARCHAR2, location VARCHAR2) RETURN NUMBER; FUNCTION remove_dept(dept_no NUMBER) --声明另个方法 RETURN NUMBER; PROCEDURE query_dept(dept_no IN NUMBER); END demo_pack; CREATE OR REPLACE PACKAGE BODY demo_pack --创建包体 IS FUNCTION add_dept --实现包定义的方法 (dept_no NUMBER, dept_name VARCHAR2, location VARCHAR2) RETURN NUMBER IS empno_remaining EXCEPTION; PRAGMA EXCEPTION_INIT(empno_remaining, -1); BEGIN INSERT INTO dept VALUES(dept_no, dept_name, location); IF SQL%FOUND THEN RETURN 1; END IF; EXCEPTION WHEN empno_remaining THEN RETURN 0; WHEN OTHERS THEN RETURN -1; END add_dept; FUNCTION remove_dept(dept_no NUMBER) --实现包定义的另一方法 RETURN NUMBER IS BEGIN DELETE FROM dept WHERE deptno=dept_no; IF SQL%FOUND THEN RETURN 1; ELSE RETURN 0; END IF; EXCEPTION WHEN OTHERS THEN RETURN -1; END remove_dept; PROCEDURE query_dept (dept_no IN NUMBER) IS BEGIN SELECT * INTO DeptRec FROM dept WHERE deptno=dept_no; EXCEPTION WHEN NO_DATA_FOUND THEN DBMS_OUTPUT.PUT_LINE(‘数据库中没有编码为‘||dept_no||‘的部门‘); WHEN TOO_MANY_ROWS THEN DBMS_OUTPUT.PUT_LINE(‘程序运行错误!请使用游标‘); WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE(SQLCODE||‘----‘||SQLERRM); END query_dept; END demo_pack; DECLARE --调用包 Var NUMBER; BEGIN Var := demo_pack.add_dept(80,‘阿晨‘, ‘西安‘); IF var =-1 THEN DBMS_OUTPUT.PUT_LINE(SQLCODE||‘----‘||SQLERRM); ELSIF var =0 THEN DBMS_OUTPUT.PUT_LINE(‘该部门记录已经存在!‘); ELSE DBMS_OUTPUT.PUT_LINE(‘添加记录成功!‘); Demo_pack.query_dept(80); DBMS_OUTPUT.PUT_LINE(demo_pack.DeptRec.deptno||‘---‘|| demo_pack.DeptRec.dname||‘---‘||demo_pack.DeptRec.loc); var := demo_pack.remove_dept(80); IF var =-1 THEN DBMS_OUTPUT.PUT_LINE(SQLCODE||‘----‘||SQLERRM); ELSIF var=0 THEN DBMS_OUTPUT.PUT_LINE(‘该部门记录不存在!‘); ELSE DBMS_OUTPUT.PUT_LINE(‘删除记录成功!‘); END IF; END IF; END;
标签:ini main -- 没有 others 错误 func line proc
原文地址:http://www.cnblogs.com/wx1691790309/p/7270322.html