Using apex_plsql_job

Apex 4.0.2
http://download.oracle.com/docs/cd/E23903_01/doc/doc.41/e21676/apex_plsql_job.htm#BGBFGBIB
If I am reading this right, APEX_PLSQL_JOB.SUBMIT_PROCESS returns a unique job_id that is used by APEX_PLSQL_JOB.UPDATE_JOB_STATUS to record periodic status updates for long-running jobs.
Maybe I am missing something but doesn't this present a chicken-and-egg problem? How can I pass the job_id as a parameter to the long-running job via the submit_process's p_sql parameter when the job_id is returned by that same API?!
The documentation for the update_job_status API further on that page talks about a special variable APP_JOB that the submitted PL/SQL can use but I am not sure how to use it without getting a compilation error (PLS-00049: bad bind variable 'APP_JOB')
Help? Thanks

Hello Vikas,
>> The documentation for the update_job_status API further on that page talks about a special variable APP_JOB that the submitted PL/SQL can use but I am not sure how to use it without getting a compilation error (PLS-00049: bad bind variable 'APP_JOB')
I want to draw your attention to the comment at the bottom of the following code, taken from the SUBMIT_PROCESS documentation:
DECLARE
    l_sql VARCHAR2(4000);
    l_job NUMBER;
BEGIN
    l_sql := 'BEGIN MY_PACKAGE.MY_PROCESS; END;';
    l_job := APEX_PLSQL_JOB.SUBMIT_PROCESS(
        p_sql => l_sql,
        p_status => 'Background process submitted');
    --store l_job for later reference
END;I believe that you should define APP_JOB as an application item and assign it the returned job ID (in the example it’s the l_job variable).
For process status updating, if you are using an inline PL/SQL code, you can use the bind variable notation of this application item, e.g. *:APP_JOB* . When using in your own package, you should use v(‘APP_JOB’).
I fully agree that the documentation on this point is not clear.
Hope this helps,
Arie.
♦ Please remember to mark appropriate posts as correct/helpful. For the long run, it will benefit us all.
♦ Author of Oracle Application Express 3.2 – The Essentials and More

