Home  >  Article  >  Database  >  函数中有插入语句解决自治事务

函数中有插入语句解决自治事务

WBOY
WBOYOriginal
2016-06-07 15:28:241743browse

要创建一个自治事务,您必须在匿名块的最高层或者存储过程、函数、数据包或触发的定义部分中,使用PL/SQL中的PRAGMA AUTONOMOUS_TRANSACTION语句。在这样的模块或过程中执行的SQL Server语句都是自治的。 例子 create or replace function sms_send(v_mobile

要创建一个自治事务,您必须在匿名块的最高层或者存储过程、函数、数据包或触发的定义部分中,使用PL/SQL中的PRAGMA AUTONOMOUS_TRANSACTION语句。在这样的模块或过程中执行的SQL Server语句都是自治的。

例子

create or replace function sms_send(v_mobile_no varchar2, --电话号码
v_dx_content varchar2 --短信内容

)
return varchar2 is
pragma autonomous_transaction;
v_result integer;
v_msg varchar2(100);
v_exception Exception;
BEGIN
v_msg := 'OK';
--往中间短信发送表插入发送数据
v_msg := '发送失败!';
v_result := -10;
INSERT INTO TABLE VALUES('','');
commit;
return 'OK';
END;

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn