zoukankan      html  css  js  c++  java
  • 如何查询数据库中所有表格,或者查询是否存在某个表格-mysql和oracle

    这个问题,在之前就有写过,但是想找到语句还是记不得,这里主要提及我自己有用到的数据库mysql和oracle

    1、mysql

      这个是自己安装的,所有配置都是默认配置没有改变,所以保存表名的表还是information_schema.tables,语句如下:

    --获取数据库中所有用户名,表名
    select table_schema 用户名,table_name 表名 from information_schema.tables
    --获取'test'用户下所有表
    select table_schema 用户名,table_name 表名 
    from information_schema.tables
    where table_schema='test'
    --判断'test'用户下是否有'user'表
    select * 
    from information_schema.tables
    where table_schema='test'
      and table_name='user' 
    --在mysql里面表名、用户名可以不区分大小写,譬如下面语句也可以查询出结果
    select * 
    from information_schema.tables
    where table_schema='TEST'
      and table_name='uSer'

    2、Oracle

      这个不是我的数据库,而oralce中保存表名的表在网上也是众说纷纭,我最终找到的表是all_tables,而且它保存的表名作为字符串是区分大小写的

    --取某个表
    select * from all_tables WHERE upper(OWNER) LIKE '用户名大写' AND upper(TABLE_NAME) LIKE '表名大写'
    --取库中所有表
    select * from all_tables
    select * from all_tables@想要的远程库

      

    当你深入了解,你就会发现世界如此广袤,而你对世界的了解则是如此浅薄,请永远保持谦卑的态度。
  • 相关阅读:
    PAT顶级 1024 Currency Exchange Centers (35分)(最小生成树)
    Codeforces 1282B2 K for the Price of One (Hard Version)
    1023 Have Fun with Numbers (20)
    1005 Spell It Right (20)
    1092 To Buy or Not to Buy (20)
    1118 Birds in Forest (25)
    1130 Infix Expression (25)
    1085 Perfect Sequence (25)
    1109 Group Photo (25)
    1073 Scientific Notation (20)
  • 原文地址:https://www.cnblogs.com/liwxmyself/p/12066262.html
Copyright © 2011-2022 走看看