update PROD_IMPORT_FEELIST a set cust_ID = (select Cust_ID
                                     from Prod_Cust_info       where a.USERNAME = b.CUST_NAME)
WHERE a.import_operid = t_head_operid and cust_id is null这样可以更新PROD_IMPORT_FEELIST表中的数据,但是如果Prod_Cust_info里的USERNAME如果有相同的话,那么肯定不是唯一的CUST_ID 系统报错:单行子查询返回多于一个行,这时候应该怎么写这个orcal,如果发现cust_id 大于1条数据时候,那我则不更新PROD_IMPORT_FEELIST的CUST_ID,让他为空

解决方案 »

  1.   

    update PROD_IMPORT_FEELIST a set cust_ID = (select Cust_ID
    from Prod_Cust_info where a.USERNAME = b.CUST_NAME 
    --
    and (select count(Cust_ID) from Prod_Cust_info where a.USERNAME = b.CUST_NAME))=1--
    WHERE a.import_operid = t_head_operid and cust_id is null
      

  2.   

    在where条件中限制一下就行了UPDATE prod_import_feelist a
    SET cust_id = (SELECT cust_id
                   FROM prod_cust_info
                   WHERE a.username = b.cust_name)
    WHERE a.import_operid = t_head_operid
    AND cust_id IS NULL
    AND a.username IN (SELECT cust_name
                      FROM prod_cust_info
                      GROUP BY cust_name
                      HAVING COUNT(*) = 1)
      

  3.   

    update PROD_IMPORT_FEELIST a set cust_ID = (select max(Cust_ID)
                                         from Prod_Cust_info       where a.USERNAME = b.CUST_NAME)
    WHERE a.import_operid = t_head_operid and cust_id is null