Oracle sql缺少右括号
我试图限制运行查询时显示的行数。 当我在 SQL Developer 中运行下面的代码时,它返回缺少右括号错误。
select * from
(select row_number() over (order by rescode) rnum, a.* from
(
SELECT *
FROM trans z
LEFT JOIN emails a
ON z.email1_hist_id=a.email_id
or z.email2_hist_id=a.email_id
) a
) where rnum between 1 and 50;
我尝试运行内部查询:
SELECT *
FROM trans z
LEFT JOIN emails a
ON z.email1_hist_id=a.email_id
or z.email2_hist_id=a.email_id
并且它工作正常。另一方面,我尝试删除查询的 OR 部分并包含限制行查询,它返回我指定的行数。
我的代码到底有什么问题?
I'm trying to limit the number of rows that would be displayed when I run my query.
When I run the code below in SQL developer, it returns missing right parenthesis error..
select * from
(select row_number() over (order by rescode) rnum, a.* from
(
SELECT *
FROM trans z
LEFT JOIN emails a
ON z.email1_hist_id=a.email_id
or z.email2_hist_id=a.email_id
) a
) where rnum between 1 and 50;
I tried running the inside query:
SELECT *
FROM trans z
LEFT JOIN emails a
ON z.email1_hist_id=a.email_id
or z.email2_hist_id=a.email_id
and it works fine. On the other hand I tried removing the OR portion of my query and included the limit rows query and it returns the number of rows I specified.
What exactly is wrong in my code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这应该可行 - 您不需要两级子查询
另外,请确保
trans
和emails
之间没有重复的列名 - 这将使查询失败,因为* 不能返回重复的名称。
This should work - you don't need two levels of subquery
Also, make sure there are no duplicate column names between
trans
andemails
- this will trip the query because*
from the inner query cannot return duplicate names.我最好的猜测是,它不喜欢您为子选择指定别名,因此它会在“) a )”中的“a”处抛出语法错误。
My best guess is that it doesn't like your giving the sub-selection an alias, so it's throwing the syntax error at the "a" in ") a )".
我不记得 Oracle,但我知道 MySQL 实际上需要子选择才能有别名。我会尝试在外部子选择中添加一个(在 where rnum... 之前)。
I don't recall about Oracle, but I know that MySQL actually requires sub-selections to have an alias. I'd try adding one to your outer sub-select (before the where rnum...).