Similar Messages

  • Htmldb csv import using apex_plsql_jobs

    Hi I am using the csv_file_upload tool from :
    http://dbswh.webhop.net/htmldb/f?p=BLOG:FILES:0:::::
    When I press on the upload button to upload the csv file and put it in an htmldb_collection I want it to run inside a apex_plsql_job. Since when I try to upload a csv larger then 4 a 5000 rows I run into the apache webserver timeout.
    declare
      l_sql               varchar2 ( 4000 );
      l_job               number;
    begin
      l_sql            :=
         BEGIN
                csv_util.upload (
         p_file_name       => ''' || :p1_file || ''',
         p_collection_name => ''' || 'CSV_DATA' || ''',
         p_enc_by          => ''' || :p1_enclosed  || ''',
         p_sep_by          => ''' || :p1_separator || ''',
         p_rows            => ''' || :p1_lines  || '''
       END;
       l_job            :=
            apex_plsql_job.submit_process (
                   p_sql => l_sql,
                   p_when => sysdate,
                   p_status => 'Background process submitted'
    exception
      when others
      then
        raise_application_error ( -20001, 'An error was encountered - ' || sqlcode || ' -ERROR- ' || sqlerrm );
    end;
    1,38601552744268E15
    109
    1,32263028543094E15
    COMP_QTG
    APEX_PUBLIC_USER
    18-10-2013 12:59:21
    18-10-2013 12:59:21
    18-10-2013 12:59:24
    Background process submitted
    COMPLETE
    18-10-2013 12:59:24
    (HUGECLOB)
    I see that the job is completed but even with 1 row in the csv file it's get never processed. Without the apex_plsql_job the sample application that came with the csv upload tool works fine.
    Help?
    Thx.

    APEX_PLSQL_JOB is a wrapper for DBMS_JOB.
    Everything that is true for DBMS_JOB applies to APEX_PLSQL_JOB.
    If you read the free documentation regarding APEX_PLSQL_JOB, you will realize that the process runs outside of any APEX environment.
    This means that the job does not have access to your session's collections.
    basically, you need to put EVERYTHING in the process that you call.  Including the final INSERT ... SELECT statement.
    due to the potential complexity, you are best putting this in a procedure (in a package) and calling that procedure via APEX_PLSQL_JOB.
    since you have parameters, you'll need to store those values in a table.
    TABLE
    In your case, the 'parameter table' will look like this:
    create table PARAMETER_TABLE (
      job_id int primary key
    ,enclosed_by varchar2(4)
    ,separated_by varchar2(4)
    ,new_lines varchar2(8) -- i'm guessing this is what p_rows means
    ,actual_file BLOB
    PROCESS
    The process you call should look like this:
    DECLARE
      l_job_id int;
    BEGIN
      -- set up JOB
      l_job_id := APEX_PLSQL_JOB.submit_process( 'BEGIN  process_csv( JOB ); END;' );
      -- note : JOB doesn't start until you call COMMIT
      -- Record the parameters for the job
      -- and copy file from WWV_FLOW_FILES into the PARAMETER_TABLE
      insert into parameter_table (job_id, enclosed_by, separated_by, new_lines, actual_file
      select l_job_id, :p1_enclosed_by, :p1_separator, :p1_lines, W.file
      from wwv_flow_files where filename = :p1_file; -- you'll need to double check my code.  I'm writing from memory.
      -- delete file from wwv_flow_files
      -- i'm just going to skip typing this out.
    END;
    PROCEDURE
    Here is the trick... all data is stored in the PARAMETER_TABLE.
    When you call DBMS_SUBMIT, there are some variables that are already setup.
    Again, APEX_PLSQL_JOB is a wrapper for DBMS_SUBMIT.
    One of those variables is JOB... it holds the JOB_ID of the currently running job.
    You use that value to find the correct parameters to run.
    (reminder : this can get complicated.  Put it in a package.)
    create or replace
    procedure process_csv( p_job_id in int )
    as
      l_enclosed_by  parameter_table.enclosed_by%TYPE;
      l_separated_by parameter_table.separated_by%TYPE;
      l_new_lines    parameter_table.new_lines%TYPE;
      l_file_blob      parameter_table.actual_file%TYPE;
    begin
      -- get actual parameters for this run
      select enclosed_by, separated_by,new_lines,file_blob
        into l_enclosed_by, l_separated_by, l_new_lines, l_file_blob
      from PARAMETER_TABLE
      where job_id = p_job_id;
      -- do something with them
      -- this will have to be different than the parser you've written
      -- delete data from parameter_table
      -- i'm sure you can write this code
    end process_csv;
    note : csv_util is not a standard Oracle package.  You will need one that doesn't do collections
    ORA-00001: Unique constraint violated: SELECT * FROM spreadsheet (or How to parse a CSV file using PL/SQL)

  • Attaching to a session using APEX_PLSQL_JOB

    Hi All,
    I'm going bonkers as I can't see why something isn't working! Basically, I have a process that is started by the user from a page within my application. This process can take a while (a number of minutes) and causes the browser to timeout thinking that the session has died (at least I think that is what is happening). So to work around this I want to submit a job via APEX_PLSQL_JOB and then have the page check every X seconds to see if that job has completed.
    The process makes use of collections to temporarily store the output during computation. So to enable this I need to attach to a session and thought I might as well use the submitting users session. Trouble is I get an error at the session attach stage and can't quite work out why exactly. So first up my 'session attach' procedure (which is in a package) is as below:
    PROCEDURE sessionattach(
       p_user       VARCHAR2
    , p_session    VARCHAR2
    , p_app_id     VARCHAR2
    , p_page_id    VARCHAR2)
    IS
    BEGIN
       -- Session attach.
       APEX_CUSTOM_AUTH.define_user_session(p_user, p_session);
       APEX_APPLICATION.g_flow_id := p_app_id;
       APEX_CUSTOM_AUTH.post_login(p_user, p_session, p_app_id || ':' || p_page_id);
    END sessionattach;When I create the job I know that the following is being passed in (it's not doing the actual work as I can't get past this stage):
    BEGIN
       master_data_pkg.sessionattach(p_user => 'MYUSERNAME', p_session => '4260523061121888', p_app_id => '101', p_page_id => '527');
    END;Again I know that each of the parameters is correct as I'm logging the job SQL that is produced. The error stack that is produced is:
    ORA-06512: at "SYS.OWA_UTIL", line 354
    ORA-06512: at "SYS.HTP", line 1368
    ORA-06512: at "SYS.HTP", line 1443
    ORA-06512: at "SYS.HTP", line 1735
    ORA-06512: at "FLOWS_030100.WWV_FLOW_CUSTOM_AUTH_STD", line 1075
    ORA-06512: at "FLOWS_030100.WWV_FLOW_CUSTOM_AUTH_STD", line 662
    ORA-06512: at "FLOWS_030100.HTMLDB_CUSTOM_AUTH", line 238
    ORA-06512: at "APEXUSR.MASTER_DATA_PKG", line 2114
    ORA-06502: PL/SQL: numeric or value error
    ORA-06512: at "SYS.OWA_UTIL", line 354
    ORA-06512: at "SYS.HTP", line 1368
    ORA-06512: at "SYS.HTP", line 1443
    ORA-06512: at "SYS.HTP", line 1735
    ORA-06512: at "FLOWS_030100.WWV_FLOW_CUSTOM_AUTH_STD", line 1075
    ORA-06502: PL/SQL: numeric or value errorNow the bit where I get really stuck is if I try and run the session attach from a SQL Developer session, the first time it runs it comes up with the same error stack, but if I run it again I get no error. However, I am still not attached to the session as, if I try and create a collection, I get an ORA-20104/ORA-20001 Invalid parsing schema error.
    Any suggestions as to where I'm going wrong and what mistake I am making?
    Many thanks,
    Gareth.

    Ok, I finally resolved the issue by basically using Scotts method in the last post of Re: How to create an Apex 3.1 a session context programmatically? thread.
    The only real change I made was to not bother with the setting of a page variable (I assumed this was just to test) and instead of setting apex_application.g_instance to the next session ID I used the one provided by the users session that launched the job.
    This allows me to create and, if required, query collections from that users session.
    I hope that helps someone else.
    Regards,
    Gareth.

  • Using APEX_PLSQL_JOB API

    I created an APEX page to submit an asynchronous process to run in the background. I defined a page process with the logic you can see below using the APEX_PLSQL_JOB API. The process runs to completion and updates my base-tables correctly. The problem is I do not know what the status of my job is. I would like to give the users some way to monitor the job so they can know when their data is ready. I tried to set up a job to execute in an hour like the logic indicates below but when I query the APEX_PLSQL_JOBS table (select * from APEX_PLSQL_JOBS) no rows are returned. How can I check the status and progress of my process that is running in the background from within APEX?
    DECLARE
    l_sql VARCHAR2(4000);
    l_job NUMBER;
    l_from varchar2(11);
    l_to varchar2(11);
    l_name varchar2(50);
    l_owner varchar2(50);
    l_parameters varchar2(200);
    l_when varchar2(50);
    BEGIN
    l_from := to_char(to_date(:P6_EMG_EFF_FROM_DATE, 'DD-MON-RRRR'), 'DD-MON-RRRR');
    l_to := to_char(to_date(:P6_EMG_EFF_TO_DATE, 'DD-MON-RRRR'), 'DD-MON-RRRR');
    l_Name := UPPER(:P6_EMG_NAME);
    l_parameters := '''' || l_name||''','''||l_from||''','''||l_to||''','''||:APP_USER || '''';
    l_owner := :OWNER;
    l_when := SYSDATE + 1/24;
    l_sql := 'BEGIN ' || l_owner || '.ERR_CREATELOG_PROC(' || l_parameters || '); END;';
    l_job := APEX_PLSQL_JOB.SUBMIT_PROCESS(
    p_sql => l_sql,
    p_when => SYSDATE + 1/24,
    p_status => 'Background process submitted');
    --store l_job for later reference
    END;

    I search OTN and found a similar question with the correct answer. the subject view is available within APEX.

  • Using apex_collection with apex_plsql_job

    Hi,
    Can anyone help with this?
    I'm building a CSV uploader app that uses apex_collections. A CSV file is uploaded to a blob column I then have a function that is successfully parsing the file and dropping the data into an Apex collection.
    This is working really well but I would like to extend it to handle really large CSV files without crashing the broswer. I would like to call my process using apex_plsql_job.
    I can't get this to work. The process runs but I can't see any data in my collection. It seems that because apex_collections are session specific, running the process of populating one via apex_plsql_job creates a collection in another session so I can't access it.
    So my question is; Is it possible to do one of the following?
    1. create an apex_collection and specifying the session I want to create it in - So I can pass in a session id to my call to apex_plsql_job
    OR
    2. call apex_plsq_job using a specific session so I can synchronise the collection that way.
    OR
    3. Querying an apex_collection specifying the session (presumably by querying the underlying tables and bypassing the apex_collections view)
    Any help appreciated.
    Cheers
    Yog

    Hi Denes,
    I have a follow up question. I hope you can help.
    I've not even managed to get as far as testing your session procedures. When I try to run the below procedure using the following on page call
    see procedure code at bottom
    BEGIN
    *:P1_JOB_ID := APEX_PLSQL_JOB.SUBMIT_PROCESS(*
    p_sql => 'BEGIN extract_file('||:P1_CSV_ID||', '||:APP_SESSION||', '||:APP_USER||', 104, 1); END;',
    p_status => 'Background process submitted');
    END;
    Nothing happens. Querying the apex_plsql_job view tells be that the job has completed.
    select * from APEX_PLSQL_JOBS where job = (select max(job) from apex_plsql_jobs)
    ID                          JOB FLOW_ID OWNER       ENDUSER   CREATED   MODIFIED STATUS                                SYSTEM_STATUS SYSTEM_MODIFIED SECURITY_GROUP_ID
    *2479017510194585 110 - KF_SYSTEM ANDERSON 07-APR-10 07-APR-10 Background process submitted COMPLETE 07-APR-10*
    *940410095919087*
    However, when If run select * from APEX_030200.WWV_FLOW_COLLECTIONS$ there is no collection called "LOADER" against any user
    even if the collection was not created I would have expected my test_log table to have been populated and it is empty.
    I have tried running apex_plsql_job using
    BEGIN
    *:P1_JOB_ID := APEX_PLSQL_JOB.SUBMIT_PROCESS(*
    p_sql => 'BEGIN insert into test_log(val) values (123); END;',
    p_status => 'Background process submitted');
    END;
    and it runs fine and populates my table.
    I've tried running grant execute on extract_file to public with no effect.
    I get the feeling I'm missing something really obvious here...
    Cheers
    Yog
    CREATE OR REPLACE procedure extract_file(p_csv_id IN NUMBER, p_session_id IN NUMBER, p_user IN VARCHAR2, p_app_id IN NUMBER, p_page IN NUMBER) as
    v_blob_data BLOB;
    v_blob_len NUMBER;
    v_position NUMBER;
    v_raw_chunk RAW(10000);
    v_char CHAR(1);
    v_chunk_len NUMBER := 1;
    v_line VARCHAR2 (32767) := NULL;
    v_data_array apex_application_global.vc_arr2;
    v_rows NUMBER;
    v_sr_no NUMBER := 1;
    v_script VARCHAR2(32767);
    v_error VARCHAR2(1000);
    BEGIN
    delete from test_log;
    insert into test_log(val) values ('p_csv_id = '||p_csv_id);
    insert into test_log(val) values ('p_session_id = '|| p_session_id);
    insert into test_log(val) values ('p_user = '||p_user);
    insert into test_log(val) values ('p_app_id = '||p_app_id);
    insert into test_log(val) values ('p_page = '||p_page );
    commit;
    HTMLDB_CUSTOM_AUTH.define_user_session (p_user, p_session_id);
    HTMLDB_APPLICATION.g_flow_id := p_app_id;
    HTMLDB_CUSTOM_AUTH.post_login (p_user,
    p_session_id,
    p_app_id || ':' || p_page
    apex_collection.create_or_truncate_collection( p_collection_name => 'LOADER' );
    SELECT csv_file
    INTO v_blob_data
    FROM test_csv
    WHERE csv_id = p_csv_id;
    v_blob_len := dbms_lob.getlength( v_blob_data );
    v_position := 1;
    WHILE ( v_position <= v_blob_len ) LOOP
    v_raw_chunk := dbms_lob.substr( v_blob_data, v_chunk_len, v_position );
    v_char := chr( fiche.hex_to_decimal( rawtohex( v_raw_chunk ) ) );
    v_line := v_line || v_char;
    v_position := v_position + v_chunk_len;
    IF v_char = chr(10) THEN
    v_line := replace( v_line, ':', '^' );
    v_line := replace( v_line, ',', ':' );
    v_data_array := apex_util.string_to_table( v_line );
    v_script := ' BEGIN
    apex_collection.add_member( p_collection_name => ''LOADER'' ';
    FOR i IN 1..v_data_array.COUNT LOOP
    v_script := v_script || '
    , p_c' ||lpad(i,3,0)|| ' => ''' || replace( replace( replace( to_char( v_data_array(i) ), '^', ':' ), chr(10),'' ), chr(13), '' ) ||'''';
    END LOOP;
    v_script := v_script ||' );
    END;
    execute immediate v_script;
    v_line := NULL;
    v_sr_no := v_sr_no + 1;
    END IF;
    END LOOP;
    exception when others then
    v_error := to_char(SQLERRM);
    insert into test_log(val) values (v_error);
    commit;
    END;
    Edited by: Yog on Apr 7, 2010 2:57 PM

  • Generate PDF (BI Publisher) through APEX_PLSQL_JOB.SUBMIT_PROCESS

    Hi!
    Oracle 10.2.0.4 32, Apex 4.0.2, BIP 10.x Win.
    I have to generate cca. 1000 reports in PDF (some customer bills) through BI Publisher print server.
    PDF is defined through "Reports queries" and "Reports layouts" directly defined from Apex env. Report template is Word RTF file. Report query has one parameter:
    and R.BILL_ID = :G_BILL_IDRunning from App page process it is not acceptable to do that because operation should takes hours and user cannot have open freezed browser.
    So I found out "APEX_PLSQL_JOB.SUBMIT_PROCESS", which submit process in "job" as background process.
    On page I left just "SUBMIT_PROCESS" call:
    BEGIN
      APEX_PLSQL_JOB.SUBMIT_PROCESS ('begin bills_pkg.generate_biils; end');
    END;and put the whole logic in package. Small problem was to change Apex item (Application item), what I solved and change with:
    APEX_UTIL.set_session_state(p_name => 'G_BILL_ID', p_value => cur_array(i).B_ID);for every record in cursor (I know his is not optimal but I just wanted to get working demo).
    Call from package procedure is like (slightly modified from Apex page process which was working!):
    open cur;
      -- assign to have that value as parameter for !??
      APEX_UTIL.set_session_state(p_name => 'G_BILL_ID', p_value => cur_array(i).B_ID);
      print_one_report (cur_array(i).B_ID);
    close cur;where "print_one_report" is mine procedure which saves PDF in db (proc was the same as before when was working but with too long result).
    Unfortunately then all generated PDF reports (which I save in database) has 0 bytes length (I call the same procedure called as before when reports were generated but from Apex page process directly).
    Seems that "G_BILL_ID" is no longer having correct values ... like session problems.
    How to achieve and fix that (generate PDF from cursor) or is there any article how to manage BI Publisher printing with APEX_PLSQL_JOB.SUBMIT_PROCESS?
    Rg,
    Damir Vadas
    P.S.
    Should
    apex_custom_auth.define_user_session (p_user, p_session_id );
    apex_application.g_flow_id := p_app_id;might help?
    Edited by: user1050751 on May 13, 2011 12:57 PM

    Damir,
    Here is one way that you could get a background job to create your thousand reports (4 steps).
    1st define your report query and layout within APEX (and BI-Publisher builder - Word plugin).
    2nd write a custom process to call apex_util.get_print_document to generate your 1000 reports and place them in a blob column.
    http://download.oracle.com/docs/cd/E17556_01/doc/apirefs.40/e15519/apex_util.htm#CHDDECIA
    DECLARE
        l_document BLOB;
         l_security_group_id NUMBER;
        CURSOR your_cur IS
        SELECT...your thousand records
    BEGIN
        wwv_flow_api.set_security_group_id(p_security_group_id);
        l_security_group_id := wwv_flow_api.get_security_group_id;
        FOR your_rec IN your_cur LOOP
            BEGIN
                 set any item values that will be referenced in your report query here
                 l_document := APEX_UTIL.GET_PRINT_DOCUMENT (p_application_id     => v_your_app_id,
                                                             p_report_query_name  => v_your_defined_report_name,
                                                             p_report_layout_name => v_your_defined_layout_name,
                                                             p_report_layout_type => 'rtf',
                                                             p_document_format    => 'pdf',
                                                             --p_print_server             =>
                INSERT INTO your_table... id, l_document, file_name, mime_type...
                COMMIT;
            EXCEPTION
                WHEN others THEN
                      write an error to a job log...
            END;
        END LOOP;
    EXCEPTION
         WHEN others THEN
               write an error to a job log...
    END;3rd write logic that will submit your custom process using APEX_PLSQL_JOB.SUBMIT_PROCESS or you can use dmbs_scheduler package.
    4th write code to retrieve the report data from the blob column and display or distribute to users.
    I've never called the apex_util.get_print_document recursively like this before so I'm not sure how it will perform. There are 4 versions of the get_print_document API so use the one that best fits your needs with performance in mind.
    After writing the above logic I found this post that is very similar.
    Scheduling reports with dbms_scheduler
    An alternative method to what I've listed above is scheduling reports using the Bi-Publisher web service.
    http://bipconsulting.blogspot.com/2010/04/how-to-schedule-report-with-bi.html
    Regards,
    Todd
    Edited by: tfa on May 16, 2011 8:03 AM

  • Syntax for APEX_PLSQL_JOB.SUBMIT_PROCESS with an OUT parameter

    Hi All,
    I am using APEX_PLSQL_JOB.SUBMIT_PROCESS and calling a procedure that has both an IN and an OUT parameter.
    The IN parameter works fine; I am able to call my procedure from APEX and pass it the :APP_JOB item as the IN parameter. The OUT parameter I can't get working. I can call my procedure from a different block in SqlDeveloper and everything works, so I'm confident that my procedure code is correct. I just can't get the OUT parameter returned via APEX.
    This is the plsql code that I'm calling from an APEX dynamic action:
    DECLARE
      l_sql      VARCHAR2(4000);
      l_instance VARCHAR2(30);
       l_job number;
      l_rows_processed number;
    BEGIN
    l_instance := :P9_INSTANCE;
      l_sql      := 'BEGIN update_tl_tables_1(:APP_JOB, :F103_ROWS_PROCESSED); END;';
      l_job      := APEX_PLSQL_JOB.SUBMIT_PROCESS( p_sql => l_sql, p_status => 'Background process submitted');
    l_rows_processed := :F103_ROWS_PROCESSED;
    insert into gse_lng_jobs (instance, job_id, rows_processed) values (l_instance, l_job, l_rows_processed);
    COMMIT;
    END; My procedure is created as:
    create or replace
    procedure UPDATE_TL_TABLES_1 (l_app_job IN number, l_rows_processed OUT number)
    IS......Again, this works fine from SqlDeveloper. Can anyone suggest the proper plsql code? I've tried this using a page item, a system item etc. and no luck. I first tried just passing my procedure a local variable like l_rows_processed, but the procedure wouldn't even run, so I'm assuming the API needs an actual APEX item but I'm out of ideas here.
    thanks in advance,
    john

    That's not going to work because the job hasn't run yet when you perform the insert. So :F103_ROWS_PROCESSED wont contain anything useful.
    Why don't you try performing the insert as part of the job, e.g.
    l_sql := 'BEGIN update_tl_tables_1(:APP_JOB, :F103_ROWS_PROCESSED); insert into gse_lng_jobs (instance, job_id, rows_processed) values ('''||l_instance||''', '||l_job||', :F103_ROWS_PROCESSED); END;';
    ...something like that.

  • Apex_plsql_job.submit_process PLS-00221: 'SUBMIT_PROCESS' is not a procedur

    Hi,
    i tried to use apex_plsql_job
    declare
    l_job number;
    begin
    apex_plsql_job.submit_process( l_job, 'p_upd;', sysdate);
    end;
    and i have this error
    ORA-06550: line 7, column 3:
    PLS-00221: 'SUBMIT_PROCESS' is not a procedure or is undefined
    ORA-06550: line 7, column 3:
    PL/SQL: Statement ignored5. begin
    6.
    7. apex_plsql_job.submit_process( l_job, 'p_se0cas_upd;', sysdate);
    8.
    9. end;
    Apex 3.1.2
    Oracle 10.1.0.5
    Thanks in advance
    km

    Hi,
    I solved using a procedure
    Many Thanks
    km

  • APEX_PLSQL_JOB: How to end/kill jobs

    Hi,
    I'm wondering if there's a good way to kill jobs that were created using APEX_PLSQL_JOB.
    I have a situation where I create a job using APEX_PLSQL_JOB. The process that it is executing will take a long time to run. After a while I decide that I need to end this job since it's slowing down the server. How can I terminate it?
    I've tried the following:
    - Kill the Oracle session that is executing the code. This terminated the process but just restarted it again a few seconds later
    - Purge the process using APEX_PLSQL_JOB.PURGE_PROCESS. This removed it from the list of APEX PL_SQL jobs in the APEX_PLSQL_JOBS view. It had no effect on the processing of the job.
    Any other ideas on how I can kill the process that I started?
    Thank you,
    Martin
    [http://apex-smb.blogspot.com/]

    On a related note, this is yet another great example of when to use the database resource manager. You could:
    - create a resource consumer group called "LONG_RUNNING_STUFF"
    - that group gets dropped to say 5% CPU after 5 min (just as an example)
    - any session in that group that has an operation that lasts longer than 20 minutes automatically killed (just as an example)
    - in your job code, make a call to DBMS_SESSION.SWITCH_CURRENT_CONSUMER_GROUP() to have that session put itself into the LONG_RUNNING_STUFF group (you need to assign a priv for this)
    It's a great way to let the db manage itself so you don't have to monitor sessions. You might also consider instrumenting your code with dbms_application_info.set_session_longops()
    Tyler Muth
    http://tylermuth.wordpress.com
    [Applied Oracle Security: Developing Secure Database and Middleware Environments|http://sn.im/aos.book]

  • Apex_plsql_job.submit not working

    Hi All,
    We are using apex_plsql_job.submit for the background job. I face no issue until the database is refreshed. Now when i submit any job which uses this function is not submitting at all.
    I checked the APEX_PLSQL_JOB.JOBS_ARE_ENABLED and it is enabled .
    Am not sure whether the recent refresh is causing the issue, can anyone please help on this?
    Thanks in advance.
    I am using oracle apex 4.0
    Thanks
    Raj

    RajEndiran wrote:
    Hi All,
    We are using apex_plsql_job.submit for the background job. I face no issue until the database is refreshed. Now when i submit any job which uses this function is not submitting at all.
    I checked the APEX_PLSQL_JOB.JOBS_ARE_ENABLED and it is enabled .
    Am not sure whether the recent refresh is causing the issue, can anyone please help on this?
    Thanks in advance.
    I am using oracle apex 4.0
    Thanks
    RajHell Raj,
    What do you mean when you say "database is refreshed"?
    BTW have you checked following view to see the status of your job?
    select * from APEX_PLSQL_JOBSRegards,
    Hari

  • Apex_plsql_job.submit_process job not Working through Apex

    Hi,
    I am using Apex 4.2 and Oracle DB 11g.
    I have a process (which calls a procedure) to run on page load which is taking quiet some time (more than a min) so I thought of using Apex_Plsql_job API. It is submitting the job (though it is submitting the job to DBA_JOBS rather than APEX_PLSQL_JOBS as said by Doc which even disappears in no time from dba_jobs).
    declare
    l_sql VARCHAR2(4000);
    l_job NUMBER;
    begin
        l_sql := 'BEGIN Pkg.procedure(param1); END;';
        l_job := APEX_PLSQL_JOB.SUBMIT_PROCESS(p_sql => l_sql, p_status => 'Background process submitted');
    end;
    Now My issue is the procedure is not being called. Am I missing something. Can anyone help me pls.
    Thanks,
    Shoaib

    Hi,
    APEX_PLSQL_JOB package works just fine for me.
    What I did check your code I think there is mistake. You have not declare parameter "param1" for job PL/SQL code
    Maybe code should look like this
    DECLARE
      l_sql VARCHAR2(4000);
      l_job NUMBER;
    BEGIN
      l_sql := q'!DECLARE param1 VARCHAR2(255) := 'MY_VALUE'; BEGIN Pkg.procedure(param1); END;!';
      l_job := APEX_PLSQL_JOB.SUBMIT_PROCESS(p_sql => l_sql, p_status => 'Background process submitted');
    END;
    Or something like
    DECLARE
      l_sql VARCHAR2(4000);
      l_job NUMBER;
    BEGIN
      l_sql := 'BEGIN Pkg.procedure(' || Px_MY_ITEM || '); END;';
      l_job := APEX_PLSQL_JOB.SUBMIT_PROCESS(p_sql => l_sql, p_status => 'Background process submitted');
    END;
    Regards,
    Jari

  • APEX_PLSQL_JOB - how to get the status

    Hi,
    I am submitting a package using APEX_PLSQL_JOB.SUBMIT_PROCESS on the click of a button.
      l_job_id :=  APEX_PLSQL_JOB.SUBMIT_process ( 'BEGIN   my_pkg;  END;' );Now I have validations that the button cannot be submitted again, which works fine.
    I want to inform the user once the process has completed. How do I do that?.
    I send out a mail once the process is complete. This is sent from the package.
    The whole process takes around 20 mins, so the mail option is fine but I also want some kind of a indication on the APEX page that the process completed successfully.
    I know about this table htmldb_plsql_jobs where I can check the status, but once I submit the job it runs asyncronously. So at what point should I check this table?
    Thanks,
    VS.

    Hello,
    you have 2 simpler options.
    1. If the job gets created with DBMS_SCHEDULER_JOBS you can query the ALL_SCHEDULER_JOB_RUN_DETAILS to see if it has completed successfully or not. If it doesn't appear in there it hasn't finished yet.
    2. If it isn't using Scheduler you can create a log table and just insert into it from at the end of your procedure in the job and then query on it.
    Also if you would like to read on DBMS_SCHEDULER_JOBS you can find more info here
    You could use these jobs independently because of their flexibility and excellent tracking capabilities.
    Thank you,
    Alex.
    Edited by: Banu Alexandru on 25.05.2013 15:36

  • How to set pl/sql function as background job in apex?

    Hi,
    I wrote a function which returns boolean value based on result.This function updates a table everyday.How to set this as a background job?or do I need to use dbms_job only?
    Thanks,
    Mahender.

    No, you can use APEX_PLSQL_JOB.
    Example:
    DECLARE
    l_sql VARCHAR2(4000);
    l_job NUMBER;
    BEGIN
    l_sql := 'BEGIN MY_PACKAGE.MY_PROCESS; END;';
    l_job := APEX_PLSQL_JOB.SUBMIT_PROCESS(
    p_sql => l_sql,
    p_status => 'Background process submitted');
    --store l_job for later reference
    END;
    full documentation link [http://download.oracle.com/docs/cd/E14373_01/apirefs.32/e13369/apex_plsql_job.htm#BGBCJIJI]
    If I help you, please stamp my answer as CORRECT or HELPFULL :)

  • Dbms_job submit status

    Hi,
    I need to disable/hide the submit button after i submit the job using dbms_job submit process.
    Also after after completion needs to enable the button.
    Is there any background process i can run which enable or disable the button?
    Thanks,
    K

    Hi,
    Client (your browser) need check status from server.
    Here is one example that might help
    https://apex.oracle.com/pls/otn/f?p=40323:69
    When you press "Submit Job" button page is submitted and process creates job using APEX_PLSQL_JOB.
    Then window is refresh every 10 sec, until job finish.
    I did create application item G_META_TAG
    I did place to page HTML header
    &G_META_TAG.Then I did create display only item Px_JOB_RUNNING and Px_JOB_ID
    Computation "PL/SQL Function body" for Px_JOB_RUNNING
    FOR c1 IN(
      SELECT 1
      FROM apex_plsql_jobs
      WHERE (job = :Px_JOB_ID OR :Px_JOB_ID IS NULL)
      AND system_status = 'COMPLETE'
    )LOOP
      RETURN 'No';
    END LOOP;
    RETURN 'Yes';Computation "PL/SQL Function body" for G_META_TAG
    IF :Px_JOB_RUNNING = 'Yes' THEN
      RETURN '<meta http-equiv="refresh" content="10">';
    ELSE
      RETURN NULL;
    END IF;Then submit button conditionally Px_JOB_RUNNING value "No".
    Page after submit process
    DECLARE
      l_sql VARCHAR2(4000);
      l_job NUMBER;
    BEGIN
      l_sql := '
        BEGIN
          FOR i IN 1..3
          LOOP
            APEX_UTIL.PAUSE(10);
          END LOOP;
        END;
      l_job := APEX_PLSQL_JOB.SUBMIT_PROCESS(
        p_sql => l_sql,
        p_status => 'Background process submitted'
      --store l_job for later reference
      :PX_JOB_ID := l_job;
      :PX_JOB_RUNNING := 'Yes';
    END;I did make process conditionally by submit button and Px_JOB_RUNNING value "No"
    This is not ready solution and probably have bugs.
    One thing is specially how you check is job running.
    My sample stores job id to item session state. Value is lost if user logout, close browser or clears cache.
    Then user can submit job again, even previous job is running.
    Anyway I hope it give idea for you how continue.
    You can do similar check using Ajax/dynamic actions. Then whole window is not refreshed.
    Regards,
    Jari
    Edited by: jarola on Nov 18, 2010 7:10 PM
    Here is sample using Ajax
    http://actionet.homelinux.net/htmldb/f?p=100:93

  • Timeout error when calling package

    Hi,
    I have an application that calls a package, this package has a process that lasts 40 minutes, 30 minutes with the browser displays the following error:
    Explanation: The request timed out before the page could be retrieved.
    Try the following:
    Refresh page: Search for the page again by clicking the Refresh button. The timeout may have occurred due to Internet congestion.
    Check spelling: Check that you typed the Web page address correctly. The address may have been mistyped.
    Access from a link: If there is a link to the page you are looking for, try accessing the page from that link.
    Contact website: You may want to contact the website administrator to make sure the Web page still exists. You can do this by using the e-mail address or phone number listed on the website home page.
    If you are still unable to view the requested page, try contacting your administrator or Helpdesk.
    Technical Information (for support personnel)
    Error Code 64: Host not available
    Background: The gateway or proxy server lost connection to the Web server.
    Date: 07/01/2012 14:05:39 [GMT]
    Server: SVGFIRE.svgmatriz.local
    Source: Remote server In the application properties:
    Session Timeout
    Maximum Session Length in Seconds, is 0
    Maximum Session Idle Time in Seconds, is 0
    I'm using Firefox 9
    The same error occurs in Chrome.
    Do I have to mess around with settings Browser Timeout? Or is some configuration of Apex?
    thank you
    Márcio Gonçalez

    mag.goncalez wrote:
    Thanks for the tip fac586,
    using apex_plsql_job execution is ok.
    Just wanted to know if there is another way without using Job, since the problem is related to timeout.And Alex and I are trying to convince you that it's the wrong problem. The timeout doesn't affect the execution of the job. Once that has started on the database it's going to complete (successfully or not), regardless of whether the user sits staring at an unresponsive screen for 30 or 40 minutes and/or gets a timeout message. Given that, it makes sense to run it asynchronously in the background and avoid the possibility of a timeout. This lets the user get on with something else in their session.
    You can modify the package so that the job sends email or SMS messages reporting when it is complete (successfully or unsuccessfully); you can use <tt>apex_plsql_job.update_job_status</tt> or <tt>dbms_application_info.set_session_longops</tt> as a mechanism to provide feedback on progress somewhere in your application.

Maybe you are looking for