Skip to content

Instantly share code, notes, and snippets.

@bradjolicoeur
Created April 1, 2014 17:29
Show Gist options
  • Save bradjolicoeur/9918928 to your computer and use it in GitHub Desktop.
Save bradjolicoeur/9918928 to your computer and use it in GitHub Desktop.
Oracle script to code gen an insert statement for an existing table.
with col as (
select atc.column_name, atc.data_type, atc.data_length, atc.nullable, atc.table_name from all_tab_cols atc
where table_name = '[table name here]'
order by column_id)
select distinct 'insert into ' || lower(table_name) ||' (' from col
union all
select case when rownum != 1 then ', ' || lower(column_name) else lower(column_name) end from col
union all
select ') values (' from dual
union all
select case when rownum != 1 then ', ' else '' end || 'null --' || column_name || ': ' || data_type || '(' || data_length || ') nullable: ' || nullable from col
union all
select ')' from dual
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment