为什么即使列存在,我仍然会遇到ORA-00904错误?

28 浏览
0 Comments

为什么即使列存在,我仍然会遇到ORA-00904错误?

在执行Hibernate SQL查询时,我遇到了一个错误。

java.sql.SQLException: ORA-00904: "table_name"."column_name":无效的标识符

当我在sqldeveloper中打开表时,该列是存在的。

这个错误只发生在生产环境中,而不是开发环境中。

我应该检查什么?

0
0 Comments

当执行用户对查询涉及的对象没有适当的权限时,Oracle会抛出ORA-00904错误。

To resolve this error, the user needs to be granted the necessary privileges on the objects referenced in the query.

要解决这个错误,用户需要被授权在查询中引用的对象上拥有必要的权限。

If the error occurs when referencing a column in a table, make sure the column name is spelled correctly and exists in the table.

如果在引用表中的列时出现错误,请确保列名拼写正确并且存在于表中。

If the error occurs when referencing a column in a view, make sure the column name is spelled correctly and exists in the underlying tables.

如果在引用视图中的列时出现错误,请确保列名拼写正确并且存在于底层表中。

If the error occurs when referencing a column in a subquery, make sure the column name is spelled correctly and exists in the subquery's table or view.

如果在引用子查询中的列时出现错误,请确保列名拼写正确并且存在于子查询的表或视图中。

If the error occurs when referencing a column in a function or procedure, make sure the column name is spelled correctly and exists in the appropriate table or view.

如果在引用函数或过程中的列时出现错误,请确保列名拼写正确并且存在于适当的表或视图中。

It is also possible that the column name is a reserved word in Oracle. In this case, you can enclose the column name in double quotes to avoid the error.

还有可能是列名在Oracle中是一个保留字。在这种情况下,可以用双引号括起列名以避免错误。

Overall, the ORA-00904 error can occur when the executing user does not have the necessary permissions or when there are issues with the spelling or existence of the referenced column. By granting proper permissions and ensuring the correct spelling and existence of the column, the error can be resolved.

0
0 Comments

这种情况发生在我意外地使用相同的持久化数据库表定义了两个实体时。在其中一个表中,存在所讨论的列,而在另一个表中不存在。当尝试持久化一个对象(属于引用错误底层数据库表的类型)时,就会出现这个错误。

解决方法:

要解决这个问题,我们需要确保在定义实体时,每个实体对应的数据库表都有正确的列定义。如果出现了相同的数据库表被重复定义的情况,我们需要删除或修改其中一个实体的定义,以避免这个错误。

示例代码:

@Entity
@Table(name = "table_name")
public class EntityA {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    private String columnA;
    
    // Other columns and getters/setters
}

@Entity
@Table(name = "table_name")
public class EntityB {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    private String columnB;
    
    // Other columns and getters/setters
}

在上面的示例代码中,我们定义了两个实体类EntityA和EntityB,它们都对应同一个数据库表"table_name"。每个实体类都有自己的列定义,因此不会出现ORA-00904错误。确保实体类与数据库表的定义一致,可以避免这个错误的发生。

0
0 Comments

ORA-00904错误通常是由于大小写敏感的问题引起的。通常,Oracle表和列是不区分大小写的,不能包含标点符号和空格。但是,如果使用双引号创建带引号的标识符,那么该标识符必须始终使用双引号引用,并且大小写必须正确。例如:

create table bad_design("goodLuckSelectingThisColumn  " number);

在我的情况下,这是由于大小写敏感性引起的;所以我将我的列在Oracle中从column_name重命名为COLUMN_NAME,问题得到解决。

0