当程序给oracle的表插入一条数据时,判断当前数据表里面有没有存在重复数据,如果没有就插入,如果有就不插入。求思路。求大神们提点 

解决方案 »

  1.   

     
        MERGE INTO tableA A
        USING (筛选结果集) B
        ON (A.XX=B.XX)
        /*WHEN MATCHED THEN
          UPDATE
             SET LOW.KFRST     = LOW1.KFRST  */          
        WHEN NOT MATCHED THEN
          INSERT
            (FIELD1,..)
          VALUES
            (1,...);
      你可以搜搜merge into 的yongf
      

  2.   

    merge into,insert into ...where not exists...都可以,但考虑到并发性,最好设置唯一键吧
      

  3.   

    加unique约束吧,这样有重复就会插入失败。
      

  4.   

    会有异常,做下异常处理,类似...
    exception
    when dup_val_on_index then --印象中重复的异常是这个,若不确定可用others
        null;--不做任何操作
      

  5.   

    这个null是放弃本次插入还是插入null值进去
      

  6.   

    这样吧  写个简单例子吧  
    表 user 有两个字段  username    userpwdzhangsan              123
    lisi                  123username字段是唯一值不能重复  如果重复放弃本次插入  这个插入操作是在C#程序写的 一报错程序端就停住了  现在问题是不能让它停  只能continue;
      

  7.   

    查出重复值的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 );
      

  8.   

    5楼正确,null是不执行任何操作。
      

  9.   


    直接用MERGE INTO 不就行了
      

  10.   

    merge into test a
    using
    (
      select '1' as name, '女' as sex from dual
    ) b
    on (a.name=b.name and a.sex = b.sex)
    when not matched then
       INSERT VALUES (1,'2','女');