Oracle常用语句

一。基本增删改语句

alter table table_a add (dept_name varchar2(6));
alter table table_a modify (dept_name varchar2(60));
alter table table_a drop (dept_name);
comment on column table_a.dept_name  is '部门名称';

二。oracle中修改table_a.dept_no字段类型number为varchar

--1.新增一个字段dept_no2
alter table table_a add (dept_no2 varchar2(60));
--2.将数据从dept_no赋值到dept_no2上
update table_a set dept_no2 = dept_no where id >0 and SOURCE_ID is not null
update table_a set dept_no = null where id > 0
--3.修改dept_no类型从numbervarchar
alter table table_a modify (dept_no varchar2(60));
comment on column table_a.dept_no  is '部门名称';
--4.将数据从dept_no2赋值到dept_no上
update table_a set dept_no = dept_no2 where id >0 and dept_no2 is not null
--5.删除dept_no2
alter table table_a drop (dept_no2);

三。恢复删除的数据,分为两种方法:scn和时间戳两种方法恢复。

3.1.通过scn恢复删除且已提交的数据

--1.获得当前数据库的scn号
select current_scn from v$database; --(切换到sys用户或system用户查询) 
  --查询到的scn号为:1499223

--2.查询当前scn号之前的scn
select * from 表名 as of scn 1499220; (确定删除的数据是否存在,如果存在,则恢复数据;如果不是,则继续缩小scn号)
select * from 表名 as of scn 1499220 where 还可以加条件;

--3、恢复删除且已提交的数据
flashback table 表名 to scn 1499220;

3.2、通过时间恢复删除且已提交的数据,闪回


--1.查询oracle中最近执行的语句。找到误删数据的时间(sys用户登录)
select sql_text,last_load_time from v$sql 
where sql_text like '%update%' order by last_load_time desc;

--2.切换到删除库中
begin;
alter table  表名 enable row movement;--开启闪回
flashback table  表名 to timestamp to_timestamp('2018-06-08/18:20:25','yyyy-mm-dd hh24:mi:ss');
alter table 表名 disable row movement;--关闭闪回
commit;
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值