Oracle gets all column names of the table

I want to use insert into to import data from one table into another table, but the columns of the two tables are not the same. The latter table is less than the former, and the names of the same parts are the same, so I want to get all the columns of the target table directly Name, and then export the data insert of these columns from the source table. To get all the column names of a table, Oracle has several views under SYS that can do it:

all_tab_comments
user_tab_comments
all_col_comments
user_col_comments
all_tab_columns
user_tab_columns

The beginning of all is all users, user is the current user, the specific difference is to look at the script of the view, user_col_comments contains less content than user_tab_columns, only three fields, and user_tab_comments is richer. But they can list all the column names of the table, but there are some differences. For example, user_col_comments does not contain the serial number of the field, so the columns found by it are not in the order of the original table. If you follow the original table column order, you can Use user_tab_columns, order by column_id can be achieved, such as

select column_name  from user_tab_columns  where table_name='表名' ORDER BY column_id

Note that the name of the table to be queried must be capitalized. If you want to transpose the found column names into row data, you can use wmsys.wm_concat, and all column data becomes one row, separated by commas.

Guess you like

Origin blog.csdn.net/qq_36802726/article/details/109722979