由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - Oracle insert primary key violation
相关主题
SQL Developer ORA-01017 错误复制ORA-02062错误
【已解决】oracle db linknewbie's question about oracle
如何把某些行的某个列(unique)的值加1?a simple question about T-SQL
Need help on a strange SQL server problemProblem when using SQL " Insert...." to AutoNumber.
[转载] 真的没有人懂 ORACLE pro*c阿? :((((SORTING 中文 IN ORACLE
How to handle inserting value to Identity column in sql server 2005found a way to corrupt oracle on NT
[转载] help database question Error Code 01034?
how to improve the performance of Oracle Insert operation?Oracle error code 12638?
相关话题的讨论汇总
话题: insert话题: oracle话题: sql话题: violation话题: primary
进入Database版参与讨论
1 (共1页)
s****y
发帖数: 66
1
最近開始用Oracle寫一些很基本的query。類似query之前在MS SQL Server和MySql上實
現都沒問題。換到Oracle最頭疼的一個問題就是居然沒有if exists也沒有insert
ignore之類的。一個簡單的insert都沒有辦法避免primary key violation。網上搜了
一下,都說是要在application code這邊catch exception。可是如果我做的是batch
insert,其中任何一個insert造成primary key violation都會讓整個batch失敗。
這麼簡單的一個事居然沒有一個簡單的辦法解決。覺得不可思議啊!
這裡的Oracle高手指點一下怎麼做insert不用擔心primary key violation吧。
y****9
发帖数: 144
2
不太熟悉MS SQL 和 MySQL, 能不能给几个 test cases to show how they complete
the same tasks?
In Oracle if we do individual insert statements, seems it won't cause the
whole batch fail.
SQL> ho cat temp.sql
insert into t values(1);
insert into t values(1);
insert into t values(2);
commit;
SQL> @temp
1 row created.
insert into t values(1)
*
ERROR at line 1:
ORA-00001: unique constraint (Vxxxx.T_PK) violated
1 row created.
Commit complete.
SQL> select * from t;
ID
----------
1
2
"if exist" is not a SQL, Oracle PL/SQL has that also
"insert ignore" seems not standard SQL either

【在 s****y 的大作中提到】
: 最近開始用Oracle寫一些很基本的query。類似query之前在MS SQL Server和MySql上實
: 現都沒問題。換到Oracle最頭疼的一個問題就是居然沒有if exists也沒有insert
: ignore之類的。一個簡單的insert都沒有辦法避免primary key violation。網上搜了
: 一下,都說是要在application code這邊catch exception。可是如果我做的是batch
: insert,其中任何一個insert造成primary key violation都會讓整個batch失敗。
: 這麼簡單的一個事居然沒有一個簡單的辦法解決。覺得不可思議啊!
: 這裡的Oracle高手指點一下怎麼做insert不用擔心primary key violation吧。

B*****g
发帖数: 34098
3
http://www.oracle-base.com/articles/10g/dml-error-logging-10gr2
http://asktom.oracle.com/pls/asktom/f?p=100:11:0%3a%3a%3a%3aP11

【在 s****y 的大作中提到】
: 最近開始用Oracle寫一些很基本的query。類似query之前在MS SQL Server和MySql上實
: 現都沒問題。換到Oracle最頭疼的一個問題就是居然沒有if exists也沒有insert
: ignore之類的。一個簡單的insert都沒有辦法避免primary key violation。網上搜了
: 一下,都說是要在application code這邊catch exception。可是如果我做的是batch
: insert,其中任何一個insert造成primary key violation都會讓整個batch失敗。
: 這麼簡單的一個事居然沒有一個簡單的辦法解決。覺得不可思議啊!
: 這裡的Oracle高手指點一下怎麼做insert不用擔心primary key violation吧。

g********s
发帖数: 3652
4
既然是PK,上面有constraint 保证这个列的值不可重复所以你无法输入重复值的
tj
发帖数: 957
5
merge ?

【在 s****y 的大作中提到】
: 最近開始用Oracle寫一些很基本的query。類似query之前在MS SQL Server和MySql上實
: 現都沒問題。換到Oracle最頭疼的一個問題就是居然沒有if exists也沒有insert
: ignore之類的。一個簡單的insert都沒有辦法避免primary key violation。網上搜了
: 一下,都說是要在application code這邊catch exception。可是如果我做的是batch
: insert,其中任何一個insert造成primary key violation都會讓整個batch失敗。
: 這麼簡單的一個事居然沒有一個簡單的辦法解決。覺得不可思議啊!
: 這裡的Oracle高手指點一下怎麼做insert不用擔心primary key violation吧。

t*********i
发帖数: 217
6
北京mm说的这个管用的呀。
如果是insert select, 也可以加一个where clause.
insert into t1
select * from t2
where not exist (select * from t1 where t1.column =t2.column...);
1 (共1页)
进入Database版参与讨论
相关主题
Oracle error code 12638?[转载] 真的没有人懂 ORACLE pro*c阿? :((((
connect to an oracle server on anoter machineHow to handle inserting value to Identity column in sql server 2005
2 problems about Oracle[转载] help database question
Help on Oracle!!how to improve the performance of Oracle Insert operation?
SQL Developer ORA-01017 错误复制ORA-02062错误
【已解决】oracle db linknewbie's question about oracle
如何把某些行的某个列(unique)的值加1?a simple question about T-SQL
Need help on a strange SQL server problemProblem when using SQL " Insert...." to AutoNumber.
相关话题的讨论汇总
话题: insert话题: oracle话题: sql话题: violation话题: primary