Start one job after another complets using PL/SQL procedure and DBMS_JOB

All,
I am attempting to refresh a materialized view using DBMS_JOB and having a PL/SQL program loop through each materialized view name that resides in a table I created. We do the table because they have to be refreshed in a specific order and I utilize the ORDER_OF_REFRESH column to dictate which MV comes first, second, third, etc.
Now - I have this working to the extent that it kicks off 4 materialized views (currently set the procedure to only do 4 MVs for testing purposes) but I would ultimately like the procedure to create a new DBMS_JOB that calls DBMS_MVIEW.REFRESH of the next view in line ONLY after the preceeding materialized view DBMS_JOB completes.
The purpose of all of this is to do a few things. One - if I simply create a procedure with the DBMS_MVIEW.REFRESH call to each materialized view in order - that works but if one fails, the job starts over again and will up to 16 times - BIG PROBLEM. Secondly, we want the job that will call this procedure to fail if it encounters 2 failures on any one materialized view (because some MVs may be dependant upon that data and cannot use old stale data).
This may not be the "best" approach but I am trying to make the job self-sufficient in that it knows when to fail or not, and doesn't kick off the materialized views jobs all at once (remember - they need to start one after the other - in order).
As you can see near the bottom, my logic doesn't work quite right. It kicks off all four jobs at once with the date of the whatever LAST_REFRESH is in my cursor (which ultimately is from the prior day. What I would like to happen is this:
1.) 1st MV kicks off as DBMS_JOB and completes
2.) 2nd MV kicks off with a start time of 3 seconds after the completion of 1st MV (based off LAST_REFRESH) date.
3.) This conitnues until all MVs are refresh or until 2 failures are encountered, in which no more jobs are scheduled.
- Obviously I am having a little bit of trouble with #2 and #3 - any help is appreciated.
CREATE OR REPLACE PROCEDURE Next_Job_Refresh_Test2 IS
V_FAILURES NUMBER;
V_JOB_NO NUMBER;
V_START_DATE DATE := SYSDATE;
V_NEXT_DATE DATE;
V_NAME VARCHAR2(30);
V_DELIMITER VARCHAR2(1);
CURSOR MV_LIST IS SELECT DISTINCT A.ORDER_OF_REFRESH,
                              A.MV_OBJECT_NAME
                    FROM CATEBS.DISCO_MV_REFRESH_ORDER A
                    WHERE A.ORDER_OF_REFRESH < 5
               ORDER BY A.ORDER_OF_REFRESH ASC;
CURSOR MV_ORDER IS SELECT B.ORDER_OF_REFRESH,
                              B.MV_OBJECT_NAME,
                              A.LAST_REFRESH
                         FROM USER_SNAPSHOTS A,
                              DISCO_MV_REFRESH_ORDER B
                         WHERE A.NAME = B.MV_OBJECT_NAME
                    ORDER BY B.ORDER_OF_REFRESH ASC;
BEGIN
FOR I IN MV_LIST
LOOP
IF I.ORDER_OF_REFRESH = 1
THEN V_START_DATE := SYSDATE + (30/86400); -- Start job one minute after execution time
          ELSE V_START_DATE := V_NEXT_DATE;
