0
SELECT /*+ DRIVING_SITE(fcr) */
       fcr.request_id,
       DECODE
             (fcpt.user_concurrent_program_name,
              'Report Set', fcr.description,
              'Request Set Stage', fcr.description,
              fcpt.user_concurrent_program_name
             ) user_concurrent_program_name,
       fcr.description, fcr.argument_text, fcr.concurrent_program_id,
       fcr.parent_request_id, fcr.actual_start_date,
       fcr.actual_completion_date,
       ROUND ((fcr.actual_completion_date - fcr.actual_start_date) * 24 * 60,
              4
             ) runtime,
       DECODE (fcr.phase_code, 'C', 'No Schedule') program_status,
       fu.user_name, frt.responsibility_name, fcr.logfile_name
  FROM apps.fnd_concurrent_requests@db_link fcr,
       apps.fnd_concurrent_programs_tl@db_link fcpt,
       apps.fnd_user@db_link fu,
       apps.fnd_responsibility_tl@db_link frt
 WHERE fcr.concurrent_program_id = fcpt.concurrent_program_id
   AND fcr.requested_by = fu.user_id
   AND fcr.responsibility_id = frt.responsibility_id
   AND fcr.responsibility_application_id = frt.application_id
   AND fcr.phase_code = 'C'
   AND fcr.status_code IN ('C', 'G', 'E', 'X')
   AND fcr.actual_completion_date >= SYSDATE - 1 / 24
   AND fcr.requested_by = 1508715
   AND fcr.request_id NOT IN (
                             SELECT parent_request_id
                               FROM apps.fnd_concurrent_requests@db_link)

我编写了上面的查询来获取程序的详细信息,这些程序也是其他程序的父程序。但由于某种原因,此查询不返回任何结果。所以我写了下面的查询:

SELECT /*+ DRIVING_SITE(fcr) */
       fcr.request_id,
       DECODE
             (fcpt.user_concurrent_program_name,
              'Report Set', fcr.description,
              'Request Set Stage', fcr.description,
              fcpt.user_concurrent_program_name
             ) user_concurrent_program_name,
       fcr.description, fcr.argument_text, fcr.concurrent_program_id,
       fcr.parent_request_id, fcr.actual_start_date,
       fcr.actual_completion_date,
       ROUND ((fcr.actual_completion_date - fcr.actual_start_date) * 24 * 60,
              4
             ) runtime,
       DECODE (fcr.phase_code, 'C', 'No Schedule') program_status,
       fu.user_name, frt.responsibility_name, fcr.logfile_name
  FROM apps.fnd_concurrent_requests@db_link fcr,
       apps.fnd_concurrent_programs_tl@db_link fcpt,
       apps.fnd_user@db_link fu,
       apps.fnd_responsibility_tl@db_link frt
 WHERE fcr.concurrent_program_id = fcpt.concurrent_program_id
   AND fcr.requested_by = fu.user_id
   AND fcr.responsibility_id = frt.responsibility_id
   AND fcr.responsibility_application_id = frt.application_id
   AND fcr.phase_code = 'C'
   AND fcr.status_code IN ('C', 'G', 'E', 'X')
   AND fcr.actual_completion_date >= SYSDATE - 1 / 24
   AND fcr.requested_by = 1508715
   AND fcr.request_id IN (SELECT request_id FROM apps.fnd_concurrent_requests@db_link
MINUS SELECT parent_request_id FROM apps.fnd_concurrent_requests@db_link)

此查询每次返回大约 300 到 400 行。但我不明白这两个查询之间的区别。此外,这两个查询都需要一个多小时才能运行。如何提高效率?

4

1 回答 1

1

Parent_request_id 包含空值,对吗?然后第一个子选择在结果中包含空值,而 NOT IN 子句导致 UNKNOWN,而不是 TRUE。比较一下:

select 'found' from dual
  where 1 not in (2,3,4);

'FOUN
-----
found

select 'found' from dual
  where 1 not in (2,3,4, null);

no rows selected

根据效率 - 影响效率的因素有很多。首先,我会将您的选择存储到您使用@db_link 作为视图引用的数据库中并查询this_view@db_link。在您的选择中,所有对象都存储在远程数据库中,优化器无法检查您的选择权。

于 2013-06-25T11:06:29.747 回答