먼저 오라클보다 SQL 사람이 더 많아서 문법/쿼리 엔진에 대한 기본적인 사실을 놓친 것처럼 보입니다.오라클 - 한 번에 여러 개의 열을 업데이트 (변형)
오라클에서 여러 컬럼을 업데이트하려고 시도하고 있으며 아래 코드에서 몇 가지 시나리오를 거쳐야합니다.
내 문제는 좀 더 복잡한 코드가 더 복잡한 코드를 업데이트하는 것이 아니라는 것입니다. 저는 수십만 건 이상의 업데이트를보고 있기 때문에 최소한의 처리 능력으로이 작업을 수행하려고합니다.
그래서 첫 번째 코드 : '내가 이것을 실행하면 이제
UPDATE [email protected] i2
SET (i2.access, i2.permission) =
(select
i2m.access, i2m.permission
from temporarytable ss
JOIN table2 pgm
ON ss.secgroup = pgm.string
JOIN table i2m
ON pgm.hmy = i2m.hgroup
AND ss.pername = i2m.sobjname
JOIN [email protected] pg
ON ss.secgroup = pg.string
WHERE
pg.string = 'string' -- this limits the updates to a specific subset of data
and i2m.hmy > 0 -- this for some freak records in both tables that are missing a primary key
and pg.hmy = i2.hgroup -- this matches the key of the 'string' from above to the records i need to update
and ss.pername = i2.sobjname -- further condition on which records to update. so only the ones that match from the temp table to the target table
and ss.orig_hmy = i2.hmy) -- further condition to make sure i am updating only records matching between temp table and target table
는 대신 위의 하위 쿼리와 일치 약 700 레코드를 업데이트하는 그것은'테이블 @의 database1 '테이블에서 모든 레코드를 업데이트하고 내가 할 수있는 왜 (아마도 나는 오라클에 대해 얻지 못하는 것들 중 하나 일 것입니다.)
그러나 아래를 실행하면 - 유일한 차이점은 'where exists'에 전체 하위 쿼리를 삽입한다는 것입니다. 이건 내가 필요한 것을 업데이트 만합니다. 내 문제는 그것을 이해하는 방식으로, 하위 쿼리는 두 번 실행됩니다. 한 번은 업데이트에서, 한 번은 where 절에서 처리하는 것은 낭비입니다.
UPDATE [email protected] i2
SET (i2.access, i2.permission) =
(select
i2m.access, i2m.permission
from temporarytable ss
JOIN table2 pgm
ON ss.secgroup = pgm.string
JOIN table i2m
ON pgm.hmy = i2m.hgroup
AND ss.pername = i2m.sobjname
JOIN [email protected] pg
ON ss.secgroup = pg.string
WHERE
pg.string = 'string'
and i2m.hmy > 0
and pg.hmy = i2.hgroup
and ss.pername = i2.sobjname
and ss.orig_hmy = i2.hmy)
where exists (select
i2m.access, i2m.permission
from temporarytable ss
JOIN table2 pgm
ON ss.secgroup = pgm.string
JOIN table i2m
ON pgm.hmy = i2m.hgroup
AND ss.pername = i2m.sobjname
JOIN [email protected] pg
ON ss.secgroup = pg.string
WHERE
pg.string = 'string'
and i2m.hmy > 0
and pg.hmy = i2.hgroup
and ss.pername = i2.sobjname
and ss.orig_hmy = i2.hmy)
모든 제안 사항을 환영합니다. 고맙습니다!
참고 : 표시되지 않는 경우 동일한 스키마를 가진 여러 DB가 있습니다. 마스터 스키마의 정보로 DB간에 테이블을 업데이트하려고합니다. Temp 테이블은 다르고 업데이트해야하는 레코드의 저장소 역할을합니다. 마스터 스키마와 15 % 만 다른 경우 수백만 개의 레코드를 업데이트 할 필요가 없습니다.
테이블을 업데이트하는이 방법이 마음에 들지 않으면 'merge'를 사용할 수 있습니다. –
Gordon에 동의합니다. MERGE 접근법을 읽고 숙지하시기 바랍니다. 그것은 미래에 큰 배당금을 지불 할 것입니다. – mathguy
"테이블 'table @ database1'에서 모든 레코드를 업데이트하고 이유를 볼 수 없습니다." 왜냐하면'update' 문에'where' 절이 없기 때문입니다. 오라클은 그 점에 대해 구체적으로 설명하지 않습니다. 모든 플랫폼에서 모든 행을 업데이트하지 않는 업데이트에 익숙합니다. –