我有以下3个表格,
Data_Excel 包含人名,地址,城市和来源;
人员表有姓名和ID;
我需要在 person_location 中插入地址来源,地址,城市和ID ......
我使用以下查询:
CREATE SEQUENCE seq
START WITH 6571
MINVALUE 6571
INCREMENT BY 1
CACHE 100
INSERT INTO Person (id,Name,source)
Select (seq.nextval),p_name,source
FROM Data_Excel
WHERE P_Name NOT IN
(SELECT name FROM Person)
GROUP BY P_Name,P_Address,P_city,Source
HAVING count(*) < 2;
但是我收到以下错误。 我正在使用seq,因为ID是人的主键,但它不是自动递增的。我也试过,但有一个错误:
02287. 00000 - "sequence number not allowed here"
*Cause: The specified sequence umber (CURRVAL or NEXTVAL) is inappropriate
here in the statement.
*Action: emove the sequence number.
答案 0 :(得分:7)
尝试将序列移出分组查询:
INSERT INTO Person (id,Name,source)
SELECT seq.nextval, p_name,source FROM (
Select p_name,source
FROM Data_Excel
WHERE P_Name NOT IN
(SELECT name FROM Person)
GROUP BY P_Name,P_Address,P_city,Source
HAVING count(*) < 2
);