SQL 从子选择向 DB2 插入一行 - NULL 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/873828/
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
Inserting a row into DB2 from a sub-select - NULL error
提问by pkaeding
I am trying to insert a row into a table, using a value that is derived from another table. Here is the SQL statement that I am trying to use:
我正在尝试使用从另一个表派生的值向表中插入一行。这是我尝试使用的 SQL 语句:
INSERT INTO NextKeyValue(KeyName, KeyValue) SELECT 'DisplayWorkItemId' AS KeyName, (MAX(work_item_display_id) + 1) AS KeyValue FROM work_item;
So, I am trying to create a row in NextKeyValue
that has 'KeyName' of 'DisplayWorkItemId' and 'KeyValue' of one more than the maximum value in work_item.work_item_display_id
.
因此,我试图在其中创建一行,NextKeyValue
其中 'DisplayWorkItemId' 的 'KeyName' 和 'KeyValue' 比work_item.work_item_display_id
.
The SELECT statement in the above query returns the expected result, when I run it on its own.
上面查询中的 SELECT 语句返回预期的结果,当我自己运行它时。
The whole SQL query is giving me the following error, though:
不过,整个 SQL 查询给了我以下错误:
Error: DB2 SQL Error: SQLCODE=-407, SQLSTATE=23502, SQLERRMC=TBSPACEID=2, TABLEID=75, COLNO=2, DRIVER=3.50.152 SQLState: 23502 ErrorCode: -407
错误:DB2 SQL 错误:SQLCODE=-407,SQLSTATE=23502,SQLERRMC=TBSPACEID=2,TABLEID=75,COLNO=2,DRIVER=3.50.152 SQLState:23502 错误代码:-407
What does this mean, and what is wrong with my query?
这是什么意思,我的查询有什么问题?
回答by Roee Adler
The most probable explanation is that you have additional columns in NextKeyValue table that can't accept NULL values, and this INSERT statement is "trying" to put NULL in them.
最可能的解释是您在 NextKeyValue 表中有其他列不能接受 NULL 值,而这个 INSERT 语句正在“尝试”将 NULL 放入其中。
Is that the case by any chance?
有没有可能是这种情况?