gpt4 book ai didi

java - 在 java 中使用带别名的查询

转载 作者:行者123 更新时间:2023-11-29 04:46:15 25 4
gpt4 key购买 nike

当我在 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..

最佳答案

在没有单引号的情况下运行它:

String sql = "SELECT COLUMN1 AS ALIAS1, COLUMN2 AS ALIAS2 FROM TABLE1 WHERE CONDITION1 = CONDITION";

关于java - 在 java 中使用带别名的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37003629/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com