Is there a way to dynamically create an alias in pl/sql?
I have a table ABC
Field1 Field2 Field3 Field4
Joe Doe $45.00 XXX
Jane Doe $77.00 XXX
I created a new table MY_REF
TableName FieldName DisplayValue
ABC Field1 First Name
ABC Field2 Last Name
ABC Field3 Tax Amount
I would like to create a proc that would take a table name (as incoming param) and return the data with the custom aliases.
So if I passed in 'ABC' my end result would be:
First Name Last Name Tax Amount
Joe Doe $45.00
Jane Doe $77.00
EDIT: (Attempt based on Metthew's suggestion)
PROCEDURE GET_CUSTOM_DATA (
i_TableName IN VARCHAR2,
o_Refcur OUT SYS_REFCURSOR
)
IS
query_string VARCHAR2(500);
BEGIN
SELECT 'SELECT ' || listagg(fieldname || ' AS "' || displayvalue || '"',',') within group (order by null) || ' FROM ' || i_TableName
INTO query_string
FROM ABC
WHERE tablename = i_TableName
OPEN :o_Refcur FOR query_string;
END GET_CUSTOM_DATA_DATA;