直接上**:
是在包裡寫的儲存過程,要測試的話,要先寫宣告
宣告
procedure test1(p_retcode in out varchar2, p_retinfo in out varchar2);
procedure test2(p_retcode in out varchar2, p_retinfo in out varchar2);
procedure test3(p_retcode in out varchar2, p_retinfo in out varchar2);
實現
procedure test1(p_retcode in out varchar2, p_retinfo in out varchar2) is
biz_exception exception;
begin
insert into tree_tb (id, node_name) values ('1', '1');
p_retcode := '1';
p_retinfo := 'test1插入成功。';
exception
when biz_exception then
p_retcode := '-1';
p_retinfo := '自定義異常1';
rollback;
when others then
p_retcode := sqlcode;
p_retinfo := substr(sqlerrm, 1, 1000);
dbms_output.put_line('error code ' || p_retcode || ': ' || p_retinfo);
rollback;
end;
procedure test2(p_retcode in out varchar2, p_retinfo in out varchar2) is
biz_exception exception;
begin
insert into tree_tb (id, node_name) values ('2', '2');
insert into tree_tb (id, node_name) values ('3', '3');
raise biz_exception;
insert into tree_tb (id, node_name) values ('4', '4');
p_retcode := '1';
p_retinfo := 'test2插入成功。';
exception
when biz_exception then
p_retcode := '-2';
p_retinfo := '自定義異常2';
rollback;
when others then
p_retcode := sqlcode;
p_retinfo := substr(sqlerrm, 1, 1000);
dbms_output.put_line('error code ' || p_retcode || ': ' || p_retinfo);
rollback;
end;
/*** @功能描述: 測試儲存過程同時調多個儲存過程時的事務原子性與一致性
* @param retcode out 返回編碼
* @param retinfo out 返回編碼對應的資訊
*/procedure test3(p_retcode in out varchar2, p_retinfo in out varchar2) is
biz_exception exception;
begin
test1(p_retcode, p_retinfo);
test2(p_retcode, p_retinfo);
exception
when biz_exception then
rollback;
when others then
p_retcode := sqlcode;
p_retinfo := substr(sqlerrm, 1, 1000);
dbms_output.put_line('error code ' || p_retcode || ': ' || p_retinfo);
rollback;
end;
以上寫法可回滾。 Sql 儲存過程 事務
alter procedure dbo usp pe delworklogbill id varchar 50 companycode varchar 50 asdeclare errno int set errno 0 begin tran 開始執行事務 delete from opeworklo...
事務和儲存過程
事務 同生共死 指訪問並可能更新資料庫中各種資料項的乙個程式執行單元 unit 也就是由多個sql語句組成,必須作為乙個整體執行 這些sql語句作為乙個整體一起向系統提交,要麼都執行 要麼都不執行 語法步驟 開始事務 begin transaction 事務提交 commit transaction...
儲存過程和事務
在儲存過程中使用事務時非常重要的,使用資料可以保持資料的關聯完整性,在sql server儲存過程中使用事務也很簡單,我們先來簡單了解一下儲存過程和事務,然後用乙個例子來簡單說明他們的用法 儲存過程 事務 以學生註冊資訊為例 create procedure dbo proc sturegister...