[20190531]建立job与commit.txt

[20190531]建立job与commit.txt

--//昨天看链接:https://connor-mcdonald.com/2019/05/28/dbms_job-the-joy-of-transactions/
--//我个人并不关心升级到19c后废除DBMS_JOB包使用新的Scheduler,不过对建立job与提交有了新的理解。
--//为什么建立job后,随手做一个提交。

1.环境:
SCOTT@test01p> @ ver1
PORT_STRING          VERSION    BANNER                                                                       CON_ID
-------------------- ---------- ---------------------------------------------------------------------------- ------
IBMPC/WIN_NT64-9.1.0 12.2.0.1.0 Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production      0

2.测试:
declare
  j int;
begin
  dbms_job.submit(j,'begin null; end;',sysdate,'sysdate+1');
end;
/

SCOTT@test01p> select job, what c40 from user_jobs;
JOB C40
--- ----------------------------------------
  1 begin null; end;

SCOTT@test01p> @ xid
XIDUSN_XIDSLOT_XIDSQN
------------------------------
3.2.984
--//可以发现本会话有事务没有提交.

SCOTT@test01p> select job_name, job_action from user_scheduler_jobs;
no rows selected

SCOTT@test01p> rollback;
Rollback complete.

SCOTT@test01p> @ xid
XIDUSN_XIDSLOT_XIDSQN
------------------------------

no rows selected

SCOTT@test01p> select job, what c40 from user_jobs;
no rows selected

--//也就是你没有提交,这个job永远不会执行.以前一直不理解为什么,原来原因如此简单.

3.xid脚本:
$ cat xid.sql
column XIDUSN_XIDSLOT_XIDSQN format a30
select dbms_transaction.local_transaction_id()  XIDUSN_XIDSLOT_XIDSQN from dual ;

原文地址:https://www.cnblogs.com/lfree/p/10953245.html