{"id":1331,"date":"2021-03-19T15:25:46","date_gmt":"2021-03-19T18:25:46","guid":{"rendered":"http:\/\/www.soudba.com.br\/?p=1331"},"modified":"2021-03-19T15:25:46","modified_gmt":"2021-03-19T18:25:46","slug":"dbms_job-move-to-dbms_scheduler","status":"publish","type":"post","link":"https:\/\/www.soudba.com.br\/?p=1331","title":{"rendered":"DBMS_JOB move to DBMS_SCHEDULER"},"content":{"rendered":"<p>Easy way to migrate my jobs, to avoid issues for upgrade to 19c or other.<\/p>\n<p>I created this query to help during the process.<\/p>\n<p>WITH<br \/>\nqueryintervaloriginal AS (<br \/>\nSELECT job, TRUNC(MONTHS_BETWEEN(next_DATE, LAST_DATE)) AS FREQ_MONTH<br \/>\n,(TRUNC(next_DATE) &#8211; TRUNC(LAST_DATE)) AS FREQ_DAY<br \/>\n, ROUND((next_DATE &#8211; LAST_DATE)* 24 * 60) AS FREQ_MINUTE<br \/>\n, TO_CHAR(next_DATE, &#8216;Dy&#8217;) AS WEEKDAY_VALUE<br \/>\n, TO_NUMBER(TO_CHAR(LAST_DATE, &#8216;DD&#8217;)) as DAY_VALUE<br \/>\n, TO_NUMBER(TO_CHAR(LAST_DATE, &#8216;HH24&#8217;)) as HOUR_VALUE<br \/>\n, TO_NUMBER(TO_CHAR(LAST_DATE, &#8216;MI&#8217;)) as MINUTE_VALUE<br \/>\n, INTERVAL<br \/>\nFROM dba_JOBS<br \/>\n),<br \/>\nqueryinterval AS (<br \/>\nSELECT job, \/* Created by Andre Rocha *\/<br \/>\nnvl(<br \/>\nCASE FREQ_MONTH<br \/>\nWHEN 1 THEN<br \/>\n&#8216;FREQ=MONTHLY;&#8217; || &#8216;BYMONTHDAY=&#8217;|| day_value || &#8216;;&#8217; ||<br \/>\n&#8216;BYHOUR=&#8217;|| hour_value || &#8216;;&#8217; || &#8216;BYMINUTE=&#8217; || minute_value || &#8216;;&#8217;<br \/>\nELSE<br \/>\nCASE freq_day<br \/>\nWHEN 7 THEN<br \/>\n&#8216;FREQ=WEEKLY;&#8217; || &#8216;BYDAY=&#8217;|| weekday_value || &#8216;;&#8217;<br \/>\n|| &#8216;BYHOUR=&#8217;|| hour_value || &#8216;;&#8217; || &#8216;BYMINUTE=&#8217; || minute_value || &#8216;;&#8217;<br \/>\nWHEN 1 THEN<br \/>\n&#8216;FREQ=DAILY;&#8217; || &#8216;BYHOUR=&#8217;|| hour_value || &#8216;;&#8217; || &#8216;BYMINUTE=&#8217; || minute_value || &#8216;;&#8217;<br \/>\nELSE<br \/>\nCASE<br \/>\nWHEN FREQ_MINUTE=60 THEN<br \/>\n&#8216;FREQ=HOURLY;&#8217; || &#8216;INTERVAL=1;&#8217;<br \/>\nWHEN FREQ_MINUTE&lt;60 THEN &#8216;FREQ=MINUTELY;&#8217; || &#8216;INTERVAL=&#8217; || FREQ_MINUTE || &#8216;;&#8217; END END END,INTERVAL) intervalvalue FROM queryintervaloriginal ), queryjobs AS ( select \/* Created by Andre Rocha *\/ &#8216;dbms_scheduler.create_job( &#8216; || chr(10) || &#8216; job_name=&gt;&#8217;||&#8221;&#8221;||'&#8221;&#8216; || schema_user ||'&#8221;.&#8221;&#8216;|| substr(upper(translate(what,&#8217;.(),;&#8217;,&#8217;_&#8217;)),1,20) ||&#8217;_JOB&#8221;&#8216; ||&#8221;&#8221;||&#8217;, &#8216; || chr(10)<br \/>\n|| &#8216; job_type=&gt; &#8216;||&#8221;&#8221;||&#8217;PLSQL_BLOCK&#8217;||&#8221;&#8221;||&#8217;,&#8217; || chr(10)<br \/>\n|| &#8216; job_action=&gt; &#8216;||&#8221;&#8221;||'&#8221;begin &#8216; || what || &#8216; end;&#8221;&#8216;||&#8221;&#8221;||&#8217;, &#8216; || chr(10)<br \/>\n|| &#8216; start_date =&gt; to_timestamp(&#8216;||&#8221;&#8221;|| to_char(next_date,&#8217;mm\/dd\/yyyy hh24:mi:ss&#8217;)<br \/>\n||&#8221;&#8221;||&#8217;,&#8217;||&#8221;&#8221;|| &#8216;mm\/dd\/yyyy hh24:mi:ss&#8217; ||&#8221;&#8221;||&#8217;), &#8216; || chr(10)<br \/>\n|| DECODE (interval,&#8217;null&#8217;,NULL, &#8216; repeat_interval =&gt; &#8216; ||&#8221;&#8221;||<br \/>\n(SELECT a.intervalvalue FROM queryinterval a WHERE a.job = dba_jobs.job)<br \/>\n|| &#8221;&#8221;||&#8217;, &#8216; || chr(10) )<br \/>\n|| &#8216; enabled =&gt; true, auto_drop=&gt; false, &#8216; || chr(10)<br \/>\n|| &#8216; comments =&gt; &#8216;||&#8221;&#8221;||&#8217;Converted from job &#8216; || job || &#8221;&#8221; || chr(10)<br \/>\n|| &#8216;);&#8217; || chr(10)<br \/>\nfrom dba_jobs<br \/>\nwhere broken = &#8216;N&#8217;<br \/>\n)<br \/>\nSELECT * FROM queryjobs ;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Easy way to migrate my jobs, to avoid issues for upgrade to 19c or other. I created this query to help during the process. WITH queryintervaloriginal AS ( SELECT job, TRUNC(MONTHS_BETWEEN(next_DATE, LAST_DATE)) AS FREQ_MONTH ,(TRUNC(next_DATE) &#8211; TRUNC(LAST_DATE)) AS FREQ_DAY , &hellip; <a href=\"https:\/\/www.soudba.com.br\/?p=1331\">Continue lendo <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"aside","meta":{"footnotes":""},"categories":[74],"tags":[364,379],"class_list":["post-1331","post","type-post","status-publish","format-aside","hentry","category-dbms_job","tag-dbms_job","tag-move-from-dbms_job-to-dbms_scheduler","post_format-post-format-aside"],"_links":{"self":[{"href":"https:\/\/www.soudba.com.br\/index.php?rest_route=\/wp\/v2\/posts\/1331","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.soudba.com.br\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.soudba.com.br\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.soudba.com.br\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.soudba.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1331"}],"version-history":[{"count":0,"href":"https:\/\/www.soudba.com.br\/index.php?rest_route=\/wp\/v2\/posts\/1331\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.soudba.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.soudba.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.soudba.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}