Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

select a column name with a variable

gellisJul 17 2019 — edited Jul 22 2019

Hi,

i have a table with 10 columns ,with names: cost201907,  cost201906, cost201905 ......

i want to put in a variable the today month and year:   a = 201907

My goal is to select a column using this variable.

for example i want its month to run a script which give me today date in a variable, for example:     a = 201907

and after use it to select the most recent columns with a select statement,  such as:                       Select  'cost'||a  from Table1.

Probably i ll use PL/SQL but still cant find a way. Please help me.

Comments
Post Details
Added on Jul 17 2019
12 comments
7,601 views