oracle ORA-00936 缺少表达式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13190059/
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
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:13:12 来源:igfitidea点击:
ORA-00936 missing expression
提问by user1793384
The following statement:
以下声明:
INSERT INTO TABLE1(COL_1,COL2) VALUES(SELECT MAX(COL_1) FROM TABLE1), 'XYZ');
throws the error:
抛出错误:
ERROR at line 1:
ORA-00936: missing expression
at the select clause.
1. The table is empty for now.
2. COL_1 is a primary key intger field.
Can you help me please?
你能帮我吗?
回答by J?cob
Try as
尝试作为
create table TABLE1 (COL_1 number, COL2 varchar2(5));
ALTER TABLE TABLE1
add CONSTRAINT t_pk PRIMARY KEY (col_1);
INSERT INTO TABLE1(COL_1,COL2) VALUES((SELECT nvl(MAX(COL_1),0) FROM TABLE1), 'XYZ');
INSERT INTO TABLE1(COL_1,COL2) VALUES((SELECT nvl(MAX(COL_1+1),0) FROM TABLE1), 'XYZ');
回答by Andriy M
If you want to use the result of a query as a scalar expression, enclose the entire (sub)query in brackets, like this:
如果要将查询结果用作标量表达式,请将整个(子)查询括在方括号中,如下所示:
INSERT INTO TABLE1(COL_1,COL2) VALUES (
(SELECT MAX(COL_1) FROM TABLE1),
'XYZ'
);
On the other hand, you could simply use a different syntax, here:
另一方面,您可以在这里简单地使用不同的语法:
INSERT INTO TABLE1(COL_1,COL2)
SELECT MAX(COL_1), 'XYZ'
FROM TABLE1
group by 'XYZ';
回答by Buzz
remove one extra bracket
移除一个额外的支架
INSERT INTO TABLE1(COL_1,COL2) SELECT MAX(COL_1) , 'XYZ' FROM TABLE1