Ms Sql sys tables在Oracle中是equivelant

时间:2016-08-24 13:12:37

标签: oracle system-tables

我无法在oracle中找到所有等效的表。 如;

sys.index_columns
sys.columns
sys.foreign_key_columns

是否有任何列表可以找到这些表名?我们在mssql中有几个查询,需要转换为oracle。

3 个答案:

答案 0 :(得分:4)

您正在寻找Oracle Data Dictionary

MS SQL                      Oracle
------------------------    ------------------------------------------
sys.index_columns           user_indexes      and  user_ind_columns
sys.columns                 user_tab_cols
sys.foreign_key_columns     user_constraints  and  user_cons_columns

代替user_(仅限于您自己的架构中的对象),您还可以对您有权访问的所有对象使用all_,或者对数据库中的所有对象使用dba_ (如果您有DBA授权)。

答案 1 :(得分:3)

记录数据表。见Static Data Dictionary Views

您可能正在寻找表格:

  • ALL_IND_COLUMNS
  • ALL_TAB_COLUMNS
  • ALL_CONS_COLUMNS

答案 2 :(得分:1)

如果有任何帮助,这里是我在我构建的“数据库浏览器”中使用的SQL模板。它根据所选数据库的RDBMS进行自我调整,并将完全相同的数据返回到应用程序中。

您可以在这里获得查询:

  • 表和视图列表,包括统计信息表中的行数。
  • 表的结构,包括索引列

表/视图列表

SQL SERVER:

SELECT ta.tname, sc.name AS owner, ta.ttype, SUM(pa.rows) RowCnt
 FROM
 (
     SELECT 'T' AS ttype, object_id, schema_id, name AS tname
     FROM sys.tables 
     WHERE is_ms_shipped = 0 AND name LIKE  '%{table_name_whatever}%' 
     UNION ALL
      SELECT 'V' AS ttype, object_id, schema_id, name AS tname
     FROM sys.views 
     WHERE is_ms_shipped = 0  AND name LIKE  '%{table_name_whatever}%'
) ta
LEFT JOIN sys.partitions pa ON pa.OBJECT_ID = ta.OBJECT_ID AND pa.index_id IN (1,0)
LEFT JOIN sys.schemas sc ON ta.schema_id = sc.schema_id
GROUP BY ta.tname, sc.name, ta.ttype
ORDER BY ta.tname

ORACLE

(SELECT table_name as tname, owner, 'T' AS ttype, NUM_ROWS AS RowCnt FROM all_tables WHERE table_name LIKE  '%{table_name_whatever}%') 
UNION ALL  
(SELECT view_name as tname, owner, 'V' AS ttype, NULL AS RowCnt FROM all_views WHERE view_name LIKE  '%{table_name_whatever}%') ORDER BY tname

表结构(cols和basic idx)

SQL SERVER

SELECT c.name as column_name, ty.name AS type_name, c.max_length AS col_len,
    (CASE 
        WHEN (i.name IS NOT NULL AND i.is_unique=1) THEN 'U'
        WHEN (i.name IS NOT NULL AND i.is_unique=0) THEN 'X'
        ELSE '' 
    END) AS idx,
    '' as comments
FROM sys.columns c
INNER JOIN sys.objects o                ON o.object_id=c.object_id  
INNER JOIN sys.types ty         ON c.system_type_id = ty.system_type_id AND ty.name<>'ID_Code'
LEFT  JOIN sys.index_columns ic ON o.object_id = ic.object_id AND ic.column_id = c.column_id
LEFT  JOIN sys.indexes i                ON o.object_id = i.object_id AND i.index_id = ic.index_id 
WHERE o.name = '{table_name_whatever}' 
ORDER BY C.column_id

ORACLE

SELECT  t.column_name, t.data_type as type_name, t.data_length as col_len, 
                (CASE 
                    WHEN b.uniqueness='UNIQUE' THEN 'U' 
                    WHEN b.uniqueness='NONUNIQUE' THEN 'X' 
                    ELSE '' 
              END) AS idx,
              c.comments
FROM all_tab_columns t
LEFT JOIN all_col_comments c ON c.table_name=t.table_name AND c.column_name = t.column_name
LEFT JOIN all_ind_columns a  ON a.table_name=t.table_name AND a.column_name = t.column_name
LEFT JOIN all_indexes b      ON a.index_name=b.index_name 
WHERE t.table_name='{table_name_whatever}' 
ORDER BY t.column_ID