oracle查询数据结构滤涉及的sql语句

  • 背景:去客户数据库查询表数据。了解表结构以及表字段及索引等信息
  • oracle数据库
sql 复制代码
SELECT 
  t.OWNER AS "用户名",
  t.TABLE_NAME AS "表名",
  c.COMMENTS AS "表说明"
FROM 
  ALL_TABLES t
LEFT JOIN 
  ALL_TAB_COMMENTS c 
  ON t.OWNER = c.OWNER 
  AND t.TABLE_NAME = c.TABLE_NAME
  AND c.TABLE_TYPE = 'TABLE'
WHERE 
  (t.OWNER = UPPER('HIS')  or t.OWNER = UPPER('SXEMR'))
  AND t.TABLE_NAME NOT LIKE 'BIN$%' 
  --AND (c.COMMENTS like '%住%' or c.COMMENTS like '%转%' )
  AND (c.COMMENTS like '%住院%' )
ORDER BY 
  c.COMMENTS;

select * from HIS.FIN_IPR_INMAININFO

SELECT 
  t.OWNER AS "用户名",
  t.TABLE_NAME AS "表名",
  c.COMMENTS AS "表说明"
FROM 
  ALL_TABLES t
LEFT JOIN 
  ALL_TAB_COMMENTS c 
  ON t.OWNER = c.OWNER 
  AND t.TABLE_NAME = c.TABLE_NAME
  AND c.TABLE_TYPE = 'TABLE'
WHERE 
  t.OWNER = UPPER('LIS')  -- 替换为实际用户名
  AND t.TABLE_NAME NOT LIKE 'BIN$%'  -- 排除回收站中的表
  and t.TABLE_NAME  like 'LIS_RE%'
ORDER BY 
  c.COMMENTS;


SELECT 
  t.OWNER AS "用户名",
  t.TABLE_NAME AS "表名",
  c.COMMENTS AS "表说明"
FROM 
  ALL_TABLES t
LEFT JOIN 
  ALL_TAB_COMMENTS c 
  ON t.OWNER = c.OWNER 
  AND t.TABLE_NAME = c.TABLE_NAME
  AND c.TABLE_TYPE = 'TABLE'
WHERE 
  t.OWNER = UPPER('SXEMR')  -- 替换为实际用户名
  AND t.TABLE_NAME NOT LIKE 'BIN$%'  -- 排除回收站中的表
  -- and c.COMMENTS  like '%诊断%'
ORDER BY 
   c.COMMENTS asc;

SELECT
    t.TABLE_NAME AS "表名",
    c.COLUMN_NAME AS "字段名",
    com.COMMENTS AS "字段描述"
FROM
    ALL_TABLES t
JOIN
    ALL_TAB_COLUMNS c ON t.OWNER = c.OWNER AND t.TABLE_NAME = c.TABLE_NAME
LEFT JOIN
    ALL_COL_COMMENTS com ON c.OWNER = com.OWNER 
                          AND c.TABLE_NAME = com.TABLE_NAME 
                          AND c.COLUMN_NAME = com.COLUMN_NAME
WHERE
    t.OWNER = 'HIS' 
  AND c.TABLE_NAME = 'FIN_IPR_INMAININFO'
ORDER BY
    t.TABLE_NAME,
    c.COLUMN_ID;  

select * from ALL_TAB_COLUMNS;

SELECT
    t.TABLE_NAME AS "表名",
    c.COLUMN_NAME AS "字段名",
    com.COMMENTS AS "字段描述",
    c.DATA_TYPE AS "字段类型"
FROM
    ALL_TABLES t
JOIN
    ALL_TAB_COLUMNS c ON t.OWNER = c.OWNER AND t.TABLE_NAME = c.TABLE_NAME
LEFT JOIN
    ALL_COL_COMMENTS com ON c.OWNER = com.OWNER 
                          AND c.TABLE_NAME = com.TABLE_NAME 
                          AND c.COLUMN_NAME = com.COLUMN_NAME
WHERE
    t.OWNER = 'HIS'
  and t.TABLE_NAME = 'FIN_IPR_INMAININFO'
ORDER BY
    t.TABLE_NAME,
    c.COLUMN_ID; 


SELECT T.PATIENT_NO AS 住院号,T.CARD_NO AS 就诊卡号,T.PATIENT_NO AS 住院号 FROM HIS.FIN_IPR_INMAININFO T


SELECT 
    a.constraint_name, 
    a.table_name,
    a.constraint_type,
    b.column_name, 
    b.position
FROM 
    all_constraints a, 
    all_cons_columns b
WHERE 
    a.constraint_name = b.constraint_name
    AND a.constraint_type = 'P'
    AND a.table_name = 'FIN_IPR_INMAININFO';
相关推荐
p***95001 小时前
Springboot3 Mybatis-plus 3.5.9
数据库·oracle·mybatis
合作小小程序员小小店1 小时前
桌面开发,在线%信息管理%系统,基于vs2022,c#,winform,sql server数据。
开发语言·数据库·sql·microsoft·c#
卡提西亚1 小时前
数据库笔记-4-SQL语言之DCL
数据库·笔记·sql
Mz12211 小时前
day05 移动零、盛水最多的容器、三数之和
数据结构·算法·leetcode
p***23361 小时前
python的sql解析库-sqlparse
数据库·python·sql
0***h9421 小时前
oracle 12c查看执行过的sql及当前正在执行的sql
java·sql·oracle
a41324471 小时前
如何解决centos上oracle连接问题
linux·oracle·centos
Cisyam^1 小时前
openGauss + LangChain Agent实战:从自然语言到SQL的智能数据分析助手
sql·数据分析·langchain
q***23571 小时前
配置MyBatis-Plus打印执行的 SQL 语句到控制台或日志文件中
数据库·sql·mybatis
complexor1 小时前
NOIP 2025 游记
数据结构·数学·动态规划·贪心·组合计数·树上问题·游记&总结