English 中文(简体)
Is it mandatory to use an ALIAS when we are doing some operation on the column?
原标题:

Folks, Is it mandatory to use an ALIAS when we are doing some operation on the column?

Ex: select upper(col1) from table1
when i am trying to retrieve the resultset by rs.getString("col1"), it was giving this exception COM.ibm.db2.jdbc.DB2Exception: [IBM][JDBC Driver] CLI0611E Invalid column name. SQLSTATE=S0022

when I changed the query to:
select upper(col1) as col1 from table1 and used rs.getString("col1"), it is working fine.

So, is it mandatory to use an ALIAS when some function like upper,trim,lower was applied on a column???

I am using: DB2 8.2, Type 2 driver

Thanks

最佳回答

The expression UPPER(COL1) is not the same thing as COL1.

Compare this:

$ db2 "describe select col1 from session.t1"

SQLDA Information

 sqldaid : SQLDA     sqldabc: 1136  sqln: 20  sqld: 1

 Column Information

 sqltype               sqllen  sqlname.data                    sqlname.length
 --------------------  ------  ------------------------------  --------------
 453   CHARACTER           10  COL1                                         4

To this:

$ db2 "describe select upper(col1) from session.t1"

SQLDA Information

 sqldaid : SQLDA     sqldabc: 1136  sqln: 20  sqld: 1

 Column Information

 sqltype               sqllen  sqlname.data                    sqlname.length
 --------------------  ------  ------------------------------  --------------
 453   CHARACTER           10  1                                            1

Notice that the column names in each result set (sqlname.data) are not the same.

So, you would have either have to use a column alias or use rs.getString("1").

问题回答

Try rs.getString("upper(col1)") instead? Typically column names in the result include any functions that were applied for that column. Otherwise, you couldn t have results for things like SELECT MIN(col1),MAX(col1) ...





相关问题
handling exceptions IN Action Filters

Is there a better way to handle exceptions that occur inside an Action Filter itself in ASP .NET MVC? There re 2 ways I can think of at the moment. Using a try catch and setting the HTTP Status ...

既可捕获,又可举出例外。

我有一种办法,可以进入亚洲开发银行,因此,我国的亚行在多瑙河航道中的所有 st子都位于一个试捕区。 它正在追捕Kexception

Cross compiler exception handling - Can it be done safely?

I am doing some maintenance on a C++ windows dll library that is required to work with different VC++ compilers (as I don’t want to address different mangling schemes). I have already eliminated any ...

File Handling Issue

I am developing a tool in c#, at one instance I start writing into a xml file continuously using my tool,when i suddenly restart my machine the particular xml file gets corrupted, what is the reason ...

Watch a memory location/install data breakpoint from code?

We have a memory overwrite problem. At some point, during the course of our program, a memory location is being overwritten and causing our program to crash. the problem happens only in release mode. ...

Unit Test for Exceptions Message

Is there a simple (Attribute-driven) way to have the following test fail on the message of the exception. [TestMethod()] [ExpectedException(typeof(ArgumentException))] public void ExceptionTestTest() ...

热门标签