0
UPDATE t1
   SET t1.language_id = (SELECT distinct(CASE WHEN NETWORK.nid = 11 
                                  THEN 10
                                  ELSE 7
                              END)
                       FROM PROFILE,
                            NETWORK
                      WHERE PROFILE.STATUS IN ('A','U','S','H','I')
                        AND PROFILE.mid = t1.mid
                        AND NETWORK.mid = t1.mid
                        AND t1.is_deleted = 'N')

   AND EXISTS( SELECT 1

              FROM PROFILE,
                   NETWORK
             WHERE PROFILE.STATUS IN ('A','U','S','H','I')
               AND PROFILE.mid = t1.mid
               AND NETWORK.mid = t1.mid
               AND t1.is_deleted = 'N');

这是慢下来的方式。对使用语句使用不同的更新?为 10 进行一次更新,为 7 进行一次更新。

4

2 回答 2

1

在您对表数据库中的每条记录的查询中,对表t1执行单独的查询。实际上,您只需要扫描此表一次。NETWORKPROFILE

我建议你使用 MERGE 子句:

merge into t1
using (
  select
    network.mid,
    decode(network.nid, 11, 10, 7) language_id,
  from
    profile,
    network
  where
    profile.status in ('A','U','S','H','I')
    and
    network.mid = profile.mid
) update_set 
on
  t1.mid = update_set.mid 
  and
  t1.is_deleted = 'N'
when matched
  then update set t1.language_id = update_set.language_id
;

有关更多信息,请查看Oracle 文档中的说明。

于 2013-03-19T21:34:18.757 回答
0

检查 MID 列的索引和统计信息(我假设选择性很高)。检查执行计划。检查 PQ/PDML。如果您的 MID 在所有方面都是 UNIQUE 列,则可以将其更改为:

UPDATE t1
SET t1.language_id = (SELECT distinct(CASE WHEN NETWORK.nid = 11 
                              THEN 10
                              ELSE 7
                          END)
                   FROM NETWORK
                   where NETWORK.mid = t1.mid
                   )
WHERE EXIST ( SELECT 1 from NETWORK where NETWORK.mid = t1.mid )
AND EXISTS( SELECT 1 FROM PROFILE where PROFILE.STATUS IN ('A','U','S','H','I')
                    AND PROFILE.mid = t1.mid )
AND t1.is_deleted = 'N'
于 2013-03-19T21:03:55.377 回答