Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将不重复的行插入到sql中分区为的表中_Sql_Oracle - Fatal编程技术网

将不重复的行插入到sql中分区为的表中

将不重复的行插入到sql中分区为的表中,sql,oracle,Sql,Oracle,有两个表x\u ass\u table和i\u ass\u table: 我正在将包含1128条记录的数据从x\u ass\u表插入I\u ass\u表。为避免唯一约束错误,我使用以下查询: insert assignment_number, effective_start_date, effective_end_date, effective_latest_change, configu

有两个表
x\u ass\u table
i\u ass\u table

我正在将包含1128条记录的数据从
x\u ass\u表插入
I\u ass\u表
。为避免唯一约束错误,我使用以下查询:

     insert assignment_number, 
            effective_start_date,
            effective_end_date,
            effective_latest_change,
            configuration_no 
     into i_ass_table
          select effective_start_date,
                 effective_end_date,
                 effective_latest_change,
                 'XX_FUS' 
      FROM     (SELECT x_ass_table.*,
                       COUNT() OVER (PARTITION BY assignment_number, 
                                                  effective_start_date,
                                                  effective_end_date,
                                                  effective_latest_change) AS c
                FROM   x_ass_table) t
    where c=1;

我仍然得到了唯一的约束错误。虽然我限制了
分配编号、生效开始日期、生效结束日期、生效最新变更
列,这些列都是唯一的键列

我认为您正在检查
x\u ass\u表中存在的重复记录,但您还应该检查
I\u ass\u表和
x\u ass\u表中是否存在相同的记录。这也会创建唯一的约束错误

    select *  
      from x_ass_table x,  
           i_ass_table i  
    where i.assignment_number = x.assignment_number  
      and i.effective_start_date = x.effective_start_date  
      and i.effective_end_date = x.effective_end_date  
      and i.effective_latest_change = x.effective_latest_change;

您确定列匹配吗?除了
x\u ass\u表中的列(您的计数)之外,您正在选择一个附加列。这当然会给出不同的错误信息,所以不是解决上述问题的方法。我已经编辑了我的查询@HoneyBadger,直到列不匹配为止,我猜你忘了
分配号
如果这些都是你需要的列,你就不能使用
distinct
?@HoneyBadger大约有20列。。。我缩短了查询,以便更好地理解I_ASS_表为空。。但我解决了这个问题。这是因为数据有出入。由于数据计数太多,需要安静一段时间