pragma autonomous_transaction : restrict_references(<fuctionname>,wnds) and serially_resumable

pragma : serially_reusable


SQL> CREATE PACKAGE pkg1 IS

   PRAGMA SERIALLY_REUSABLE;
    num NUMBER := 0;
   PROCEDURE init_pkg_state(n NUMBER);
   PROCEDURE print_pkg_state;
END pkg1;
/  2    3    4    5    6    7


Package created.


SQL> CREATE PACKAGE BODY pkg1 IS
    PRAGMA SERIALLY_REUSABLE;
   PROCEDURE init_pkg_state (n NUMBER) IS
   BEGIN
      pkg1.num := n;
   END;
   PROCEDURE print_pkg_state IS
   BEGIN
      dbms_output.put_line('Num: ' || pkg1.num);
   END;
END pkg1;
/  2    3    4    5    6    7    8    9   10   11   12


Package body created.


SQL>
SQL>
SQL> exec pkg1.init_pkg_state(10);


PL/SQL procedure successfully completed.

SQL> exec pkg1.print_pkg_state;
Num: 0


PL/SQL procedure successfully completed.


pragma :autonomous_transaction

SQL> create table t(ab date);


Table created.


SQL> create or replace package pkg2 is
             function fn_auto return number;
           end pkg2;
/  2    3    4


Package created.


SQL> create or replace package body pkg2 is
            function fn_auto return number
             is
            begin
                insert into t values(sysdate);
                commit;
                return 1;
            end;
         end pkg2;
 /  2    3    4    5    6    7    8    9   10


Package body created.


SQL>  select pkg2.fn_auto() test from dual;
 select pkg2.fn_auto() test from dual
        *
ERROR at line 1:
ORA-14551: cannot perform a DML operation inside a query
ORA-06512: at "QDL.PKG2", line 5


SQL> create or replace package body pkg2 is
function fn_auto return number
is
pragma autonomous_transaction;
begin
insert into t values(systimestamp);
commit;
 return 1;
end;
end pkg2;
/  2    3    4    5    6    7    8    9   10   11


Package body created.


SQL>  select pkg2.fn_auto() test from dual;


      TEST
----------
         1


pragma :restrict_references(fn_auto,wnds)

make the compiler compile the function fn_auto according to WNDS (write no database ) , so after the package boday created, you see the compile error directly.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值