Insert in table, Sequence.nextval not working

oracle-sqldeveloper, oracle11g, sql, sql-insert

Solution

Try moving the sequence out of the grouping query:

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
);

Problem

I have the following 3 tables, Data_Excel contains the names, address, city and source of person; Person table has the name and ID; I need to insert into person_location the address source, address, city and ID... I am using the following query : ``` 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; ``` but I get the following error. I am using seq because ID is the primary key in persons but its not auto incrementing. I also tried that but there was an error : ``` 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. ```

Original source