Insert and subselect

こ雲淡風輕ζ 提交于 2019-12-13 04:39:42

问题


INSERT INTO S654321.PERSON
(PNR, FIRSTNAME, LASTNAME)
VALUES
SELECT 32, FIRSTNAME, LASTNAME
FROM S654321.CUSTOMER
WHERE CUSTNR = 'C002'

Returns sqlcode -104 and sqlstate 42601. Do you see the error? The select statement itself is correct.


回答1:


The error is that when you insert records you either use a select, or you specify the values. You don't do both. This is ok

insert into table
(field1)
values
(value1)

as is this:

insert into table
(field1)
select distinct value1
from somewhere

So pick a method.




回答2:


you are mixing two statements, this is what you should do

INSERT INTO S654321.PERSON
(PNR, FIRSTNAME, LASTNAME)
SELECT 32, FIRSTNAME, LASTNAME
FROM S654321.CUSTOMER
WHERE CUSTNR = 'C002'


来源:https://stackoverflow.com/questions/23043818/insert-and-subselect

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!