Oracle导出表结构

Oracle导出表结构。

表结构Sql

-- 表结构导出
SELECT
B.TABLE_NAME AS "表名",
C.COMMENTS AS "表说明",
B.COLUMN_NAME AS "属性",
A.COMMENTS AS "描述",
case when B.DATA_TYPE ='VARCHAR2' then  B.DATA_TYPE ||'('|| B.DATA_LENGTH || ')'
when B.DATA_TYPE ='DATE' then B.DATA_TYPE 
when B.DATA_TYPE = 'NUMBER' and B.DATA_SCALE != 0  then B.DATA_TYPE ||'('|| B.DATA_PRECISION || ',' || B.DATA_SCALE || ')'
when B.DATA_TYPE = 'NUMBER' then B.DATA_TYPE ||'('|| B.DATA_PRECISION || ')'
end AS "DB数据类型",
case when B.DATA_TYPE ='VARCHAR2' then  'String'
when B.DATA_TYPE ='DATE' then 'Date'
when B.DATA_TYPE = 'NUMBER' and B.DATA_SCALE != 0 then 'Double'
when B.DATA_TYPE = 'NUMBER' then 'Integer'
end AS "类型",
'' as 规则,
B.DATA_DEFAULT as 默认值,
case when B.NULLABLE = 'N' then 'not null'
    when B.NULLABLE = 'Y' then '' end
  as 必填,
'' as 备注
FROM
ALL_COL_COMMENTS A,
ALL_TAB_COLUMNS B,
ALL_TAB_COMMENTS C
WHERE
A.TABLE_NAME IN (SELECT U.TABLE_NAME FROM USER_ALL_TABLES U)
AND A.OWNER = B.OWNER
AND A.TABLE_NAME = B.TABLE_NAME
AND A.COLUMN_NAME = B.COLUMN_NAME
AND C.TABLE_NAME = A.TABLE_NAME
AND C.OWNER = A.OWNER
AND A.OWNER = 'XXX' --用户名(区分大小写)
AND A.TABLE_NAME = 'XXX' --表名(区分大小写)
ORDER BY A.TABLE_NAME, B.COLUMN_ID;

主键、索引、分区

-- 1.查看索引字段
select t.TABLE_NAME,t.COLUMN_NAME from user_ind_columns t,user_indexes i where t.index_name = i.index_name and
t.table_name='XXX' -- 替换自己使用的表名即可
GROUP by t.TABLE_NAME,t.COLUMN_NAME;
-- 2. 查看主键字段
select cu.* from user_cons_columns cu, user_constraints au where cu.constraint_name = au.constraint_name and
au.constraint_type = 'P' AND cu.table_name = 'XXX'; -- 替换自己使用的表名即可
-- 3. 查看分区字段
SELECT * FROM all_PART_KEY_COLUMNS where OWNER = 'ZC' and name ='XXX'; -- 替换自己使用的表名即可

表结构示例

图片示例

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值