select wm_concat(COLUMN_NAME) A FROM ALL_TAB_COLUMNS where table_name like 'T_EMPLOYEE';
How to extract the data out from A
and assign it to another varchar2
variable?
select wm_concat(COLUMN_NAME) A FROM ALL_TAB_COLUMNS where table_name like 'T_EMPLOYEE';
How to extract the data out from A
and assign it to another varchar2
variable?
If you just need to store it in a VARCHAR2 variable for further processing, you can do it with something like:
DECLARE
BUFF_V VARCHAR2(2000); -- make sure there's enough space or add some substr
BEGIN
SELECT wm_concat(COLUMN_NAME)
INTO BUFF_V
FROM ALL_TAB_COLUMNS
WHERE TABLE_NAME LIKE 'T_EMPLOYEE';
END;
If you don't want to bother with the parsing of the wm_concat, you can just use something like:
DECLARE
COL_V VARCHAR2(100);
BEGIN
FOR QUERY_C IN (select COLUMN_NAME FROM ALL_TAB_COLUMNS where table_name like 'T_EMPLOYEE') LOOP
COL_V := QUERY_C.COLUMN_NAME;
-- do whatever you want with COL_V
END LOOP;
END;
This will iterate on all results (all column names of table T_EMPLOYEE) storing them in the COL_V variable.
I know there is an accepted answer already but just FYI, wm_concat will not work if your version is upgraded on 12c.
You may use LISTAGG as an alternative so why bother use an undocumented feature.Read this
Just saying.
Cheers =)