我在java中的查询中使用Alias时出现错误。
19:34:26.852 java.sql.SQLSyntaxErrorException: ORA-00923: FROM keyword not found where expected
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:450)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:884)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1167)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1289)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3584)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3628)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1493)
at com.tlc.common.DbWrapper.QueryDataRows(DbWrapper.java:327)
at com.tlc.sky.admin.modules.reports.m.WalletToDistributorReportCollection.hasRows(WalletToDistributorReportCollection.java:73)
at com.tlc.sky.admin.modules.reports.c.WalletToDistributorReportCommand.execute(WalletToDistributorReportCommand.java:46)
at com.tlc.sky.admin.modules.reports.main.test.main(test.java:19)
~U0VMRUNUIERFQ1JZUFQoQS5BTElBUywnc3VuZXY4Y2x0MTIzNDU2Nzg5MCcsQS5NU0lTRE4pIEFTIERJU1RSSUJVVE9SLCBCLlRJTUVTVEFNUCBBUyAnVFJBTlNBQ1RJT04gREFURScsICBCLlJFRkVSRU5DRUlEIEFTICdSRUZFUkVOQ0UgSUQnLCBBLkZJUlNUTkFNRSBBUyAnRklSU1QgTkFNRScsIEEuTEFTVE5BTUUgQVMgJ0xBU1QgTkFNRScsIEEuTVNJU0ROLCBCLkFNT1VOVCwgQi5ERVNUQkFMQU5DRUJFRk9SRSBBUyAnUFJFVklPVVMgQkFMQU5DRScsIEIuREVTVEJBTEFOQ0VBRlRFUiBBUyAnQ1VSUkVOVCBCQUxBTkNFJywgQi5PUklHQkFMQU5DRUFGVEVSIEFTIFdBTExFVCwgQi5SRU1BUktTIEZST00gREJTS1lNQy5UQkxUUkFOU0FDVElPTlMgQiBJTk5FUiBKT0lOIERCU0tZTUMuVEJMTU9CSUxFQUNDT1VOVElORk8gQSBPTiBBLk1TSVNETiA9IEIuVE9NU0lTRE4gV0hFUkUgQi5UWVBFID0gJ0FMTE9DJyBBTkQgQS5SRUZFUkVOQ0VBQ0NPVU5UID0gJzAnIEFORCAoQi5USU1FU1RBTVAgQkVUV0VFTiBUT19EQVRFKD8sJ1lZWVknKSBBTkQgVE9fREFURSg/LCdZWVlZJykpIE9SREVSIEJZIFRJTUVTVEFNUCBBU0M=
我的查询
String sql = "SELECT COLUMN1 AS 'ALIAS1', COLUMN2 AS 'ALIAS2' FROM TABLE1 WHERE CONDITION1 = CONDITION";
or
String sql = "SELECT COLUMN1 AS " + "ALIAS1" + ", COLUMN2 AS " + "ALIAS2" + " FROM TABLE1 WHERE CONDITION1 = CONDITION";
有人可以帮助我.. 我用过"' '"它显示了JAVA编制时间的错误..
我使用的是Eclipse IDE ..我的数据库是Oracle ..
答案 0 :(得分:2)
在没有单引号的情况下运行它:
String sql = "SELECT COLUMN1 AS ALIAS1, COLUMN2 AS ALIAS2 FROM TABLE1 WHERE CONDITION1 = CONDITION";
答案 1 :(得分:1)
尝试转义"
:
String sql = "SELECT COLUMN1 as \"ALIAS1\", COLUMN2 as \"ALIAS2\" FROM TABLE1 WHERE CONDITION1 = CONDITION";