SQL 在表中插入,Sequence.nextval 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20119055/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Insert in table, Sequence.nextval not working
提问by Mouzzam Hussain
I have the following 3 tables,
我有以下 3 个表,
Data_Excelcontains the names, address, city and source of person;
Person tablehas the name and ID;
I need to insert into person_locationthe address source, address, city and ID...
Data_Excel包含姓名、地址、城市和人员来源;
Person表有名字和ID;
我需要在person_location 中插入地址来源、地址、城市和 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 :
但我收到以下错误。我使用 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.
回答by halfbit
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
);