设为首页 加入收藏

TOP

Oracle06、增删改数据(二)
2017-10-16 18:20:02 】 浏览:10129
Tags:Oracle06 删改 数据
清空回收站 select * from recyclebin;--查询清空之后删除的表是不是还是在回收站(亲测不在回收站中了) /*使用关键字purge,彻底删除emp表,即不会将emp表丢入回收站,永久删除emp表,drop table 表名 purge*/ create table t_hzp( id number(12) primary key, name varchar(32) );--创建表 insert into t_hzp (id,name) values (12,'夜孤寒');--插入数据 select * from t_hzp;--查询表数据 drop table emp purge;--彻底删除表 select * from recyclebin;--查询删除的表是不是在回收站中 /*依据xxx_emp表结构,创建emp表的结构,但不会插入数据*/ create table xxx_emp as select * from emp where 1<>1;--复制表结构 select * from xxx_emp;-- /*当不小心使用关键字purge将表彻底删除之后怎么回复?如果没有办法的话,那就创建吧...*/ create table EMP ( empno NUMBER(4) not null, ename VARCHAR2(10), job VARCHAR2(9), mgr NUMBER(4), hiredate DATE, sal NUMBER(7,2), comm NUMBER(7,2), deptno NUMBER(2) ); /*使用下面语句更新或者创建对象比较方便*/ select * from emp for update; /*创建emp表,复制xxx_emp表中的结构,同时复制xxx_emp表的所有数据*/ create table yyy_emp as select * from emp where 1=1;--复制表 select * from yyy_emp;--查询表 注意:where不写的话,默认为true /*将emp截断,再自动创建emp表,truncate table 表名*/ truncate table emp; /*向emp表,批量插入来自xxx_emp表中部门号为20的员工信息,只包括empno,ename,job,sal字段*/ insert into emp (empno, ename, job, sal) select empno, ename, job, sal from xxx_emp where deptno = 20; /*使用关键字purge,彻底删除emp表,即不会将emp表丢入回收站,不要乱用,不然就炸了*/ drop table emp purge; /*依据xxx_emp表,只创建emp表,但不复制数据,且emp表只包括empno,ename字段*/ create table emp(empno,ename) as select empno,ename from xxx_emp where 1=2; /*向emp表(只含有empno和ename字段),批量插入xxx_emp表中部门号为20的员工信息*/ insert into emp (empno, ename) select empno, ename from xxx_emp where deptno = 20;

 以上基本涵盖了Oracle常用的增删改操作,如果读者觉得有遗漏的话,欢迎指正,谢谢!

三、drop、truncate、delete的区别

drop table 和 truncate table 和 delete from 区别:
drop table
1)属于DDL
2)不可回滚
3)不可带where
4)表内容和结构删除
5)删除速度快

truncate table
1)属于DDL
2)不可回滚
3)不可带where
4)表内容删除
5)删除速度快

delete from
1)属于DML
2)可回滚
3)可带where
4)表结构在,表内容要看where执行的情况
5)删除速度慢,需要逐行删除

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇连接远程数据库ORACLE11g,错误百.. 下一篇Oracle08、视图+同义词+序列+索引

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目