{"id":1337,"date":"2017-04-17T15:19:39","date_gmt":"2017-04-17T07:19:39","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=1337"},"modified":"2017-04-17T15:19:39","modified_gmt":"2017-04-17T07:19:39","slug":"oracle-job%e5%ae%9a%e6%97%b6%e5%99%a8-%e7%94%a8%e6%b3%95","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=1337","title":{"rendered":"Oracle job\u5b9a\u65f6\u5668 \u7528\u6cd5"},"content":{"rendered":"<p>\n\t\u5728\u505a\u67d0\u4e9b\u4e1a\u52a1\u65f6\uff0c\u9700\u8981\u7528\u5230 <a href=\"https:\/\/www.oracle.com\/index.html\" name=\"Oracle\" target=\"_blank\" title=\"Oracle\">Oracle<\/a> \u7684\u5b9a\u65f6\u4efb\u52a1\u529f\u80fd\u3002\u8fd9\u4e00\u822c\u90fd\u662f <a href=\"http:\/\/baike.baidu.com\/item\/\u6570\u636e\u5e93\u7ba1\u7406\u5458\/1216449\" name=\"\u6570\u636e\u5e93\u7ba1\u7406\u5458\" target=\"_blank\" title=\"\u6570\u636e\u5e93\u7ba1\u7406\u5458\">DBA<\/a> \u6765\u5b8c\u6210\u7684\uff0c\u4f46\u662f\u4f5c\u4e3a\u5f00\u53d1\u8005\u6211\u4eec\u8fd8\u662f\u6709\u5fc5\u8981\u719f\u7ec3\u7684\u638c\u63e1\u7684\u3002\u4e0b\u9762\u5c06\u5206\u4eab\u4e00\u4e9b Oracle job\u7684\u7528\u6cd5\u5fc3\u5f97\u3002\n<\/p>\n<p>\n\t\u987e\u540d\u601d\u4e49\uff0c\u5b9a\u65f6\u5668\u5c31\u662f\u5b9a\u65f6\u6765\u5b8c\u6210\u67d0\u4e9b\u64cd\u4f5c\uff0coracle \u4e2d\u7684\u5b9a\u65f6\u5668 job \u4e5f\u662f\u8fd9\u79cd\u7528\u6cd5\uff0c\u5728 oracle \u4e2d\u53ef\u4ee5\u901a\u8fc7\u5b9a\u4e49 job \u6765\u5b9a\u671f\u6267\u884c\u67d0\u4e2a\u7a0b\u5e8f\u3002oracle \u63d0\u4f9b\u5185\u7f6e\u5305 <a href=\"http:\/\/baike.baidu.com\/item\/DBMS_JOB\" name=\"DBMS_JOB\" target=\"_blank\" title=\"DBMS_JOB\">DBMS_JOB<\/a> \u6765\u6267\u884cjob\u7684\u76f8\u5173\u64cd\u4f5c\uff0c\u6bd4\u5982\u5b9a\u4e49\u3001\u63d0\u4ea4\u3001\u66f4\u6539\u3001\u505c\u6b62\u3001\u79fb\u9664\u7b49\u3002\n<\/p>\n<h2>\n\t\u521b\u5efa \u4f5c\u4e1a job<br \/>\n<\/h2>\n<p>\n\t\u521b\u5efa Oracle \u4f5c\u4e1a job \u9700\u8981\u7528\u5230 submit() \u8fc7\u7a0b\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\u67095\u4e2a\u53c2\u6570\uff1ajob\u3001what\u3001next_date\u3001interval\u3001no_parse\u3002\n<\/p>\n<pre class=\"brush:sql;\">\r\nprocedure submit(\r\n\tjob out binary_integer,\r\n\twhat in varchar2,\r\n\tnext_date in date,\r\n\tinterval in varchar2,\r\n\tno_parse in boolean:= FALSE\r\n);<\/pre>\n<p>\n\tsubmit()\u8fc7\u7a0b\u7684\u53c2\u6570\u8bf4\u660e\u5982\u4e0b\uff1a\n<\/p>\n<ul>\n<li>\n\t\tjob\u53c2\u6570\u662f\u7531submit()\u8fc7\u7a0b\u8fd4\u56de\u7684binary_integer\uff0c\u8fd9\u4e2a\u503c\u7528\u6765\u552f\u4e00\u6807\u8bc6\u4e00\u4e2a\u5de5\u4f5c\uff1b\n\t<\/li>\n<li>\n\t\twhat\u53c2\u6570\u662f\u5c06\u88ab\u6267\u884c\u7684pl\/sql\u4ee3\u7801\u5757\uff1b\n\t<\/li>\n<li>\n\t\tnext_date\u53c2\u6570\u6307\u4f55\u65f6\u5c06\u8fd0\u884c\u8fd9\u4e2a\u5de5\u4f5c\uff1b\n\t<\/li>\n<li>\n\t\tinterval\u53c2\u6570\u6307\u4f55\u65f6\u8fd9\u4e2a\u5de5\u4f5c\u518d\u6b21\u88ab\u6267\u884c\uff0c\u5f53interval\u8bbe\u7f6e\u4e3anull\u65f6\uff0c\u8be5job\u6267\u884c\u7ed3\u675f\u4ee5\u540e\uff0c\u5c31\u88ab\u4ece\u961f\u5217\u4e2d\u5220\u9664\uff1b\n\t<\/li>\n<li>\n\t\tno_parse\u53c2\u6570\u6307\u6b64\u5de5\u4f5c\u5728\u63d0\u4ea4\u6216\u6267\u884c\u65f6\u662f\u5426\u5e94\u8fdb\u884c\u8bed\u6cd5\u5206\u6790\uff0c\u9ed8\u8ba4\u503c\u4e3afalse\uff0c\u8868\u793a\u7b28pl\/sql\u4ee3\u7801\u5e94\u8be5\u7acb\u5373\u8fdb\u884c\u8bed\u6cd5\u5206\u6790\u3002\n\t<\/li>\n<\/ul>\n<p>\n\t\u4e0b\u9762\u4e3a\u521b\u5efa job \u7684\u4e00\u4e2a\u5177\u4f53\u5b9e\u4f8b\uff1a\n<\/p>\n<pre class=\"brush:sql;\">\r\nDECLARE\r\n  jobno NUMBER;\r\nBEGIN\r\n  dbms_job.submit(job       =&gt; jobno,\r\n                  what      =&gt; &#039;OVER_PACK.ADD_DEPT(&#039;&#039;EDUCATION&#039;&#039;,2710);&#039;,\r\n                  next_date =&gt; trunc(SYSDATE + 1),\r\n                  INTERVAL  =&gt; &#039;TRUNC(SYSDATE + 1)&#039;);\r\n  dbms_output.put_line(&#039;job_no = &#039; || jobno);\r\n  COMMIT;\r\nEND;<\/pre>\n<h2>\n\t\u67e5\u770b job<br \/>\n<\/h2>\n<p>\n\t\u67e5\u770b\u76f8\u5173\u7684job\u4fe1\u606f\uff0c\u53ef\u67e5\u8be2\u4ee5\u4e0b\u5bf9\u8c61\uff1adba_jobs\u3001all_jobs\u3001user_jobs\u3001dba_jobs_running\uff08\u6b63\u5728\u8fd0\u884c\u7684job\u4fe1\u606f\uff09\u3002\n<\/p>\n<pre class=\"brush:sql;\">\r\n--\u67e5\u770bjob  \r\nselect * from sys.user_jobs <\/pre>\n<h2>\n\t\u8fd0\u884c job<br \/>\n<\/h2>\n<p>\n\t\u8fd0\u884cjob\u901a\u8fc7dbms_job.run()\u6765\u7acb\u5373\u6267\u884c\u4e00\u4e2a\u6307\u5b9a\u7684\u5de5\u4f5c\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u53ea\u63a5\u6536\u4e00\u4e2a\u53c2\u6570\u3002\n<\/p>\n<pre class=\"brush:sql;\">\r\nBEGIN\r\n    dbms_job.run(jobno); -- jobno\u5c31\u662f\u4e0a\u9762\u5b9a\u4e49\u8fc7\u7684jobno\r\nEND;<\/pre>\n<h2>\n\t\u4fee\u6539\u6539 job<br \/>\n<\/h2>\n<pre class=\"brush:sql;\">\r\nBEGIN\r\n  DBMS_JOB.CHANGE(1, NULL, TRUNC(SYSDATE + 1) + 6 \/ 24, &#039;SYSDATE+4\/24&#039;);\r\nEND;<\/pre>\n<h2>\n\t\u5220\u9664 job<br \/>\n<\/h2>\n<pre class=\"brush:sql;\">\r\nBEGIN\r\n    dbms_job.remove(jobno);\r\nEND;<\/pre>\n<h2>\n\t\u505c\u6b62 job<br \/>\n<\/h2>\n<pre class=\"brush:sql;\">\r\n---\u505c\u6b62job  25\u662f\u5efa\u7acb\u7684job test_job_really  \r\nbegin  \r\ndbms_job.broken(25,true);  \r\ncommit;  \r\nend;  \r\n--\u505c\u6b62\u4e00\u4e2ajob,\u91cc\u9762\u53c2\u6570true\u4e5f\u53ef\u662ffalse\uff0cnext_date\uff08\u67d0\u4e00\u65f6\u523b\u505c\u6b62\uff09\u4e5f\u53ef\u662fsysdate\uff08\u7acb\u523b\u505c\u6b62\uff09\u3002  \r\ndbms_job.broke(v_job,true,next_date); <\/pre>\n<h2>\n\t\u4fee\u6539 job \u7684\u4e0b\u4e00\u6b21\u8fd0\u884c\u65f6\u95f4<br \/>\n<\/h2>\n<pre class=\"brush:sql;\">\r\n--\u4fee\u6539\u67d0\u4e2ajob\u540d \u4fee\u6539\u4e0b\u4e00\u6b21\u8fd0\u884c\u65f6\u95f4  \r\ndbms_job.next_date(v_job,sysdate);  \r\nbegin \r\n\tdbms_job.next_date (v_job,SYSDATE + 10\/(24*60)); \r\nend; <\/pre>\n<h2>\n\tDBMS_Job\u5305\u542b\u7684\u5b50\u8fc7\u7a0b<br \/>\n<\/h2>\n<ul>\n<li>\n\t\tBroken()\u8fc7\u7a0b\u3002&nbsp;\n\t<\/li>\n<li>\n\t\tchange()\u8fc7\u7a0b\u3002&nbsp;\n\t<\/li>\n<li>\n\t\tInterval()\u8fc7\u7a0b\u3002&nbsp;\n\t<\/li>\n<li>\n\t\tIsubmit()\u8fc7\u7a0b\u3002&nbsp;\n\t<\/li>\n<li>\n\t\tNext_Date()\u8fc7\u7a0b\u3002&nbsp;\n\t<\/li>\n<li>\n\t\tRemove()\u8fc7\u7a0b\u3002&nbsp;\n\t<\/li>\n<li>\n\t\tRun()\u8fc7\u7a0b\u3002&nbsp;\n\t<\/li>\n<li>\n\t\tSubmit()\u8fc7\u7a0b\u3002&nbsp;\n\t<\/li>\n<li>\n\t\tUser_Export()\u8fc7\u7a0b\u3002&nbsp;\n\t<\/li>\n<li>\n\t\tWhat()\u8fc7\u7a0b\u3002\n\t<\/li>\n<\/ul>\n<p>\n\t\u5173\u4e8e DBMS_Job\u5305\u7684\u5b50\u8fc7\u7a0b\uff0c\u8bf7\u67e5\u770b\u6211\u7684\u53e6\u5916\u4e00\u7bc7\u6587\u7ae0\uff1a<a href=\"http:\/\/www.xttblog.com\/?p=1339\" name=\"DBMS_Job\u5305 \u5b50\u8fc7\u7a0b\u7528\u6cd5\u8be6\u89e3\" target=\"_blank\" title=\"DBMS_Job\u5305 \u5b50\u8fc7\u7a0b\u7528\u6cd5\u8be6\u89e3\">http:\/\/www.xttblog.com\/?p=1339<\/a>\n<\/p>\n<p>\n\t\u5b9a\u4e49\u4e86job\u4e4b\u540e\uff0c\u6700\u91cd\u8981\u7684\u5c31\u662f\u4e0d\u8981\u5fd8\u4e86\u7528dbms_job.run()\u6765\u8fd0\u884cjob\uff0c\u4ee5\u524d\u6211\u505a\u7684\u65f6\u5019\uff0c\u5c31\u8001\u662f\u5fd8\u4e86\u6267\u884c\u3002\u4e0b\u9762\u662f\u4e00\u4e9b\u5e38\u7528\u7684interval\u53c2\u6570\u8bbe\u7f6e\u7684\u4f8b\u5b50\uff1a\n<\/p>\n<table>\n<tbody>\n<tr>\n<td valign=\"top\" width=\"433\">\n\t\t\t\t<strong>\u63cf\u8ff0<\/strong>\n\t\t\t<\/td>\n<td valign=\"top\" width=\"433\">\n\t\t\t\t<strong>interval\u53c2\u6570\u503c<\/strong>\n\t\t\t<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"433\">\n\t\t\t\t\u6bcf\u5929\u8fd0\u884c\u4e00\u6b21\n\t\t\t<\/td>\n<td valign=\"top\" width=\"433\">\n\t\t\t\tsysdate + 1\n\t\t\t<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"433\">\n\t\t\t\t\u6bcf\u5c0f\u65f6\u8fd0\u884c\u4e00\u6b21\n\t\t\t<\/td>\n<td valign=\"top\" width=\"433\">\n\t\t\t\tsysdate + 1 \/ 24\n\t\t\t<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"433\">\n\t\t\t\t\u6bcf10\u5206\u949f\u8fd0\u884c\u4e00\u6b21\n\t\t\t<\/td>\n<td valign=\"top\" width=\"433\">\n\t\t\t\tsysdate + 10 \/ (60 * 24)\n\t\t\t<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"433\">\n\t\t\t\t\u6bcf30\u79d2\u8fd0\u884c\u4e00\u6b21\n\t\t\t<\/td>\n<td valign=\"top\" width=\"433\">\n\t\t\t\tsysdate + 30 \/ (60 * 24 * 60)\n\t\t\t<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"433\">\n\t\t\t\t\u6bcf\u9694\u4e00\u4e2a\u661f\u671f\u8fd0\u884c\u4e00\u6b21\n\t\t\t<\/td>\n<td valign=\"top\" width=\"433\">\n\t\t\t\tsysdate + 7\n\t\t\t<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"433\">\n\t\t\t\t\u4e0d\u518d\u8fd0\u884c\u8be5\u4efb\u52a1\u5e76\u5220\u9664\u5b83\n\t\t\t<\/td>\n<td valign=\"top\" width=\"433\">\n\t\t\t\tnull\n\t\t\t<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"433\">\n\t\t\t\t\u6bcf\u5929\u5348\u591c12\u70b9\n\t\t\t<\/td>\n<td valign=\"top\" width=\"433\">\n\t\t\t\ttrunc(sysdate + 1)\n\t\t\t<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"433\">\n\t\t\t\t\u6bcf\u5929\u65e9\u4e0a8\u70b930\u5206\n\t\t\t<\/td>\n<td valign=\"top\" width=\"433\">\n\t\t\t\ttrunc(sysdate + 1) + (8 * 60 + 30) \/ (24 * 60)\n\t\t\t<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"433\">\n\t\t\t\t\u6bcf\u661f\u671f\u4e8c\u4e2d\u534812\u70b9\n\t\t\t<\/td>\n<td valign=\"top\" width=\"433\">\n\t\t\t\tnext_day(trunc(sysdate), &#039;Tuesday&#039;) + 12 \/ 24\n\t\t\t<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"433\">\n\t\t\t\t\u6bcf\u4e2a\u6708\u7b2c\u4e00\u5929\u7684\u5348\u591c12\u70b9\n\t\t\t<\/td>\n<td valign=\"top\" width=\"433\">\n\t\t\t\ttrunc(last_day(sysdate) + 1)\n\t\t\t<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"433\">\n\t\t\t\t\u6bcf\u4e2a\u5b63\u5ea6\u6700\u540e\u4e00\u5929\u7684\u665a\u4e0a11\u70b9\n\t\t\t<\/td>\n<td valign=\"top\" width=\"433\">\n\t\t\t\ttrunc(add_months(sysdate + 2 \/ 24, 3), &#039;Q&#039;) &#8211; 1 \/ 24\n\t\t\t<\/td>\n<\/tr>\n<tr>\n<td valign=\"top\" width=\"433\">\n\t\t\t\t\u6bcf\u4e2a\u661f\u671f\u516d\u548c\u661f\u671f\u65e5\u65e9\u4e0a6\u70b910\u5206\n\t\t\t<\/td>\n<td valign=\"top\" width=\"433\">\n\t\t\t\ttrunc(least(next_day(sysdate, &#039;Saturday&#039;), next_day(sysdate, &#039;Sunday&#039;))) + (6 * 60 + 10) \/ (24 * 60)\n\t\t\t<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\n\t\u4f7f\u7528next_day\u7684\u65f6\u5019\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0&ldquo;\u5468\u4e2d\u7684\u65e5\u671f\u9519\u8bef&rdquo;\uff0c\u53ef\u4ee5\u8bd5\u8bd5\u770b\u5c06\u82f1\u6587\u7684\u65e5\u671f\u6362\u6210\u4e2d\u6587\u7684\uff0c\u6bd4\u5982&ldquo;Friday&rdquo;\u6362\u6210&ldquo;\u661f\u671f\u4e94&rdquo;\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=1337\">Oracle job\u5b9a\u65f6\u5668 \u7528\u6cd5<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u5728\u505a\u67d0\u4e9b\u4e1a\u52a1\u65f6\uff0c\u9700\u8981\u7528\u5230 Oracle \u7684\u5b9a\u65f6\u4efb\u52a1\u529f\u80fd\u3002\u8fd9\u4e00\u822c\u90fd\u662f DBA \u6765\u5b8c\u6210\u7684\uff0c\u4f46\u662f\u4f5c\u4e3a\u5f00\u53d1\u8005\u6211\u4eec\u8fd8\u662f\u6709 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[1090,1089,1087,467,1088],"class_list":["post-1337","post","type-post","status-publish","format-standard","hentry","category-sql","tag-dba_jobs_running","tag-dbms_job","tag-job","tag-oracle","tag-1088"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/1337","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1337"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/1337\/revisions"}],"predecessor-version":[{"id":1338,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/1337\/revisions\/1338"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1337"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1337"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1337"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}