[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 ;sql