2
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;

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

4

1 回答 1

1

您是否尝试过使用user_scheduler_job_run_detailsall_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;
于 2013-10-03T21:22:45.863 回答