1. 元数据表结构的查询语句:
--查询所有的表信息,当前数据库ZFW_WW下的表信息加owner
select * from all_tables;
select * from all_tables where owner='ZFW_WW';
--查询所有的视图信息,当前数据库ZFW_WW下的视图信息加owner
select * from all_views;
select * from all_views where owner='ZFW_WW';
--查询当前用户所有的表信息
select * from user_tables;
--查询当前用户下某个表字段信息
select * from user_tab_columns where table_name='T_GZGL_DW';
--查询所有用户的某个表字段信息
select * from all_tab_columns where Table_Name='T_GZGL_DW' ;
--查询当前用户表或者视图的注释信息
select * from user_tab_comments;
--查询所有用户下数据库ZFW_WW的表或者视图注释信息
select * from all_tab_comments where owner='ZFW_WW' ;
--查询当前用户下某个表的字段注释信息
select * from user_col_comments where table_name='T_GZGL_DW';
--查询所有用户下某个表的字段注释信息
select * from all_col_comments where table_name='T_GZGL_DW';
--关联查询某个表的字段和注释信息
select t1.column_name,t1.data_type,t1.data_length,t2.comments
from all_tab_columns t1
left join user_col_comments t2
on (t1.table_name= t2.table_name and t1.column_name= t2.column_name)
where t1.table_name='T_GZGL_DW'
and t2.table_name='T_GZGL_DW'
and t1.owner='ZFW_WW'
and t2.owner='ZFW_WW'
--查询某个表的限制字段信息
select * from user_cons_columns where Table_Name='T_GZGL_DW';
2.增删查改的语句
- 查询返回的默认字段名和数据库里的字段名保持大小写一致
- 查询语句的字段名大小写就是返回字段名的大小写,就是你写的SQL里大写返回就是大写,反之小写就返回小写;
--查
select * from ZFW_WW.T_GZGL_DW where ...
--删
delete from ZFW_WW.T_GZGL_DW where ...
--增
insert into ZFW_WW.T_GZGL_DW (WW_XH, WW_MC) values('','')
--改
update ZFW_WW.T_GZGL_DW set WW_XH = ''
3.达梦数据库大字段的读取
- 注意以map返回的对象(含有大字段)不能直接转json
import com.alibaba.druid.proxy.jdbc.ClobProxyImpl;
public static void setTextVal(Map<String, Object> row) {
for (Map.Entry<String, Object> entry : row.entrySet()) {
if (entry.getValue() instanceof ClobProxyImpl){
try {
ClobProxyImpl dmdbClob = (ClobProxyImpl) entry.getValue();
String value = dmdbClob.getSubString(1, (int) dmdbClob.length());
row.put(entry.getKey(),value);
} catch (SQLException e) {
log.error("达梦大字段取值异常:{}", Throwables.getStackTraceAsString(e));
}
}
}
}