无法从通过db链接访问数据的视图中获取数据

时间:2013-07-23 07:47:28

标签: sql oracle oracle10g distributed-computing

我有一个查询来通过db链接从两个表中获取数据,如下所示:

SELECT a.ID, a.NAME, b.address
  FROM table1@dblink a, table2@dblink b
 WHERE a.ID = b.ID;

这完全没问题。然后我为此创建一个视图,如下所示:

CREATE VIEW myview
AS
   SELECT a.ID, a.NAME, b.address
     FROM table1@dblink a, table2@dblink b
    WHERE a.ID = b.ID;

视图已成功创建。但是当我从视图中选择数据时如下:

SELECT *
  FROM myview

我得到的错误如下:

ORA-00942: table or view does not exist
ORA-02063: preceding line from MYLINK

可能是什么问题?

编辑:

尝试了不同的方法,最终得到了不同的错误。在这里,我发布确切的查询和最新的错误:

CREATE OR REPLACE VIEW plan_view
AS
   WITH plan_name AS
        (SELECT     fcr.argument1 AS plan_name, fcr.request_id AS request_id
               FROM apps.fnd_concurrent_requests@dblink fcr
              WHERE argument1 IN
                             ('E10', 'E20', 'E40', 'E60L', 'EDC', 'PS1', 'S')
         CONNECT BY PRIOR fcr.request_id = fcr.parent_request_id
         START WITH request_id =                                 -- '58043920'
                       (SELECT MAX (request_id) AS request_id
                          FROM apps.fnd_concurrent_requests@dblink
                         WHERE description = 'Mail Program'
                           AND actual_start_date >=
                                  TO_DATE (   TO_CHAR (TRUNC (SYSDATE - 1),
                                                       'mm-dd-yyyy'
                                                      )
                                           || '05:00:00 PM',
                                           'MM-DD-YYYY HH:MI:SS PM'
                                          )
                           AND actual_start_date < SYSDATE)),
        e10 AS
        (SELECT     TRIM
                       (BOTH ' ' FROM (SELECT meaning
                                         FROM apps.fnd_lookup_values@dblink
                                        WHERE lookup_type = 'CP_STATUS_CODE'
                                          AND lookup_code = fcr.status_code
                                          AND view_application_id = 0)
                       ) status,
                    TRIM
                       (BOTH ' ' FROM (SELECT meaning
                                         FROM apps.fnd_lookup_values@dblink
                                        WHERE lookup_type = 'CP_PHASE_CODE'
                                          AND lookup_code = fcr.phase_code
                                          AND view_application_id = 0)
                       ) phase,
                    fcr.request_id AS rid,
                    fcr.actual_start_date AS start_date,
                    fcr.actual_completion_date AS completion_date
               FROM apps.fnd_concurrent_requests@dblink fcr
         CONNECT BY PRIOR fcr.request_id = fcr.parent_request_id
         START WITH request_id = (SELECT request_id
                                    FROM plan_name
                                   WHERE plan_name IN ('E10')))
   SELECT 'E10' "PLAN_NAME", (SELECT MIN (start_date)
                                FROM e10) "START_DATE",
          (SELECT COUNT (rid)
             FROM e10)
     FROM DUAL

当我尝试直接从查询中选择时,我得到了正确的输出。但在我创建视图并尝试select * from plan_view后,我收到以下错误:

ORA-00604: error occurred at recursive SQL level 1
ORA-00904: "FCR"."REQUEST_ID": invalid identifier

1 个答案:

答案 0 :(得分:1)

这听起来像是授予权限的旧问题。对于临时DML(选择,插入等),我们可以使用通过角色授予的权限。但是要构建永久对象 - 视图,存储过程等 - 我们必须直接授予用户特权。

因此,您所描述的现象最常见的解释是,表的所有者已将这些表的权利授予不属于您的角色。