在oracle sql开发人员中进行偏移和获取

时间:2016-03-04 08:26:05

标签: sql oracle oracle-sqldeveloper

我们有数百万的数据(总行1698393)。虽然在文本中导出此数据需要4个小时。我需要知道是否有办法使用SQL Developer减少Oracle数据库中那些记录的导出时间。

with cte as (
  select *
  from (
   select distinct
          system_serial_number,
          ( select s.system_status
            from   eim_pr_system s
            where  .system_serial_number=a.system_serial_number
          ) system_status,
          ( select SN.cmat_customer_id
            from   EIM.eim_pr_ib_latest SN
            where  SN.role_id=19
            and    SN.system_serial_number=a.system_serial_number
          ) SN_cmat_customer_id,
          ( select  EC.cmat_customer_id
            from EIM.eim_pr_ib_latest EC
            where EC.role_id=1
            and   a.system_serial_number=EC.system_serial_number
          ) EC_cmat_customer_id
    from  EIM.eim_pr_ib_latest a
    where a.role_id in (1,19)
  ) 
  where nvl(SN_cmat_customer_id,0)!=nvl(EC_cmat_customer_id,0)
)
select system_serial_number,
       system_status,
       SN_CMAT_Customer_ID,
       EC_CMAT_Customer_ID,
       C.Customer_Name SN_Customer_Name,
       D.Customer_Name EC_Customer_Name
from   cte,
       eim.eim_party c,
       eim.eim_party D
where  c.CMAT_Customer_ID=SN_cmat_customer_id
and    D.CMAT_Customer_ID=EC_cmat_customer_id;
offset first 5001 rows fetch next 200000 rows only

2 个答案:

答案 0 :(得分:0)

您可以通过执行以下操作来摆脱大量连接和相关子查询(通过减少表扫描的数量来加快速度):

SELECT a.system_serial_number,
       s.system_status,
       a.SN_cmat_customer_id,
       a.EC_cmat_customer_id,
       a.SN_customer_name,
       a.EC_customer_name
FROM   (
  SELECT l.system_serial_number,
         MAX( CASE l.role_id WHEN 19 THEN l.cmat_customer_id END ) AS SN_cmat_customer_id,
         MAX( CASE l.role_id WHEN  1 THEN l.cmat_customer_id END ) AS EC_cmat_customer_id
         MAX( CASE l.role_id WHEN 19 THEN p.customer_name END ) AS SN_customer_name,
         MAX( CASE l.role_id WHEN  1 THEN p.customer_name END ) AS EC_customer_name
  FROM   EIM.eim_pr_ib_latest l
         INNER JOIN
         EIM.eim_aprty p
         ON ( p.CMAT_Customer_ID= l.cmat_customer_id )
  WHERE  l.role_id IN ( 1, 19 )
  GROUP BY system_serial_number
  HAVING    NVL( MAX( CASE l.role_id WHEN 19 THEN l.cmat_customer_id END ), 0 )
         <> NVL( MAX( CASE l.role_id WHEN  1 THEN l.cmat_customer_id END ), 0 )
) a
LEFT OUTER JOIN
eim_pr_system s
ON ( s.system_serial_number=a.system_serial_number )

由于您的原始查询没有在相关子查询上抛出TOO_MANY_ROWS异常,我假设您的数据是这样的,每个相关查询只返回一行,而上述查询将反映你的输出(虽然没有一些样本数据很难测试)。

答案 1 :(得分:0)

除了“快速查询”之外&#39; - 有一种方法可以使用SQL Developer实现更快的导出。

使用数据网格时,导出功能 - 这将再次执行查询。这不会发生的唯一一次是你是否已将所有行都输入到网格中。这样做对于非常大的数据集将是昂贵的&#39;在客户端,但你可以避免这种情况。

要加快导出速度,请在select中添加/*csv*/注释,并使用假脱机c:\ my_file.csv包装该语句 - 然后折叠脚本输出面板,并使用F5运行该注释。在我们获取数据时,我们会以CSV格式将其写入该文件。

/*csv*/
/*xml*/
/*json*/
/*html*/
/*insert*/

我详细讨论了这个功能here