zoukankan      html  css  js  c++  java
  • Oracle——判断对象是否存在(未完工)

    一、系统表:

    1、User_Tables:存储用户下的所有表的信息;

    2、dba_tables:存储管理员权限下的所有表的信息;

    3、all_tables:存储所有表的信息。

    4、all_Tab_Columns:存储所有表的所有字段的信息

    二、判断对象是否存在

    1、判断表

    我们只能通过使用select count(*) 的方式判断当前表是否存在,返回1则代表存在,0则代表不存在,例如:
    SELECT COUNT(*) FROM User_Tables WHERE table_name = 'CODE_BMDM';(在SQL中使用这种方法亦可)
    需要注意的是:表名(或者其他对象名)必须全部大写,有特殊字符的除外(表名之间有空格等特殊字符),否则查询不到。其中的 User_Tables(用户下的所有表) 也可以换成dba_tables(管理员权限下的所有表) 或者all_tables(所有表)

     2、判断字段

    declare cl integer:=0;
    begin
      select count(*) into cl from all_tab_columns where table_name='表名' and column_name='字段名';
      if cl<1 then /* 不存在字段 */
        dbms_output.put_line('bu存在字段');
        execute immediate'alter table 表名 add (字段名 varchar2(36))';
      end if;
    end;

    • 添加字段的语法:alter table tablename add (column datatype [default value][null/not null],….);
    • 修改字段的语法:alter table tablename modify (column datatype [default value][null/not null],….);
    • 删除字段的语法:alter table tablename drop (column);

    3、查看表中字段类型

    select * From all_tab_columns where table_name=upper('表名');

     

     

     

     

  • 相关阅读:
    个人工作总结(2)
    个人工作总结(1)
    学习进度条
    学习进度条
    返回一个二维整数数组中最大联通子数组的和
    学习进度条
    构建之法阅读笔记02
    STM32F4寄存器初始化:PWM输出
    STM32F4跳转函数
    STM32F4寄存器串口DMA汇总
  • 原文地址:https://www.cnblogs.com/SunBlog/p/4015477.html
Copyright © 2011-2022 走看看