Oracle query table field names and splicing

        When using databases, we often need to obtain all fields of a table, so how to query?

Query table field name

SELECT column_name
FROM all_tab_columns
WHERE table_name = 'table_name';

        Just replace the table_name in quotation marks with your own table name to find out all fields and return multiple rows.

Query table field names and splice them

SELECT LISTAGG(column_name, ', ') WITHIN GROUP(ORDER BY column_id) AS column_names
  FROM all_tab_columns
 WHERE table_name = 'table_name';

        Just replace the table_name in the quotation marks with your own table name to find out all the fields and concatenate them with commas and return them. If you need to use other characters to splice, just replace "," with the required comma.

Guess you like

Origin blog.csdn.net/weixin_40709965/article/details/132277269