Oracle ——存储过程
1、带参数的存储过程,没有返回值
CREATE OR REPLACE PROCEDURE sp_pro2 (spname VARCHAR2, newsal NUMBER) IS
BEGIN
UPDATE emp SET sal = newsal WHERE ename=spname;
END;
--参数VARCHAR2不需要指定大小
exec sp_pro2('SMITH',10);
或者call sp_pro2('SMITH',10);
--IN表示输入参数,默认
--OUT表示输出参数
CREATE OR REPLACE PROCEDURE sp_pro9
(bookId IN NUMBER,bookName IN VARCHAR2, publishHouse IN VARCHAR2) IS
BEGIN
INSERT INTO book VALUES(bookId,bookName,publishHouse);
END;
2、带参数的存储过程,有返回值 单一值
--OUT表示输出参数
CREATE OR REPLACE PROCEDURE sp_pro10
(sp_empno IN NUMBER,sp_ename OUT VARCHAR2, sp_sal OUT NUMBER) IS
BEGIN
SELECT ename,sal INTO sp_ename,sp_sal FROM emp WHERE sp_empno=empno;
END;
3、带参数的存储过程,有返回值 返回结果集合
(1)创建一个包
CREATE OR REPLACE PACKAGE test_package IS
TYPE test_cursor IS REF CURSOR;
END test_package;
(2)建立存储过程
CREATE OR REPLACE PROCEDURE pro_getSet
(sp_deptNo IN NUMBER, sp_emps OUT test_package.test_cursor) IS
BEGIN
OPEN sp_emps FOR SELECT * FROM emp WHERE emp.deptno = sp_deptNo;
END;
posted on 2014-04-28 21:58 Sunny_NUAA 阅读(108) 评论(0) 编辑 收藏 举报