以下声明:
INSERT INTO TABLE1(COL_1,COL2) VALUES(SELECT MAX(COL_1) FROM TABLE1), 'XYZ');
抛出错误:
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.
你能帮我吗?
以下声明:
INSERT INTO TABLE1(COL_1,COL2) VALUES(SELECT MAX(COL_1) FROM TABLE1), 'XYZ');
抛出错误:
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.
你能帮我吗?
试试看
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');
如果要将查询的结果用作标量表达式,请将整个(子)查询括在括号中,如下所示:
INSERT INTO TABLE1(COL_1,COL2) VALUES (
(SELECT MAX(COL_1) FROM TABLE1),
'XYZ'
);
另一方面,您可以在这里简单地使用不同的语法:
INSERT INTO TABLE1(COL_1,COL2)
SELECT MAX(COL_1), 'XYZ'
FROM TABLE1
group by 'XYZ';
移除一个额外的支架
INSERT INTO TABLE1(COL_1,COL2) SELECT MAX(COL_1) , 'XYZ' FROM TABLE1