SQL:ORA-00933选择中出现错误
我试图从3个表中执行一个有点复杂的选择,所有表都由一个b_id连接:SQL:ORA-00933选择中出现错误,sql,oracle,Sql,Oracle,我试图从3个表中执行一个有点复杂的选择,所有表都由一个b_id连接: select max(bs.b_id), h.b_type_id, t.name_id from b_state as bs, t_info as t, history as h where bs.b_id = t.b_id and bs.b_id = h.b_id and t.name_id in (???) and bs.is
select max(bs.b_id),
h.b_type_id,
t.name_id
from b_state as bs,
t_info as t,
history as h
where bs.b_id = t.b_id
and bs.b_id = h.b_id
and t.name_id in (???)
and bs.is_detached = ?
group by h.b_type_id,
t.name_id
在MySQL中,它给出了我想要的东西,但在PSQL和Oracle中似乎失败了,再加上在Oracle中执行的结果是:“ORA-00933:SQL命令没有正确结束”
(这通常发生在谷歌建议的插入查询中)
我想有一种与DB无关的方法可以做到这一点。请提供建议。尝试:
select max(bs.b_id), h.b_type_id, t.name_id
from b_state bs
inner join t_info t on bs.b_id = t.b_id
inner join history h on bs.b_id = h.b_id
where t.name_id in (???) and bs.is_detached = ?
group by h.b_type_id, t.name_id
试试这个:
select max(bs.b_id),
h.b_type_id,
t.name_id
from b_state bs,
t_info t,
history h
where bs.b_id = t.b_id
and bs.b_id = h.b_id
and t.name_id in (???)
and bs.is_detached = ?
group by h.b_type_id,
t.name_id
表的“as”别名在Oracle中造成了问题
编辑:我使用了SQL-86语法,因为这是您最初发布的语法,但您实际上应该默认使用SQL-92语法。Oracle使用
:varname
绑定变量,而不是?
所以试试类似的方法
select
max(bs.b_id),
h.b_type_id,
t.name_id
from
b_state as bs,
t_info as t,
history as h
where
bs.b_id = t.b_id and
bs.b_id = h.b_id and
t.name_id in (:1, :2, :3) and
bs.is_detached = :4
group by
h.b_type_id,
t.name_id
我建议在子句中为max和(如有必要)逗号指定一个别名,用于分隔
中的参数,如下所示:
select max(bs.b_id) max_b_id,
h.b_type_id,
t.name_id
from b_state as bs,
t_info as t,
history as h
where bs.b_id = t.b_id
and bs.b_id = h.b_id
and t.name_id in (?,?,?)
and bs.is_detached = ?
group by h.b_type_id,
t.name_id
谢谢你的建议。不幸的是,检查所有数据库中的测试需要几个小时,但我肯定会这样做。这就是问题所在。为了更好的可读性,我使用了iner JOIN
。您是如何在Oracle中执行此查询的?例如,通过JDBC、ODBC、SQLPlus。。。?