Home > database >  Is there a way to select hardcoded values under the same column name
Is there a way to select hardcoded values under the same column name

Time:11-11

I have 3 values 'ABC', 'DEF', and 'GHI' and I need to select them as a single column from the table so that output is:

Column1
________
ABC
DEF
GHI

CodePudding user response:

Use UNION ALL:

SELECT 'ABC' AS column1 FROM DUAL UNION ALL
SELECT 'DEF' FROM DUAL UNION ALL
SELECT 'GHI' FROM DUAL;

Or, use a collection:

SELECT COLUMN_VALUE AS column1
FROM   TABLE(SYS.ODCIVARCHAR2LIST('ABC', 'DEF', 'GHI'));

Which both output:

COLUMN1
ABC
DEF
GHI

db<>fiddle here

  • Related