【发布时间】:2017-06-28 05:34:49
【问题描述】:
我有一个 table1(key is X, XX) 如下所示:
x,y,xx,yy,xxx,yyy
我创建了一个新的table2(关键是代码)如下:
code,name,xx,yy,xxx,yyy
现在我想将table1中的所有数据复制到table2,如果遇到相同的代码跳过它,
x -> code
Y -> name
xx-> xx
yy -> yy
xxx -> xxx
yyy -> yyy
我使用下面的代码复制所有数据,我收到错误00001. 00000 - "unique constraint (%s.%s) violated",因为table1中有重复的x,但我不知道如何跳过重复的X数据,你能帮帮我吗?
INSERT INTO table2 (code, name, xx, yy, xxx, yyy)
SELECT x, y, xx, yy, xxx, yyy FROM table1
我试过了,我觉得不正确。
INSERT INTO table2 (code, name, xx, yy, xxx, yyy)
SELECT DISTINCT x, y, xx, yy, xxx, yyy FROM table1
【问题讨论】:
-
那个答案有同样的错误
Error report - SQL Error: ORA-00001: unique constraint (table2_index) violated 00001. 00000 - "unique constraint (%s.%s) violated" *Cause: An UPDATE or INSERT statement attempted to insert a duplicate key. For Trusted Oracle configured in DBMS MAC mode, you may see this message if a duplicate entry exists at a different level. *Action: Either remove the unique restriction or do not insert the key. -
那么您需要查看 ON 标准,因为您的标准不够严格,无法满足 UNMATCHED 过滤器的要求。
-
我通过
INSERT /*+ ignore_row_on_dupkey_index(table2, table2_index) */ INTO table2 (code, name, xx, yy, xxx, yyy) SELECT x, y, xx, yy, xxx, yyy FROM table1得到了我需要的东西
标签: oracle subquery sql-insert sqlbulkcopy