END IF;
     V_FAILURES := 0;
     V_JOB_NO := 0;
     V_NAME := I.MV_OBJECT_NAME;
     V_DELIMITER := '''';
DBMS_JOB.SUBMIT(V_JOB_NO,'DBMS_MVIEW.REFRESH(' || V_DELIMITER || V_NAME || V_DELIMITER || ');',V_START_DATE,NULL);
          SELECT JOB, FAILURES INTO V_JOB_NO, V_FAILURES
          FROM USER_JOBS
          WHERE WHAT LIKE '%' || V_NAME || '%'
          AND SCHEMA_USER = 'CATEBS';
IF V_FAILURES = 3
THEN DBMS_JOB.BROKEN(V_JOB_NO,TRUE,NULL); EXIT;
END IF;
FOR O IN MV_ORDER
LOOP
IF I.ORDER_OF_REFRESH > 2
THEN V_NEXT_DATE:= (O.LAST_REFRESH + (3/86400)); -- Start next materialized view 3 seconds after completion of prior refresh
END IF;
END LOOP;
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND
     THEN
          IF MV_LIST%ISOPEN
               THEN CLOSE MV_LIST;
          END IF;
NULL;
END Next_Job_Refresh_Test2;
---------------------------------------------------------------------------------------------------------------------

Justin,
I think I am getting closer. I have a procedure shown just below this that updates my custom table with information from USER_SNAPSHOTS to reflect the time and status of the refresh completion:
CREATE OR REPLACE PROCEDURE Upd_Disco_Mv_Refresh_Order_Tbl IS
V_STATUS VARCHAR2(7);
V_LAST_REFRESH DATE;
V_MV_NAME VARCHAR2(30);
CURSOR MV_LIST IS SELECT DISTINCT NAME, LAST_REFRESH, STATUS
                         FROM USER_SNAPSHOTS
                    WHERE OWNER = 'CATEBS';
BEGIN
FOR I IN MV_LIST
LOOP
     V_STATUS := I.STATUS;
     V_LAST_REFRESH := I.LAST_REFRESH;
     V_MV_NAME := I.NAME;
UPDATE DISCO_MV_REFRESH_ORDER A SET A.LAST_REFRESH = V_LAST_REFRESH
WHERE A.MV_OBJECT_NAME = V_MV_NAME;
COMMIT;
UPDATE DISCO_MV_REFRESH_ORDER A SET A.REFRESH_STATUS = V_STATUS
WHERE A.MV_OBJECT_NAME = V_MV_NAME;
COMMIT;
END LOOP;
END Upd_Disco_Mv_Refresh_Order_Tbl;
Next, I have a "new" procedure that does the job creation and refresh show just below this which, when starting the loop, sets the LAST_REFRESH date in my table to NULL and the STATUS = 'INVALID'. Then if the order of refresh = 1 then it uses SYSDATE to submit the job and start right away, else if it's not the first job, it uses V_NEXT_DATE. Now, V_NEXT_DATE is equal to the LAST_REFRESH date from my table when the view has completed and the V_PREV_STATUS = 'VALID'. I think tack on 2 seconds to that to begin my next job.... See code below:
CREATE OR REPLACE PROCEDURE Disco_Mv_Refresh IS
V_FAILURES NUMBER;
V_JOB_NO NUMBER;
V_START_DATE DATE := SYSDATE;
V_NEXT_DATE DATE;
V_NAME VARCHAR2(30);
V_PREV_STATUS VARCHAR2(7);
CURSOR MV_LIST IS SELECT DISTINCT A.ORDER_OF_REFRESH,
                              A.MV_OBJECT_NAME,
                              A.LAST_REFRESH,
                              A.REFRESH_STATUS
                    FROM CATEBS.DISCO_MV_REFRESH_ORDER A
                    WHERE A.ORDER_OF_REFRESH <= 5
               ORDER BY A.ORDER_OF_REFRESH ASC;
BEGIN
FOR I IN MV_LIST
LOOP
V_NAME := I.MV_OBJECT_NAME;
V_FAILURES := 0;
UPDATE DISCO_MV_REFRESH_ORDER SET LAST_REFRESH = NULL WHERE MV_OBJECT_NAME = V_NAME;
UPDATE DISCO_MV_REFRESH_ORDER SET REFRESH_STATUS = 'INVALID' WHERE MV_OBJECT_NAME = V_NAME;
IF I.ORDER_OF_REFRESH = 1
THEN V_START_DATE := SYSDATE;
ELSE V_START_DATE := V_NEXT_DATE;
END IF;
DBMS_JOB.SUBMIT(V_JOB_NO,'DBMS_MVIEW.REFRESH(' || '''' || V_NAME || '''' || '); BEGIN UPD_DISCO_MV_REFRESH_ORDER_TBL; END;',V_START_DATE,NULL);
SELECT A.REFRESH_STATUS, A.LAST_REFRESH INTO V_PREV_STATUS, V_NEXT_DATE
FROM DISCO_MV_REFRESH_ORDER A
WHERE (I.ORDER_OF_REFRESH - 1) = A.ORDER_OF_REFRESH;
IF I.ORDER_OF_REFRESH > 1 AND V_PREV_STATUS = 'VALID'
THEN V_NEXT_DATE := V_NEXT_DATE + (2/86400);
ELSE V_NEXT_DATE := NULL;
END IF;
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND
     THEN
          IF MV_LIST%ISOPEN
               THEN CLOSE MV_LIST;
          END IF;
NULL;
END Disco_Mv_Refresh;
My problem is that it doesn't appear to be looping to the next job. It worked succesfully on the first job but not the subsequent jobs (or materialized views in this case).... Any ideas?

Similar Messages

  • I created a playlist with 100 songs.  I want those 100 songs played using the shuffle option.  This no longer works in iTunes version 11.1.5.5  How can I get an entire  playlist to paly one song after another by using the switch option?

    I created a playlist with 100 songs.  I want those 100 songs played using the shuffle option.  This no longer works in iTunes version 11.1.5.5  How can I get an entire  playlist to paly one song after another by using the switch option?

    You're welcome.
    Going back to your original post:
    5) Tried running Itunes in 'safe mode', running itunes as an administrator..nothing.
    Was that iTunes' safe mode as opposed to Windows' safe mode? iTunes safe mode is invoked by holding down CTRL+SHIFT immediately after clicking the icon to launch iTunes and continuing to hold until this message pops up:
    Click continue, then close iTunes and reopen. With luck iTunes now opens normally every time.
    tt2

  • How to insert BLOB datatype image using PL/SQL Procedure and SQL Loader

    Hi,
    How to insert an image into database using PL/SQL Procedure and also how to insert using SQL Loader. Please help by giving sample code and process description.
    Thanks,
    Vijay V

    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:232814159006

  • Inserting data from one table into another table using PL/SQL

    HI,
    I am trying to insert values from one table into another using PL procedure, the values I want to retrieve from the table riverside1 are charac_id and charac_type and insert these values into another table called riverside2 , the stored procedure zorgs_gorfs(x,y) accepts two parameters which are 2 charac_id's of d characters in riverside1 then using insert statements inserts these characters from riverside1 into riverside2.
    CREATE OR REPLACE PROCEDURE zorgs_gorfs(x IN NUMBER, y IN NUMBER) AS
         BEGIN
              INSERT INTO riverside2
                   (charac_id)
              VALUES
                   (x);
    INSERT INTO riverside2
                   (charac_id)
              VALUES
                   (y);
          END zorgs_gorfs;
    /This works but the problem im having is that when I also try to insert the charac_type as well as the charac_id it doesnt work below is the code:
    CREATE OR REPLACE PROCEDURE zorgs_gorfs(x IN NUMBER, y IN NUMBER) AS
         BEGIN
              INSERT INTO riverside2
                   (charac_id,charac_tye)
              VALUES
                   (Select
                        charac_id,
                        charc_type
                   FROM
                        riverside1
                   WHERE
                        charac_id = x);
          END zorgs_gorfs;
    /can someone kindly sort me out

    modify this sql
    INSERT INTO riverside2
                   (charac_id,charac_tye)
              VALUES
                   (Select
                        charac_id,
                        charc_type
                   FROM
                        riverside1
                   WHERE
                        charac_id = x);as
    INSERT INTO riverside2
                   (charac_id,charac_tye)
              VALUES
                   (Select
                        charac_id,
                        charc_type
                   FROM
                        riverside1
                   WHERE
                        charac_id in ( x,y));But my suggestion would be consider revising your approach. It does not look that good.
    Thanks,
    karthick.

  • Using PL/SQL procedure and function

    In a page i have a VO that uses a Where clause that looks like this
    WHERE attr=package.function
    where the function returns a value of an internal variable valued by another procedure in the package which considers only the Dbuser DBSchema as parameters.
    Do i have to call the procedure in a method like initializeBindigsForPage or i have to put it in another place? And in which mode?
    Thanks Marco

    hi satish,
    i tried ur suggestion, but its shows error like
    declare
    o1 number;
    total_bytes number;
    o3 number;
    unused_bytes number;
    o5 number;
    o6 number;
    o7 number;
    b number:=0;
    str varchar2(2000);
    cursor name is select TNAME FROM TAB WHERE TABTYPE='TABLE';
    begin
    FOR VAL IN name
    LOOP
    DBMS_SPACE.UNUSED_SPACE('XMLUSER',VAL.TNAME,'TABLE',o1,total_bytes,o3,unused_bytes,o5,o6,o7);
    --dbms_output.put_line(VAL.TNAME);
    --dbms_output.put_line(total_bytes);
    --dbms_output.put_line(unused_bytes);
    EXECUTE IMMEDIATE 'select count(*) from '||VAL.TNAME||' ' RETURNING into b;
    --select count(*) into b from VAL.TNAME;
    --execute immediate(str);
    dbms_output.put_line(b);
    insert into space values(VAL.TNAME,total_bytes,unused_bytes,b);
    END LOOP;
    end;
    SQL> @space.sql
    declare
    ERROR at line 1:
    ORA-06547: RETURNING clause must be used with INSERT, UPDATE, or DELETE
    statements
    ORA-06512: at line 19
    wat goes wrong satish?

  • Start background Job when another is finished (NOT with the JobSteps)

    Hi guys,
    i need your help.
    I've already searched here in forum, but i wasn't able to find a good solution.
    I have this problem.
    I have a program that create a background job with the FM FM JOB_OPEN.. SUBMIT report with parameters .. JOB_CLOSE.
    I want that if i run this report again (20 secs after for example) it does:
    - Check if there is an already running Job with the same name (means with state 'R') (This task is simply, with a select on TBTO table)
    - If it's found, it have to create a new job with the same name that starts automatically AFTER the first running job is finished (don't care about the end-state of the first job).
    I've already tried with pred_jobcount & PRED_JOBNAME parameters of the JOB_CLOSE FM but it doesen't works!
    The JOB_CLOSE, creates a job in Planned state. But when the first Job is finished, the second job(Planned) doesen't start automatically.
    In this scenario, i CANNOT use endless loops (wait until the first job is finished and then submit the second) Job-steps (one job that contains multiple steps) events (i have to start only one job after the predecessor is finished), because this report could be run many times and each job should be collected like a "stack" (only when the first job is finshed the second "registered" should be started and so on, until the aren't more planned jobs).
    <REMOVED BY MODERATOR>
    Thx a lot for your help.
    Andrea
    Edited by: Alvaro Tejada Galindo on Jun 12, 2008 12:19 PM

    Hi Veda
    i can tell u but ... some reward points are very appreciated ....
    I'm joking (of course)
    Here the question:
    I have a program (called A) that submit a new program (called B) with the JOB_OPEN .. submit JOB_CLOSE. The program B should start only if another program B (called before for example) is finished.
    Here the solution.
    I add a parameter (with no-display clausole) to the program B. In this parameter i pass to the program, the job number returned by the JOB_OPEN function. 
    When i create the JOB with the function, the "jobname" parameter is set with value 'G_DELIVERY' (Here u can change the name of the job as u want : this is the jobname that u see in SM37 transaction).
    In the start-of-selection of program B i put a "waiting" procedure like this :
    First i save a timestamp of system-date and system-time (called for example r_date and r_time)
    select from table TBTCO all the jobs called "G_DELIVERY" with jobnumber <> from the jobnumber parameter (that means exclude itselfs)  with status running ('R')  -> that have startdate /starttime less than the r_date and r_time <- (this is the key of the selection that solve the problem).
    if it is found (means there is another running job started before this one).
    wait up to 60 seconds. "for example
    repeat the selection.
    endif.
    When the job called before ends, this one programs exits from the loop and continues. If u submit more programs "B", they'll works like a stack.
    I should say to u just one thing.... I solved my problem in another way (because i've changed the logic so this problem was no more) so i didn't implemented that logic, but it should works very good.
    Try it and tell me!
    Bye
    Andrea

  • Embed question - play one movie after another

    I am trying to figure out how to play a short 10 second clip before each movie on my website. The clip may be a short ad or a promo and will depend upon the content of the main video. What is the code that enables you to play one move after another in a web page. I don't want to edit the two clips to become one cos over time the ads and promos will change. In Realplayer I remember using SMIL but how is it done in QT. I will eventually write code to write out the Embed tag but now i am just experimenting. Here is what my drupal site puts out
    <!-- start main content -->
    <!-- begin content -->
    <!--[if !IE]> <-->
    <object type="video/quicktime" width="483" height="381"
    data="http://www.1234567.com/files/videos/Mpeg4TestSnapX-480x360.mp4">
    <!--> <![endif]-->
    <!--[if IE]>
    <object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="483" height="381" scale="tofit" >
    <![endif]-->
    <param name="src" value="http://www.1234567.com/files/videos/Mpeg4TestSnapX-480x360.mp4" />
    <param name="AUTOPLAY" value="true" />
    <param name="KIOSKMODE" value="false" />
    Your browser is not able to display this multimedia content.
    </object>
    Problems viewing videos?
    Download latest Quicktime Player

    Embed the initial movie clip as normal, but give it an HREF property.
    Set the source for the HREF to be the next movie, set autohref=true, and set target="myself". It's the same technique you use to build a poster movie but (a) instead of having the poster movie open QT Player, you have its target open in its own frame and (b) instead of waiting for a user to click the poster, you have the poster movie "click itself".
    Code that I used a very long time ago to display a "Loading..." graphic as a movie loaded (waste of effort, actually, as the movie is fast start and loads very fast):
    <embed
    src="loading.mov"
    height="208"
    width="256"
    autohref="true"
    href="Worm.mov"
    target="Myself">
    </embed>
    (of course this was before I learned about OBJECT and the need to use OBJECT to activate the ActiveX control in IE. Also, it's worth noting that the javascript hack isn't strictly necessary for IE users, but without it, IE users will get a security dialog before they get the movie.)
    The code above can be found on:
    http://capital2.capital.edu/admin-staff/dalthoff/adventures/worm.html
    --Dave Althoff, Jr.

  • My iPad air won't charge at all and I don't know if it's the charger or port help!i have had a new port put in before and it worked fine after but it's not working now! I have spent way to much trying to fix this thing one problem after another?

    My iPad air won't change at all, and I don't know if it's the port or charger cable it is charging normally but it just won't charge. I have had a new port put in before after a charger getting stuck in there but it worked fine after and now it's not working at all! I don't know if maybe it's the charger getting old but I have spent far too much money on this iPad then I should have as it's one problem after another witch is causing me lots of stress.

    Try giving your iPad a reset. Hold down the sleep and home keys for about 20 seconds. When you see the silver apple, let go and let it reboot and try again.
    How are you charging it? its's best charged plugged into the wall  not via USB. So if you're trying via USB, try using the supplied power block plugged into the wall.

  • Starting a movie after another movie is finished

    hello
    i have a series of movie clips that I want to play
    sequentially. For some I would like them to play one right after
    another and others that have a pause in between. I have the first
    part worked out but it is sloppy and there is code all over the
    place. is there a set, clean way to accomplish this?
    peace

    Yeah that's what I have been doing. I guess I should have
    been clearer. Is there anyway to consolidate the code so that it
    stays on the _root timeline?
    I have also used this method, shown in the attached code. I
    have tried to do other things with that code but it hasn't worked.
    Can anything else be done w/ the attached code or is that the most
    it can do?

  • Help!! As I was scrolling through my library, one folder after another had the photos in it turn to "static"!  Lots of streaks and dots!  What is happening and how do I save my photos?

        As I was scrolling through my Aperture library just now, I saw one folder after another turn the photos in that folder into garbage!   They have lines and dots and nothing recognizable - what in the world is causing this?    Can I get my photos back?    It almost looks like a virus eating my files - could it be - and if it is - is my entire computer in trouble?   HELP HELP HELP!

    Interesting that you posted this Cleaning up photo library about one hour before this post. I'd say there is a good possibility they are related.
    Without knowing your system, OS version and Aperture version and what you were doing to 'clean up' your library there is little we can do.
    My photo library is a mess.  I have moved things around a lot in a futile attempt to organize them, now I have a lot of placeholders with no files attached.  How do I clean things up?
    I suggest you restore from your backup and forgo the cleaning operation until you have a better grasp of the situation.
    BTW the Masters folder is organized by date and time of import at least in Aperture 3, if you are using 2 then all bets are off,
    Good luck with Apple support, if you want to try and get this sorted out post back the information I requested above.
    regards

  • Can I transfer info from one macbook to another by using a firewire cable?

    Can I transfer info from one mac to another by using a firewire cable?

    You can boot the computer that you would like to get the file from into target disk mode.
    This document will help you.
    http://docs.info.apple.com/article.html?path=Mac/10.6/en/8443.html

  • I have an ipad mini. From one moment to another a document that was created and used on pages app ( on the ipad mini) does not want to open ( When pressed it states " document cant be opened). How can I make this document open again?

    I have an ipad mini. From one moment to another a document that was created and used on pages app ( on the ipad mini) does not want to open ( When pressed it states " document cant be opened). How can I make this document open again?
    I have tried back ups and  restoring, resetting, and even updating the pages app. And nothing has worked.

    I have an ipad mini. From one moment to another a document that was created and used on pages app ( on the ipad mini) does not want to open ( When pressed it states " document cant be opened). How can I make this document open again?
    I have tried back ups and  restoring, resetting, and even updating the pages app. And nothing has worked.

  • How do I transfer files from one computer to another without using cables??

    How do I transfer files from one computer to another without using cables?

    Wifi network
    Email
    Thumb Drive
    Online storage such as, iCloud Google Docs, SkyDrive, etc.

  • How do i get music videos to play like the music does on my ipad, for example one right after another and shuffle

    I need to know how I can get the music videos on my IPad to play like the music does.  What I mean id setting up a playlist, shuffle, and have them play one right after another instead of going back to the main screen.

    At the top of the playlist where it shows the playlist title and the number of songs, there are two icons. Click the "play" triangle to add the entire playlist to "Up Next", or the "shuffle" symbol to do the same thing but in random order. But the currently playing track will stop playing, and all the songs in "Up Next" will be removed (replaced by the ones from this playlist).
    If you hold down the "option" key while clicking those icons, the currently playing song will continue playing, and the new playlist will be added to "Up Next" (above the songs that were already there).

  • How to transfer songs from one iPad to another iPad using iTunes?

    How to transfer songs from one iPad to another iPad using iTunes?

    You can't without a third party app. If you didn't purchase the Music with your Apple ID or if the music was imported from CD's on your friends iTunes library, syncing will not work ....nor will transferring purchases.
    Look at this app .... TouchCopy
    http://www.wideanglesoftware.com/touchcopy/index.php

Maybe you are looking for

  • Please advice how to connect iphone 5G to Lenovo laptop? Thanks

    Please advice how to connect iphone 5c to Lenovo laptop? Thanks I tried but cannot connet iphone 5C to the laptop

  • Photos in Aperture do not wrap in rows, go straight off to right

    Photos in Aperture go right off to the right in one long row.  They no longer wrap in any project.  And NO I don't have filmstrip selected.   I'm well aware of the modes of view.   I've seen others with this proble here but the discussions were archi

  • Read latin extended characters

    i want to read characters(and use it in a String) from a file which contains extended latin characters. i tried with FileReader and FileInputStream, but i did't get to a reasonable result. My OS is Win 2000 and i have installed the characters i neede

  • Attaching files to an email in icloud

    Is there anyway to reset the window size of the file window that pops up when you are adding a file to an email in icloud?  My window only shows minimal information and I have to manually resize it every time I want to attach a file.

  • Xdg-open for irc links in chromium

    Hey! I know that the first thing to do is search before bothering other people and I did it a lot. Google, posts, how-to`s, wikis... I see my last chance in asking this community So here is my problem: I use chromium as default browser and konversati