oracle 常用数据类型及表的创建及使用

oracle 常用数据类型及表的创建及使用

案例分析
创建一个人员信息表

drop table person;
create table person(
       xingming varchar2(20),
       age  number(2),
       shengri date default sysdate,
       xingbie varchar2(20) default '男'
);

给表中插入数据
insert into person (xingming,age,shengri,xingbie) values ('大桥',18,TO_DATE('2222-10-21','yyyy-mm-dd'),'女');
insert into person (xingming,age,xingbie)values ('长肥',25,'男'); 
insert into person values('呵呵',108,'男');
select*from person;

给表重命名
RENAME 旧的表 TO 新的表名;
rename person to renyuan;
select*from renyuan;

复制表
create table 表名称 as 子查询
范例:将10部门的雇员数据复制到emp10之中
create table emp 10 as select*from emp where deptno=10;
删除表
drop table 表名称;
彻底删除表

drop table 表名  purge;

oracle 常用数据类型及表的创建及使用
提交事务
commit;
给数据表中加入数据列
例子:向person表中加入tel number(20)和address varchar(30)列
alter table 表名称 add(
      列名称 数据类型[default 默认值],
      列名称 数据类型[default 默认值],..
);




alter table person add(
      tel number(10),
      address varchar2(30) default '中国陕西省西安'
);


修改列结构
例子将person中的tel改为varchar2类型,并设置默认值120120120

alter table 表名称 modify(
      列名称 数据类型[default 默认值],
      列名称 数据类型[default 默认值],..
);




alter table person modify(
      tel varchar2(11) default '120120120'
);