oracle insert 语句

基于oracle数据库中自带的scott表emp

一、最基本用法

1、列出表中的所有字段及每个字段对应的值
insert into emp(empno,ename,job,mgr,hiredate,sal,comm,deptno)
values(7333,'GEJUN','CLERK',7999,to_date('1980/12/17','yyyy-mm-dd'),900,200,10);

2、按表中字段顺序给出字段值
insert into emp values(7333,'GEJUN','CLERK',7999,to_date('1980/12/17','yyyy-mm-dd'),900,200,10);

[img]http://dl2.iteye.com/upload/attachment/0096/6975/94971158-273e-3c25-8d53-b0cda1560719.png[/img]


二、insert into select

我的测试步骤是:
1.删除表中部门编号是7369的员工
delete emp where empno=7369;

[img]http://dl2.iteye.com/upload/attachment/0096/6979/1a35062a-b0b9-3e0d-82cf-2598501b2e94.png[/img]


2.查询出删除的数据
select * from emp as of timpstamp sysdate-1/12
where not exists(select 1 from emp e where emp.empno=e.empno);

[img]http://dl2.iteye.com/upload/attachment/0096/6981/159f5cd6-ba09-32c2-8e7e-ee1d22b0894c.png[/img]

3.将删除的数据再次插入到表中
insert into emp(
select * from emp as of timpstamp sysdate-1/12
where not exists(select 1 from emp e where emp.empno=e.empno));

[img]http://dl2.iteye.com/upload/attachment/0096/6983/ca4ecf83-69e3-31b2-9042-63039a0f91a7.png[/img]

三、insert into with

我的测试步骤是:
1.删除表中部门编号是7369的员工
delete emp where empno=7369;

[img]http://dl2.iteye.com/upload/attachment/0096/6979/1a35062a-b0b9-3e0d-82cf-2598501b2e94.png[/img]


2.查询出删除的数据
select * from emp as of timpstamp sysdate-1/12
where not exists(select 1 from emp e where emp.empno=e.empno);

[img]http://dl2.iteye.com/upload/attachment/0096/6981/159f5cd6-ba09-32c2-8e7e-ee1d22b0894c.png[/img]

3.将删除的数据再次插入到表中
insert into emp
with a as (select * from emp as of timestamp sysdate-1/12 where not exists(select 1 from emp e where emp.empno=e.empno))
select * from a;

[img]http://dl2.iteye.com/upload/attachment/0096/6985/49e6d71f-0f3a-3299-ae7a-2d0583ffdee5.png[/img]

[color=red]值得注意的是第二和第三种方案的比较,insert into select 时要目标表后紧跟括号,而用with as(临时表)时,insert into emp后是不带括号的。(另外提一点,with as语句后要紧跟select 语句。)[/color]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值