插入具有不同的序列

时间:2015-11-19 04:00:23

标签: sql oracle oracle11g

我知道不可能插入带有SELECT DISTINCT的序列,你必须以某种方式将不同的FROM嵌套在我看不到的地方。这是插入语句

INSERT INTO rental (rental_id, customer_id, check_out_date, return_date, created_by, creation_date, last_updated_by, last_update_date)
SELECT DISTINCT  rental_s1.nextval, c.contact_id, tu.check_out_date, tu.return_date, m.created_by, m.creation_date, m.last_updated_by, m.last_update_date
FROM     member m INNER JOIN contact c
ON       m.member_id = c.member_id INNER JOIN transaction_upload tu
ON       c.first_name = tu.first_name
AND      NVL(c.middle_name,'x') = NVL(tu.middle_name,'x')
AND      c.last_name = tu.last_name  
AND      m.account_number = tu.account_number LEFT JOIN rental r
ON       tu.check_out_date = r.check_out_date;

从右到右不是它给了我一个ORA-02287:Sequence number not allowed here我怎么能改变它以允许所有其他值不同并且仍然能够添加序列。

1 个答案:

答案 0 :(得分:2)

这可以解决您的问题:

INSERT INTO rental (rental_id, customer_id, check_out_date, 
                    return_date, created_by, creation_date, 
                    last_updated_by, last_update_date)
SELECT rental_s1.nextval, contact_id, check_out_date, return_date,
       created_by, creation_date, last_updated_by, last_update_date
  FROM ( SELECT DISTINCT c.contact_id, tu.check_out_date, 
                         tu.return_date, m.created_by, 
                         m.creation_date, m.last_updated_by, 
                         m.last_update_date
           FROM member m 
                 INNER JOIN contact c ON m.member_id = c.member_id 
                 INNER JOIN transaction_upload tu ON c.first_name = tu.first_name
                        AND NVL(c.middle_name,'x') = NVL(tu.middle_name,'x')
                        AND c.last_name = tu.last_name  
                        AND m.account_number = tu.account_number 
                  LEFT JOIN rental r ON tu.check_out_date = r.check_out_date
       ) tab