CREATE [OR REPLACE] PROCEDURE procedure_name ([arg1 [ IN | OUT | IN OUT ]] type1 [DEFAULT value1], [arg2 [ IN | OUT | IN OUT ]] type2 [DEFAULT value1]], ...... [arg [ IN | OUT | IN OUT ]] type [DEFAULT value]) [ AUTHID DEFINER | CURRENT_USER ]
IS|AS
<声明部分>
BEGIN
<执行部分>
EXCEPTION
<可选的异常错误处理程序>
END procedure_name;
示例:
CREATE OR REPLACE PROCEDURE DelEmp (v_empno IN employees.employee_id%TYPE)
AS
No_result EXCEPTION;
BEGIN
DELETEFROM employees
WHERE employee_id = v_empno;
IF SQL%NOTFOUND THEN
RAISE no_result;
ENDIF;
DBMS_OUTPUT.PUT_LINE('编码为'||v_empno||'的员工已被删除!');
EXCEPTION
WHEN no_result THEN
DBMS_OUTPUT.PUT_LINE('温馨提示:你需要的数据不存在!');
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLCODE||'---'||SQLERRM);
END DelEmp;
调用:
EXEC[UTE] procedure_name( parameter1, parameter2…);
示例:
execute 存储过程名