gpt4 book ai didi

sql - 在表中插入,Sequence.nextval 不起作用

转载 作者:行者123 更新时间:2023-12-04 23:52:47 25 4
gpt4 key购买 nike

我有以下 3 个表,

数据_Excel 包含姓名、地址、城市和人员来源;
人表 有姓名和身份证;
我需要插入 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.

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

最佳答案

尝试将序列移出分组查询:

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

关于sql - 在表中插入,Sequence.nextval 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20119055/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com