Oracle 表结构、索引以及分区信息查询
Oracle 表结构、索引以及分区信息查询
/* 获取表:*/ select table_name from user_tables; --当前用户的表 select table_name from all_tables; --所有用户的表 select table_name from dba_tables; --包括系统表 --表字段信息 select * from all_tab_columns a where a.TABLE_NAME='T_X27_USER'; --表注释信息 select * from user_tab_comments a where a.table_name='T_X27_USER'; --表字段注释信息 select * from user_col_comments a where a.table_name='T_X27_USER'; --表分区信息 --1,分区表信息 -- (1)显示数据库所有分区表的信息 select * from DBA_PART_TABLES a where a.owner=upper('') and a.table_name=upper(''); -- (2)显示当前用户可访问的所有分区表信息 select * from ALL_PART_TABLES a where a.owner=upper('') and a.table_name=upper(''); -- (3)显示当前用户所有分区表的信息 select * from USER_PART_TABLES a where a.table_name=upper(''); --2,分区表的分区列信息 -- (1)显示当前用户所有分区表的分区列信息 select * from USER_PART_KEY_COLUMNS a where a.name=upper('') and a.object_type='TABLE'; -- (2)显示当前用户可访问的所有分区表的分区列信息 select * from ALL_PART_KEY_COLUMNS a where a.owner=upper('etl') and a.name=upper('') and a.object_type='TABLE'; --(3)显示分区列 显示数据库所有分区表的分区列信息 select * from DBA_PART_KEY_COLUMNS a where a.owner=upper('etl') and a.name=upper('') and a.object_type='TABLE'; -- 3,分区表的名字、归属表空间以及表的详细分区情况 select * from user_tab_partitions a where a.table_name=upper(''); -- 4,查看组合表的子分区信息以及子分区列信息情况 -- (1)显示当前用户所有组合分区表的子分区信息 select * from USER_TAB_SUBPARTITIONS; -- (2)显示当前用户可访问的所有组合分区表的子分区信息 select * from ALL_TAB_SUBPARTITIONS; -- (3)显示当前用户可访问的所有组合分区表的子分区信息 select * from ALL_TAB_SUBPARTITIONS ; -- (4)显示当前用户所有分区表的子分区列信息 select * from USER_SUBPART_KEY_COLUMNS; -- (5)显示当前用户可访问的所有分区表的子分区列信息 select * from ALL_SUBPART_KEY_COLUMNS; -- (6)显示子分区列 显示数据库所有分区表的子分区列信息 select * from DBA_SUBPART_KEY_COLUMNS; --表包含的索引 select * from user_indexes where table_name=upper('T_X27_USER'); --索引的具体信息:根据索引名查看索引包含的字段 select * from user_ind_columns where index_name = 'UK_T_X27_USER_USERID'; --表的唯一约束条件 select * from user_constraints where constraint_type='U' and owner='ETL' and table_name='T_X27_USER'; --表外键 select * from user_constraints where constraint_type='R' and owner='ETL' and table_name='T_X27_USER'; --表外键以及约束条件字段组成信息 select * from user_cons_columns where owner='ETL' and table_name='T_X27_USER';
示例(oracle查看表结构信息):
select a.owner 所属用户, a.table_name 表名, a.column_name 字段名, a.data_type 字段类型, a.字段长度, a.字段精度, a.是否为空, a.创建日期, a.最后修改日期, case when a.owner=d.owner and a.table_name=d.table_name and a.column_name=d.column_name then '主键' else '' end 是否主键 from (select a.owner,a.table_name,b.column_name,b.data_type,case when b.data_precision is null then b.data_length else data_precision end 字段长度,data_scale 字段精度, decode(nullable,'Y','√','N','×') 是否为空,c.created 创建日期,c.last_ddl_time 最后修改日期 from all_tables a,all_tab_columns b,all_objects c where a.table_name=b.table_name and a.owner=b.owner and a.owner=c.owner and a.table_name=c.object_name and a.owner='SCOTT' --这个是查某个用户,你到时候把用户名换一下就好,一定大写 and c.object_type='TABLE') a left join (select a.owner,a.table_name,a.column_name,a.constraint_name from user_cons_columns a, user_constraints b where a.constraint_name = b.constraint_name and b.constraint_type = 'P') d on a.owner=d.owner and a.table_name=d.table_name and a.column_name=d.column_name order by a.owner,a.table_name;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南