Oracle - Selecting All User Tables with Fields and Comments
To write a script to select all user tables with fields and comments, we need system tables:
user_tables
--Выбираем все пользовательские таблицы и их параметры
select * from user_tables
user_tab_comments
--Выбираем комментарии к пользовательским таблицам
select * from user_tab_comments
user_tab_columns
--Выбираем все поля и их параметры по пользовательским таблицам
select * from user_tab_columns
user_col_comments
--Выбираем комментарии к полям пользовательских таблиц
select * from user_col_comments
Procedure that outputs a list of tables and all fields with data type, size, and comment:
begin
-- Выбираем все пользовательские таблицы
for rec in (select u1.TABLE_NAME,u2.COMMENTS from user_tables u1 left join user_tab_comments u2 on u1.TABLE_NAME=u2.TABLE_NAME)
loop
dbms_output.put_line(\'Таблица: \'||rec.table_name||\' - \'||rec.comments);
dbms_output.put_line(\'\');
--Выбираем поля и комментарии по таблице
for rec1 in
(
select t1.COLUMN_NAME, t1.DATA_TYPE, t1.DATA_LENGTH, t2.COMMENTS
from user_tab_columns t1
left join user_col_comments t2 on t1.TABLE_NAME=t2.TABLE_NAME and t1.COLUMN_NAME=t2.COLUMN_NAME
where upper(t1.table_name) = upper(rec.table_name) order by t1.COLUMN_ID
)
loop
dbms_output.put_line(\'Поле: \'||rec1.column_name||\' (\'||rec1.data_type||\'[\'||rec1.data_length||\']) - \'||rec1.comments);
end loop;
dbms_output.put_line(\'\');
dbms_output.put_line(\'\');
end loop;
end;
That's it.
Comments (0)
No comments yet.