我有以下 SQL 模式:
Create table Employee (Id int, Salary int);
Truncate table Employee;
insert into Employee (Id, Salary) values ('1', '100');
insert into Employee (Id, Salary) values ('2', '200');
insert into Employee (Id, Salary) values ('3', '300');
并对数据库执行以下查询:
SELECT Salary as SecondHighestSalary
FROM Employee
ORDER BY Salary
OFFSET 1 ROWS FETCH FIRST 1 ROWS ONLY;
它适用于 Oracle XE 18
,但在 leetcode.com 上(我不知道他们运行的是哪个版本的 Oracle)它返回以下错误:
ORA-00933: SQL command not properly ended
我做错了什么?
最佳答案
错误消息表明您使用的版本低于 Oracle 12c(很可能是 Oracle 11g XE)。
OFFSET FETCH
是在版本 12c 中引入的。您可以通过执行以下操作轻松检查它:
select * from V$VERSION;
SELECT Salary as SecondHighestSalary
FROM Employee
ORDER BY Salary
OFFSET 1 ROWS FETCH FIRST 1 ROWS ONLY;
-- ORA-00933: SQL command not properly ended
关于sql - SELECT 语句返回 ORA-00933 : SQL command not properly ended,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56303227/