5.Oracle中的数据表

1.数据表的数据类型:
    varchar2(size) : 可变字符数据;
    char:固定长度字符数据;
    number:数值型;
    date:日期时间型;
    long:可变长度的字符型数据(2G);
    clob:单字节的大型字符对象(4G);
    raw and long raw : 二进制类型;
    blob:二进制大型对象,最大(4G);
    bfile:二进制数据,在数据库外部存储文件(4G);

2.表的创建:
   create table 表名
   (
      字段1 类型1,
      字段2 类型2,
         ...       ...
      字段n 类型n
    )
  create table student
  (
     stuno int,
     stname varchar(10)not null,
     stBirth date default to_date('1987-6-23','YYYY-MM-DD')
  );

3.数据表的维护:
  添加字段:
  alter table student add(stuphone varchar(18));
  删除字段:
  alter table student drop column stuphone;
  修改字段:
  alter table student modify(stuname varchar(12));
  将一列设置为不可使用状态;意味着可以删除掉;
  alter table student set unused column stuname;
  删除无用字段:
  alter table student drop unused columns;
  增加约束:
  alter table student add constraint pk_stuno primarykey(stuno);
  删除约束:
  alter table student drop constraint pk_stuno;
  查看表约束:

  desc user_constraints;

4.表分区:
   第一种方案:范围分区法
                        这种分区法事根据表中列值的范围对表进行分区;
                        分区时,首先依据列中的值可能的范围进行划分;
                        如某省对参加四六级考试的成绩进行整理并保存至数据库。我们可以对于分数段进行如下划分:
                           60---p1;
                           75---p2;
                           85---p3;
                           100--p4;
    create table student
    (
       student_ID integer not null,
       student_name varchar2(20),
       score integer
     )
     partition by range(score)
     (
         partition p1 values less than(60),
         partition p2 values less than(75),
         partition p3 values less than(85),
         partition p4 values less than(maxvalue)   
     );
     查询表中数据:select * from student partition(p1);
   第二种方案:散列分区法
                        提供了一种通过指定分区编号来均匀的分布数据的方法;
                        它通过hash函数将数据映射到相应的分区上;
                        它可使得数据均匀的分布到各个分区上,各个分区大小趋于一致;
      create table department
       (
          deptno int,
          deptname varchar(14)
        )
       partition by hash(depno)
       (
           partition p1,
           partition p2
        );
    第三种方案:复合分区
                         先对数据进行范围分区,然后在每个子分区又进行散列泛起的一种分区表方法;
         create table salgrade
         (
            grade number ,
            losal number,
            hisal number
          )
         partition  by range(grade) --先范围分区;
         subpartition by hash(losal,hisal) --然后散列分区;
         (
             partition p1 values less than(10),
             (subpartition sp1,subpartition sp2),
             partition p2 values less than(20),
             (subpartition sp3,subpartition sp4),
          );
    第四种方案:列表分区
                        列表分区允许用户明确地控制行到分区的映射;
                        不同范围分区或散列分区,他允许按自然方式对无序或不相关的数据集进行分组和组织;
                        例如:在客户表中记录着客户的国籍信息,他们是中国,美国,法国,英国,加拉大。那么在创建表时,                         我们可以对表进行列表分区;
         create table customer
         (
            custno int,
            custname varchar(20);
            custstate varchar(20)
          )
          partition by list(custstate)
         (
             partition asia values('中国','韩国','新加坡'),
             partition europe values('英国','法国','德国'),
             partition ameria values('美国','加拿大','墨西哥')
          );
5.查看表分区语句:
      desc user_tab_partitions;
   查看表上的分区:
      select table_name as 表名,partition_name as 分区名,partition_position from user_tab_partitions;

原文地址:https://www.cnblogs.com/zhangqs008/p/2341257.html