Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert in table, Sequence.nextval not working

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. 

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...where ID comes from person table and name that exist against the id should be matched in the data_excel table to get all the details

like image 579
Mouzzam Hussain Avatar asked Mar 22 '23 13:03

Mouzzam Hussain


1 Answers

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
);
like image 66
halfbit Avatar answered Mar 24 '23 03:03

halfbit