Skip to content

Instantly share code, notes, and snippets.

@thiago-vieira
Created January 13, 2015 19:34
Show Gist options
  • Save thiago-vieira/ad6b96a55938722d4bc5 to your computer and use it in GitHub Desktop.
Save thiago-vieira/ad6b96a55938722d4bc5 to your computer and use it in GitHub Desktop.
Generate database schema document with search
select
TABLE_NAME,
decode(column_id,0,null,column_id) as COLUMN_ID,
COLUMN_NAME, NULLABLE, DATA_TYPE, COMMENTS
from (
select cc.TABLE_NAME,
tc.COLUMN_ID, tc.COLUMN_NAME,
tc.NULLABLE, tc.DATA_TYPE ||
case when tc.DATA_SCALE is not null then '(' || tc.DATA_PRECISION || ',' || tc.DATA_SCALE || ')'
when tc.DATA_PRECISION is not null then '(' || tc.DATA_PRECISION || ')'
when tc.DATA_LENGTH is not null and tc.DATA_TYPE like '%CHAR%' then '(' || tc.DATA_LENGTH || ')'
end DATA_TYPE,
cc.COMMENTS
from all_col_comments cc
INNER JOIN all_tab_cols tc ON (cc.TABLE_NAME = tc.TABLE_NAME and cc.TABLE_NAME = tc.TABLE_NAME and cc.COLUMN_NAME = tc.COLUMN_NAME and cc.owner = tc.owner)
where cc.owner = 'SCHEMA_OWNER'
UNION
select tab.table_name as TABLE_NAME,
0 as COLUMN_ID, '' as COLUMN_NAME,
'' as NULLABLE, '' as DATA_TYPE,
tab.comments as COMMENTS
from all_tab_comments tab
where tab.owner = 'SCHEMA_OWNER'
)
order by table_name, decode(column_id,null,0,column_id);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment