Oracle:从 SELECT...JOIN 中插入值,SQL 错误:ORA-00947:没有足够的值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11414177/
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
Oracle: INSERT values from SELECT...JOIN, SQL Error: ORA-00947: not enough values
提问by mszaro
I'm trying to do the following:
我正在尝试执行以下操作:
INSERT INTO MyTable(a, b, c)
SELECT a FROM source1
JOIN source2 ON ...
Where source2 contains columns B and C.
其中 source2 包含列 B 和 C。
However Oracle doesn't seem to like this and is telling me "SQL Error: ORA-00947: not enough values".
然而,Oracle 似乎并不喜欢这个,并告诉我“SQL 错误:ORA-00947:没有足够的值”。
Am I doing something wrong here? Is this syntax even possible? Or do I have to rewrite it as:
我在这里做错了吗?这种语法甚至可能吗?还是我必须将其重写为:
SELECT a, b, c FROM source1, source2 WHERE ....
Thanks!
谢谢!
回答by Vincent Malgrat
Use as many identifiers in the SELECT clause as in the INSERT clause, as in:
在 SELECT 子句中使用与 INSERT 子句中一样多的标识符,如下所示:
INSERT INTO MyTable(a, b, c)
SELECT s1.a, s2.b, s2.c FROM source1 s1
JOIN source2 s2 ON ...
回答by a_horse_with_no_name
The select needs to return the same number of columns as you listed in the INSERT
statement.
select 需要返回与您在INSERT
语句中列出的列数相同的列数。
So: yes, you need to rewrite the query to SELECT a,b,c FROM ...
所以:是的,您需要将查询重写为 SELECT a,b,c FROM ...