开发者

DB2: How to print few columns with conversion along with all other columns without having to write all the names of the columns?

开发者 https://www.devze.com 2023-04-07 02:11 出处:网络
I have a table having 10 columns, with id, f_name, l_name ..... low_range, high_range, ... I want to write a query which will print all my table, but just this low_range and high_range to be converte

I have a table having 10 columns, with id, f_name, l_name ..... low_range, high_range, ...

I want to write a query which will print all my table, but just this low_range and high_range to be converted in hex.

I know two things:

 1. We can write all the column names and replacing the 
    low_range with hex(low_range) and high_range with high_range. 

but 开发者_JAVA百科this asks me two to write all the column names, which seems a bit unfair.

2. We can write a query like:
 select t.*, hex(low_range), hex(high_range) from table t

But it will give all the column names first and then the required fields in hex also after them, which I don't want to as there is a repetition of information.

Is there any other clean way to achieve this thing.

PS: I am new to databases.


In short, no. The two ways you list are the only two ways to specify column output order, so you can either:

  1. select t.* and then append your custom fields to the end (or the beginning) OR

  2. List each field individually eg select t.field1, t.field2, hex(t.field3), t.field4...

The two methods you describe are the only ways to do this.

0

精彩评论

暂无评论...
验证码 换一张
取 消