Skip to main content

Posts

Showing posts from June, 2018

Generate a list of columns to be used in Insert or for the IN clause.

How often do we have to write an insert with explicit column list: May be because the source we are inserting from do not have all the columns. Or the destination table has that dreaded long column that you have to exclude. Keep below SQL handy (Oracle database 11g onwards only). To quickly get a comma seperated list of columns for a table. SELECT LISTAGG(column_name , ',') WITHIN GROUP (ORDER BY column_id ) column_list FROM all_Tab_columns where table_name = upper(:TABLE_NAME) and owner = upper(:OWNER) GROUP BY table_name;