3

I'm writing a SQL (Oracle) to update a table with the values in another table. But since there is a 2 column unique constraint, the update always failed. It is something like this:

Table A
- A_1
- A_2
- A_3
(There is a unique constraint for A_1 + A_3 )

Table B
- B_1
- B_2

Here is my current sql:

UPDATE A a
SET a.A_1 =
    (SELECT b.B_1
    FROM B b
    WHERE a.A_2 = b.B_2
    )
AND EXISTS
    (SELECT b.B_1
    FROM B b
    WHERE a.a.A_2 = b.B_2
    )

I want to skip the lines that violate the unique constraint but I don't know how to do it. Please advise. Thank you!

4

1 に答える 1

0

AND NOT EXISTS制約された値を新しい値に対してチェックして、最後に を配置できます (更新後のように)。

...
AND NOT EXISTS
(
    SELECT 1
    FROM A checkA
    WHERE checkA.A_1 = (SELECT b.B_1 FROM B b WHERE a.A_2 = b.B_2)
    AND checkA.A_3 = a.A_3
)
于 2013-01-23T18:31:30.010 に答える