ORA-00942: 表或視圖不存在 dba_objects

來源:互聯網
上載者:User

create type date_obj as object (
    month varchar2(20),
    sun char(2),
    mon char(2),
    tue char(2),
    wed char(2),
    thu char(2),
    fri char(2),
    sat char(2)
);
/
create type date_obj_tab as table of date_obj;
/

 

create or replace function get_date_str(in_date in date default sysdate)
  return date_obj_tab
  pipelined is
  date_o date_obj := date_obj(to_char(in_date, 'Month'),
                              1,
                              1,
                              1,
                              1,
                              1,
                              1,
                              1);
  cursor c1 is
    select sum(case
                 when date_str = 'sun' then
                  date_d
               end) sun,
           sum(case
                 when date_str = 'mon' then
                  date_d
               end) mon,
           sum(case
                 when date_str = 'tue' then
                  date_d
               end) tue,
           sum(case
                 when date_str = 'wed' then
                  date_d
               end) wed,
           sum(case
                 when date_str = 'thu' then
                  date_d
               end) thu,
           sum(case
                 when date_str = 'fri' then
                  date_d
               end) fri,
           sum(case
                 when date_str = 'sat' then
                  date_d
               end) sat
      from (select to_number(to_char(date_d, 'dd')) date_d,
                   to_char(date_d, 'dy') date_str,
                   to_number(to_char(date_d, 'ddd')) -
                   to_number(to_char(date_d, 'd')) date_w
              from (select trunc(date_d) + rownum - 1 date_d
                      from DBA_OBJECTS a,
                           (select trunc(in_date, 'mm') date_d from dual) b
                     where rownum <=
                           to_number(to_char(last_day(date_d), 'dd'))))
     group by date_w;
begin
  for rs in c1 loop
    date_o.sun := rs.sun;
    date_o.mon := rs.mon;
    date_o.tue := rs.tue;
    date_o.wed := rs.wed;
    date_o.thu := rs.thu;
    date_o.fri := rs.fri;
    date_o.sat := rs.sat;
    pipe row(date_o);
  end loop;
  return;
end;

 

Compilation errors for FUNCTION LANDUSER.GET_DATE_STR

Error: PL/SQL: ORA-00942: 表或視圖不存在
Line: 46
Text: from dba_objects a,

解決辦法

connect sys/ as sysdba;

grant   select   on   DBA_OBJECTS   to   landuser;

 

 

select * from table(get_date_str(sysdate-10));

MONTH SU MO TU WE TH FR SA
-------------------- -- -- -- -- -- -- --
March 1 2 3 4 5
March 6 7 8 9 10 11 12
March 13 14 15 16 17 18 19
March 20 21 22 23 24 25 26
March 27 28 29 30 31

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.