【问题标题】:SQL invalid identifierSQL 无效标识符
【发布时间】:2012-12-30 14:15:22
【问题描述】:

任何人都可以帮助我进行查询,该查询从我的家表中选择一个家,并从另一个表中获取一个列表值列表到单个列中。该查询来自我在此处发布的另一个问题的帮助,但是我现在正尝试根据需要添加到查询中。当我尝试在另一个表中添加一个列时,Oracle 会抛出一个无效标识符错误,下面是我的查询;

SELECT homes.title, homes.description, homes.living_room_count, homes.bedroom_count, homes.bathroom_count, homes.price, homes.sqft,
listagg(features.feature_name, ',') WITHIN GROUP (ORDER BY features.feature_name)  features, home_type.type_name, home_photo.photo, home_photo.description
FROM homes, home_type, home_photo
INNER JOIN home_feature
    ON homes.home_id = home_feature.home_id
INNER JOIN features
    ON home_feature.feature_id = features.feature_id
INNER JOIN home_photo
    ON home_photo.home_id = homes.home_id
WHERE home_type.type_code = homes.type_code AND homes.homes_id = home_photo.home_id
GROUP BY homes.title, homes.description, homes.living_room_count, homes.bedroom_count, homes.bathroom_count, homes.price, homes.sqft, home_type.type_name;

上面的查询抛出了这个,但是列确实是正确的:

ORA-00904: "HOMES"."HOME_ID": invalid identifier
00904. 00000 -  "%s: invalid identifier"
*Cause:    
*Action:
Error at Line: 5 Column: 4

从我的其他问题中删除原始查询的列会导致查询工作吗?以下是添加来自不同表的其他列之前的工作查询:

SELECT homes.title, homes.description, homes.living_room_count, homes.bedroom_count, homes.bathroom_count, homes.price, homes.sqft,
listagg(features.feature_name, ',') WITHIN GROUP (ORDER BY features.feature_name)  features
FROM homes
INNER JOIN home_feature
    ON homes.home_id = home_feature.home_id
INNER JOIN features
    ON home_feature.feature_id = features.feature_id
GROUP BY homes.title, homes.description, homes.living_room_count, homes.bedroom_count, homes.bathroom_count, homes.price, homes.sqft;

如果有人可以提供帮助,谢谢。

【问题讨论】:

  • 您不能将 Oracle 样式连接与 ansi 92 样式连接混合使用。

标签: sql oracle join oracle11g inner-join


【解决方案1】:
SELECT homes.title, homes.description, homes.living_room_count, homes.bedroom_count, homes.bathroom_count, homes.price, homes.sqft,
listagg(features.feature_name, ',') WITHIN GROUP (ORDER BY features.feature_name)  features, home_type.type_name, home_photo.photo, home_photo.description
FROM homes
INNER JOIN home_feature
    ON homes.home_id = home_feature.home_id
INNER JOIN home_type
    ON home_type.type_code = homes.type_code
INNER JOIN home_photo
    ON homes.homes_id = home_photo.home_id
INNER JOIN features
    ON home_feature.feature_id = features.feature_id
INNER JOIN home_photo
    ON home_photo.home_id = homes.home_id
GROUP BY homes.title, homes.description, homes.living_room_count, homes.bedroom_count, homes.bathroom_count, homes.price, homes.sqft, home_type.type_name;

会起作用。即不要混淆 ANSI + oracle join 语法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多