java.sql.SQLException: ORA-00904

戏子无情 提交于 2019-12-31 04:30:10

问题


I am getting this below exception-

java.sql.SQLException: ORA-00904: : invalid identifier
ORA-06512: at line 1

Below is the query that I am trying to execute-

public static final String DATABASE_TABLE = "LnPData";

public static final String CREATE_SQL = "DECLARE " +
"t_count INTEGER; " +
"v_sql VARCHAR2(1000) := 'create table " +DATABASE_TABLE + "(" +
"(ID number(10,0), " +
"CGUID VARCHAR(255), " + 
"PGUID VARCHAR(255), " + 
"SGUID VARCHAR(255), " + 
"USERID VARCHAR(255), " +
"ULOC VARCHAR(255), " +
"SLOC VARCHAR(255), " +
"PLOC VARCHAR(255), " +
"ALOC VARCHAR(255), " +
"SITEID VARCHAR(255), " +
"PRIMARY KEY ( ID ))'; " +
"BEGIN " +
"SELECT COUNT(*) " +
"INTO t_count " +
"FROM user_tables " +
"WHERE table_name = '" +DATABASE_TABLE + "'; " +

"IF t_count = 0 THEN " +
"EXECUTE IMMEDIATE v_sql; " +
"END IF; " +
"END; ";

On the console it is getting printed as-

DECLARE t_count INTEGER; v_sql VARCHAR2(1000) := 'create table LnPData((ID number(10,0), CGUID VARCHAR(255), PGUID VARCHAR(255), SGUID VARCHAR(255), USERID VARCHAR(255), ULOC VARCHAR(255), SLOC VARCHAR(255), PLOC VARCHAR(255), ALOC VARCHAR(255), SITEID VARCHAR(255), PRIMARY KEY ( ID ))'; BEGIN SELECT COUNT(*) INTO t_count FROM user_tables WHERE table_name = 'LnPData'; IF t_count = 0 THEN EXECUTE IMMEDIATE v_sql; END IF; END; 

回答1:


Change

"v_sql VARCHAR2(1000) := 'create table " +DATABASE_TABLE + "(" +
"(ID number(10,0), " +

into

"v_sql VARCHAR2(1000) := 'create table " +DATABASE_TABLE +
"(ID number(10,0), " +

and it is working. You just had one incorrect bracket.



来源:https://stackoverflow.com/questions/10771189/java-sql-sqlexception-ora-00904

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!