Created
April 1, 2014 17:29
-
-
Save bradjolicoeur/9918928 to your computer and use it in GitHub Desktop.
Oracle script to code gen an insert statement for an existing table.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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