3.windows-oracle实战第二课 -表的管理

oracle的核心 多表查询、存储过程、触发器

 字符型:

  char  定义 最大2000字符,例如“char(10)  '小韩' 前4个字符放小韩,后添加6个空格补全,查询极快

  varchar2(20) 变长 4000字符 ,是节约空间的

  clob 字符性大对象  相对于 varchar而言

  number 代表整数或者小数  例如:number(5,2)表示有5位有效数,2位小数 范围(-999.99-999.99);number(5)表示一个5位的整数(-99999-99999)

  date  年月日时分秒

  timestamp  数据类型扩展毫秒级(银行项目)

  blob  图片/声音/视频(一般存放路径,因为不安全,因此用不到)

表:

  create table student(

                                 id number(4),

                                 uname varchar2(20),

                                 sex char(2),

                                 birthday date,

                                 sal number(5,2)

                                 )

表是存储在磁盘中,但是为了管理好表引入一个表空间的概念,用于管理表。

     create table classes(

       classId number(2),

       cname varchar2(40)     

       );

添加一个字段:alter table student add(classId number(2));

修改表名,删除字段、修改字段类型或名字、修改字段长度varchar2等企业不常用,这里不介绍

删除表:drop table student;

添加表: insert into student values (1,'小明','男', '25-1月-1991',100.33,12); --默认格式

或者 alter session set nls_date_format = 'yyyy-mm-dd'; --针对的是当前会话,如果关闭,将失效

insert into student values (1,'小红','男', '1992-12-11',100.33,12);

如果有一个字段是null ,查询需要是 is null,不为空是 is not null (null和什么都没有是有区别的)

修改:update  student set sal=sal/2 ,classId=3  where set='男';

删除数据:delete from student;表结构是存在,写日志,可以恢复。用回滚命令

                   truncate table student; 无法恢复,速度极快

回滚:savepoint a; 

           delete  from  student;

           rollback to a;

猜你喜欢

转载自www.cnblogs.com/dangjingwei/p/12077817.html
今日推荐