Oracle中的数据类型和表的管理


日期类型
   date 包含年月日和时分秒
   timestamp 这是Oracle9i对date数据类型的扩展 (时间戳)date类型的时间更精确
 

 图片类型

   blob 二进制数据可以存放图片 和声音 4G


 oracle表的管理

 创建表一个student表的语句

  create table student(
    xh number(4),
    xm varchar2(20),
    sex char(2),
    birthday date,
    sal number(7,2)
    );
  创建表一个Tclass表的语句

   create table Tclass(
     class_id number(2),
     cName varchar2(20)
     );


   修改表
   在Student表中添加一个字段class_id
   alter table student add(class_id number(2));

   在Student表中修改一个字段xm
   alter table student modify (xm varchar2(30))

   在Student表中删除一个字段xm
  alter table student drop column xm;

  怎样改oracle中的默认日期(因为在oracle中日期默认为 "日月年")

   alter session set nls_date_format='yy-mm-dd'


  使用is 关键字查询null值
  select * from student where birthday is null;
 

  使用like关键字
  select * from student where xh like '%3%';

  更新student表中xh=1234的birthday为 null值
  update student set birthday = null where xh = 1234

  删除数据
  delete from student;
 
 

 oracle 支持事务回滚
 设置 一个点 savepoint a ;
 执行 delete from student 语句 删除表中的所有数据
 然后回到 我们设置的点a

 执行的语句 :rollback to a ;


 执行完后我们在去查询数据表的数据 将会 回到删除前的状态。

 使用truncate 删除表 表的结构还在, 不写日志,无法找回删除的记录 , 但速度快。
执行语句:truncate table student

 使用delete 删除表
 使用delete删除会将表的结构删除 这张表将不会存在。

相关内容