select columns by a concat text as columnname in oracle

Posted by glaudiston on Stack Overflow See other posts from Stack Overflow or by glaudiston
Published on 2010-06-02T20:58:09Z Indexed on 2010/06/08 14:02 UTC
Read the original article Hit count: 163

Filed under:
|
|
|

I have a table with columns named with the number of hour of day like this:

col00 NUMBER(5)
col01 NUMBER(5)
col02 NUMBER(5)
...
col23 NUMBER(5)

...and I have another query that returns a count by hour.

I want to recover the colXX value by hour.... then I can recover with "decode" or "case when..." but I want know if exists any way to recover the column by a text like this:

select "col"||hour from table;

in the hypothetical above example if hour is 13 then would be translated like:

select col13 from table;

there is any way to do this ?

© Stack Overflow or respective owner

Related posts about sql

Related posts about Oracle