当前位置:网站首页>oracle利用as of timestamp语句找回误删除的数据
oracle利用as of timestamp语句找回误删除的数据
2022-08-08 23:45:00 【西楚少羽】
oracleXE是oracle数据库的一个免费版本,占用内存小,适合我们学习使用。
一、安装oracle
这里我们利用docker安装oracleXE
1.搜索OracleXE镜像
docker search oracle
2.下载OracleXE镜像
docker pull oracleinanutshell/oracle-xe-11g
3.运行一个临时容器
docker run --name oracle -d -p 1521:1521 -v /data/oracle:/u01/app/oracle -e ORACLE_ALLOW_REMOTE=true oracleinanutshell/oracle-xe-11g
4.将运行容器的持久化目录复制在我们宿主机的data目录下
cp后面的oracle代表容器名称,/u01/app/oracle为容器内部目录,/data/oracle为宿主机目录
docker cp oracle:/u01/app/oracle /data/oracle
5.删除临时容器
docker stop oracle
docker rm oracle
6.重新运行容器
docker run --name oracle -d -p 1521:1521 -v /data/oracle:/u01/app/oracle -e ORACLE_ALLOW_REMOTE=true oracleinanutshell/oracle-xe-11g
7.测试连接
这里我们直接用idea连接,默认的账号是system,密码是oracle
8.创建表空间
初始大小为100m,自动拓展10m,最大为500m
--创建表空间
create tablespace adminSpace datafile '/u01/app/oracle/oradata/XE/admin.dbf' size 100M autoextend on next 10M MAXSIZE 500M;
命令执行成功后我们在服务器目录下可以看到创建的.dbf文件
9.创建用户
账号为admin,密码为admin123456,表空间为adminSpace
--创建用户test
create user admin identified by admin123456 default tablespace adminSpace;
10.授权为管理员
一定要授权,至少要有连接权限,否则账号无法登录
--授予管理员角色
grant dba to admin;
此时我们就可以用我们创建的用户登录
二、数据找回
用plsql连接,并准备一张表名为sys_user的表,初始如下数据

2.先删除ID为2的数据,手动提交事务,再执行查询语句,结果如下
3.利用时间戳查询’2022/8/5 9:10:45’这个时间点的数据
可以看到我们用delete删除的数据又能查出来了
select * from sys_user as of timestamp to_timestamp('2022/8/5 9:10:45','yyyy-mm-dd hh24:mi:ss');
这样我们就可以利用这个数据达到恢复数据的目的
insert into sys_user
(id, user_id, user_name, age, create_time)
with tab as
(select id, user_id, user_name, age, create_time
from sys_user as of timestamp to_timestamp('2022/8/5 9:10:45', 'yyyy-mm-dd hh24:mi:ss'))
select id, user_id, user_name, age, create_time
from tab t
where not exists (select 1 from sys_user x where x.id = t.id);
注意:此方式只适用于找回delete语句删除的数据,并且期间表结构不能发生改变
边栏推荐
- WeChat applet develops some function usage methods
- Learning experience of bp neural network
- 51nod2614 小B爱旅行 (参考范艺杰代码 基本抄袭 太难了)
- Get the current time before/after one day's date
- 循环神经网络实现股票预测
- 05 Spark on 读取内部数据分区存储策略(源码角度分析)
- 风控建模一:好坏标签定义
- [Tensorflow2] Some interface changes of tensorflow1.x-tensorflow2.x
- mysql 高级知识【order by 排序优化】
- Risk Control Modeling II: Modeling Scheme formulation
猜你喜欢
随机推荐
Binary tree level traversal and examples
13 Spark on RDD 全局累加器
07 Spark on RDD 血缘关系
并发编程第二篇,线程之间的通讯
使用 Gradio 在 huggingface 创建应用 Space
12 Spark on RDD 分区器
弹出PopupWindow后让背景变暗的方法
实用小技能:一键获取Harbor中镜像信息,快捷查询镜像
(newcoder 15079)无关(容斥原理)
【瑞吉外卖】day04:员工分页查询、启用/禁用员工账号、编辑员工信息
如何在Android中使用Realm数据库
Formatting of time objects
积性函数
Hand-written prometheus exporter-01-Gauge (dashboard)
域前置通信过程和溯源思路
51nod2614 小B爱旅行 (参考范艺杰代码 基本抄袭 太难了)
WeChat applet error undefined Expecting 'STRING','NUMBER','NULL','TRUE','FALSE','{','[', got ]Solution
AsyncTask的替代方案
ABP中的数据过滤器
51nod 1830









