2017-08-28 43 views
0

我想通過pl/sql進程創建oracle調度程序作業(發送郵件)(按鈕單擊時創建作業)。它成功地創造就業崗位,但始終與錯誤完成:Oracle調度程序錯誤:安全組ID(您的工作區標識)無效

"ORA-20001: Security Group ID (your workspace identity) is invalid. ORA-06512: at "APEX_050100.WWV_FLOW_SECURITY", line 2939 ORA-06512: at "APEX_050100.HTMLDB_UTIL", line 3014 ORA-06512: at line 7 ORA-06512: at line 7.

我也試圖security_group_id直接(apex_util.set_security_group_id(p_security_group_id => my_worspace_idwwv_flow_api.set_security_group_id(p_security_group_id=>my_worspace_id)設定,但總是相同的錯誤我的示例代碼完成。當我嘗試在SQL開發人員手動創建作業時,它可以工作。但是當pl/sql過程創建工作時,它完成了所提到的錯誤。在這兩種情況下(PL/SQL過程或手動)創建作業成功與相同的參數,所以我不明白爲什麼在作業是由PL/SQL過程創建時,它完成的錯誤。

BEGIN 
    DBMS_SCHEDULER.CREATE_JOB (
      job_name => '"INVERTORY"."TEST"', 
      job_type => 'PLSQL_BLOCK', 
      job_action => 'begin 
for c1 in (
    select workspace_id 
    from apex_applications 
    where application_id = 104) 
loop 
    apex_util.set_security_group_id(p_security_group_id => 
c1.workspace_id); 
end loop; 

HTMLDB_MAIL.SEND(
       p_to => ''****.****@****.com'', 
       p_from => ''[email protected]****.com'', 
       p_subj => ''test mail'', 
       p_body => ''komu''); 

      end;', 
      number_of_arguments => 0, 
      start_date => TO_TIMESTAMP_TZ('2017-08-28 10:29:57.000000000 EUROPE/PRAGUE','YYYY-MM-DD HH24:MI:SS.FF TZR'), 
      repeat_interval => NULL, 
      end_date => NULL, 
      enabled => TRUE, 
      auto_drop => FALSE, 
      comments => ''); 

    DBMS_SCHEDULER.SET_ATTRIBUTE( 
      name => '"INVERTORY"."TEST"', 
      attribute => 'logging_level', value => DBMS_SCHEDULER.LOGGING_OFF); 

    DBMS_SCHEDULER.enable(
      name => '"INVERTORY"."TEST"'); 
END; 

回答

0

嘗試修改此:

for c1 in (
    select workspace_id 
    from apex_applications 
    where application_id = 104) 
loop 
    apex_util.set_security_group_id(p_security_group_id => 
c1.workspace_id); 
end loop; 

要這樣:

SELECT MAX(workspace_id) 
    INTO v_workspace FROM apex_applications 
    WHERE application_id = 104; 
--set workspace - declare v_workspace above as type number 
    wwv_flow_api.set_security_group_id(v_workspace) 

在任何情況下,這將是更好地把你的邏輯在數據庫中的包,並創建一個作業與job_type => 'STORED_PROCEDURE'並從那裏調用你的程序。

+0

我已經嘗試過,但我得到錯誤:ORA-20001:此過程必須從應用程序會話內調用。 ORA-06512:在 「APEX_050100.WWV_FLOW_MAIL」,線路595 ORA-06512:在 「APEX_050100.WWV_FLOW_MAIL」,線路621 ORA-06512:在 「APEX_050100.WWV_FLOW_MAIL」,線路654 ORA-06512:在「APEX_050100 .WWV_FLOW_MAIL_API「,第47行 ORA-06512:在第17行 – john179

+0

現在沒有時間回覆,但此線程可能有所幫助 - https://community.oracle.com/thread/3998543 – RLOG

+0

此外,請嘗試使用' apex_mail.send',而不是'HTMLDB_MAIL.SEND',後面跟着'apex_mail.push_queue();' – RLOG