使用级联连接比较时标识符无效

Posted

技术标签:

【中文标题】使用级联连接比较时标识符无效【英文标题】:Invalid Identifier when using concatenated join comparison 【发布时间】:2013-01-22 16:53:00 【问题描述】:

这是我的查询。 v.location 是一列,其中包含楼层和房间信息,即 FL 2 RM 204。我需要将其与 mv_rooms 表进行比较,该表将房间和楼层分成两个单独的列。

select v.location, v.customer_name, v.street_name
from voip_validate v, mv_rooms r, mv_buildings b
left outer join voip_validate
on v.location = 'FL ' || r.floor || ' RM ' || r.room
where 'FL ' || r.floor || ' RM ' || r.room is null
and b.dps_number = r.dps_number;

当我运行查询时,我得到了错误:

ORA-00904: "R"."ROOM": 无效标识符 00904. 00000 - “%s:无效标识符” *原因: *行动: 行错误:4 列:47

【问题讨论】:

您正在混淆 ANSI 连接语法样式。使用一种风格并坚持下去。 【参考方案1】:

您正在混合使用 oracle 连接语法和 ANSI。

select v.location, v.customer_name, v.street_name
  from voip_validate v
       left outer join mv_rooms r
                    on v.location = 'FL ' || r.floor || ' RM ' || r.room
       left outer join mv_buildings b
               on b.dps_number = r.dps_number
 where r.room is null

你的 where 子句也是完全错误的,因为它永远不能为空。

where 'FL ' || r.floor || ' RM ' || r.room is null

您是否打算返回在“V”中没有匹配行的行?

【讨论】:

我想返回 V 中与 R 中的行不匹配的行。 @GeoffDawdy 好吧,我已经修改了我的示例。我假设 r.room 是一个不可为空的字段。如果没有,请将where r.room 设置为任何不可为空(例如,PK 列之一)列 谢谢。这是我正在使用的代码,在大多数情况下,我相信它会返回我正在寻找的记录。 select v.location, v.customer_name, v.street_name from voip_validate v left outer join mv_rooms r on v.location = 'FL' || r.地板 || 'RM' || r.room left outer join mv_dps_buildings b on b.dps_building_number = r.dps_building_number 其中 r.room 为空,r.floor 为空;【参考方案2】:

你的where子句肯定有问题, 因为您需要测试 floor 字段和 room 字段是否为 NULL,而不是整个字符串。

select v.location, v.customer_name, v.street_name
from voip_validate v, mv_rooms r, mv_buildings b
left outer join voip_validate
on v.location = 'FL ' || r.floor || ' RM ' || r.room
where (r.floor is null or r.room is null)
and b.dps_number = r.dps_number;

楼层和/或房间是整数数据类型可能存在问题。将它们转换为字符串。

【讨论】:

我仍然收到无效的标识符。难道我的 r.floor 和 r.room 列的类型是 VARCHAR2(4 字节)和 VARCHAR2(8 字节),但我的 v.locations 是 VARCHAR2(60 字节)? 我刚刚意识到另一个问题。由于 where 子句查找 floor 或 room 为空的记录,因此您不能进行字符串连接。尝试将 is null 更改为 is not null,然后尝试省略部分 SQL,直到您可以摆脱错误。这应该以问题为中心。 虽然您的解决方案不是选定的答案,但我相信您帮助我找到了一些问题。感谢您的帮助。

以上是关于使用级联连接比较时标识符无效的主要内容,如果未能解决你的问题,请参考以下文章

Oracle 日期比较(无效标识符)

在应用程序购买“无效的产品标识符”错误消息

ORA-00904 使用 CASE 语句更新表时标识符无效

内部连接错误

ORA-00904: "pass": 无效的标识符

过程中 UPDATE oracle 中的变量:标识符无效