函数中的dba_scheduler_job_run_details返回空光标

时间:2013-10-03 13:42:10

标签: sql oracle

grant select on sys.dba_scheduler_job_run_details to user;

create or replace function view_failed_jobs(start_date in timestamp,
                                            rc       out sys_refcursor) return integer is
begin
  open rc for
    select   t.OWNER,
             t.job_name,
             t.ACTUAL_START_DATE,
             t.ADDITIONAL_INFO
      from dba_scheduler_job_run_details t
     where t.STATUS like 'FAILED'
           and t.ACTUAL_START_DATE > start_date;
  return(1);
end view_failed_jobs;

当我尝试执行此函数时,它返回空光标。但是当我选择它时返回数据。  如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

您是否尝试过使用 user_scheduler_job_run_details all_scheduler_job_run_details 而不是 dba_scheduler_job_run_details

向用户帐户授予对dba_视图的访问权限通常是个坏主意。

另一种解决方案是将该函数创建为sys / system帐户,并将 AUTHID DEFINER 子句添加到该函数中,并授予用户对该函数的访问权。

http://psoug.org/definition/AUTHID.htm

create or replace function view_failed_jobs(
    start_date in timestamp,
    rc out sys_refcursor
) return integer AUTHID DEFINER
is
begin
  open rc for
    select   t.OWNER,
             t.job_name,
             t.ACTUAL_START_DATE,
             t.ADDITIONAL_INFO
      from dba_scheduler_job_run_details t
     where t.STATUS like 'FAILED'
           and t.ACTUAL_START_DATE > start_date;
  return(1);
end view_failed_jobs;

grant execute on view_failed_jobs TO user;