I want to convert the below statement into normal query.
SELECT CAST(COLLECT(warehouse_name ORDER BY warehouse_name) AS warehouse_name_t) "Warehouses" FROM warehouses;
How to do this?
I tried some of the things but could not succeed. Please help.
I want to convert the below statement into normal query.
SELECT CAST(COLLECT(warehouse_name ORDER BY warehouse_name) AS warehouse_name_t) "Warehouses" FROM warehouses;
How to do this?
I tried some of the things but could not succeed. Please help.
If you want ANSI SQL and do not want a collection but want the values as rows:
SELECT warehouse_name
FROM Warehouses
ORDER BY warehouse_name
If you want to aggregate the rows into a single row and want a delimited single string then use LISTAGG
:
SELECT LISTAGG(warehouse_name, ',') WITHIN GROUP (ORDER BY warehouse_name)
AS warehouses
FROM Warehouses
If you want a collection data-type then CAST
and COLLECT
are standard built-in functions and are exactly what you should be using:
SELECT CAST(
COLLECT(warehouse_name ORDER BY warehouse_name)
AS warehouse_name_t
) AS Warehouses
FROM warehouses;
db<>fiddle here