oracle表存在重复值不插入数据问题
当程序给oracle的表插入一条数据时,判断当前数据表里面有没有存在重复数据,如果没有就插入,如果有就不插入。求思路。求大神们提点。。。
[解决办法]
merge into,insert into ...where not exists...都可以,但考虑到并发性,最好设置唯一键吧
[解决办法]
加unique约束吧,这样有重复就会插入失败。
[解决办法]
会有异常,做下异常处理,类似
...exceptionwhen dup_val_on_index then --印象中重复的异常是这个,若不确定可用others null;--不做任何操作
[解决办法]
查出重复值的SQL,如果有记录说明重复,没有则不重复。
select rowid,username,userpwd from a where a.rowid!=(select max(rowid) from a b where a.username=b.usernameand a.userpwd =b.userpwd );
[解决办法]
5楼正确,null是不执行任何操作。
[解决办法]