一、存储过程创建
create or replace sp_test(
v_date_in in varchar2,--入参(入参个数0-N)
v_ret_out out varchar2--出参(出参个数0-N)
) is
--自定义参数
v_count int;
v_code varhar2(100);
begin
--此段写业务sql
--示例
execute immediate 'truncate table tbl_test';--清空表数据
--执行新增
insert into tbl_test(id,name)values(1,'张三');
commit;--提交
--示例结束
--异常处理
exception
when others then
--记录日志
insert into al_log(id,create_date,sp_name,error_msg)values(主键,日期,存储过程名,错误信息);
rollback;--回滚
end sp_test;
/
二、存储过程调用方式
1.没有出参的情况直接用call: call sp_test(填写入参);
2.存在出参使用declare:
declare
v_ret_out varchar2(100);
begin
sp_test('20240731',v_ret_out);
dbms_output.put_line(v_ret_out);--输出
end;
25万+

被折叠的 条评论
为什么被折叠?



