I want to automatically assign column aliases to multiple columns. My tables usually have min 20 columns. I am trying to avoid writing something like "column1 AS XXX_column1, column2 AS XXX_column2 ... x20".
I am new to PLSQL but I was hoping to use output from multiplied “column AS XXX_column” returned by function directly in standard SELECT clause.
So I have written a function (RETURN data type is VARCHAR2) to generate a column name. I want to use it directly in my SELECT statement. Below is simplified example of this:
--- Function
CREATE OR REPLACE FUNCTION simple RETURN varchar2 IS
BEGIN
RETURN ‘my_column’;
END simple;
--- Select
SELECT simple FROM my_table;
This does not work. It seems that output from function is passed as a quotation i.e.
SELECT ‘my_column’ FROM my_table;
So the output from SELECT is a list of rows populated with values my_table:
COLUMN simple
ROW1 my_column
ROW2 my_column
ROW3 my_column
Can please someone help me with this?