美文网首页
oracle 数据的找回

oracle 数据的找回

作者: 周六不算加班 | 来源:发表于2019-08-12 09:36 被阅读0次

在我们操作数据库的时候难免会更新错数据,或者删除错数据,oracle提供了一个快照功能可以回退数据。
1、查看最近正确的时间点数据

SELECT * from tableName as of timestamp to_timestamp('2019-08-09 20:05:00','yyyy-mm-dd hh24:mi:ss')

2、打开回闪功能

alter table  tableName   enable row movement;

3、回闪到对应的时间点

flashback table tableName to timestamp to_timestamp('2019-08-09 20:00:00','yyyy-mm-dd hh24:mi:ss');

回闪的时候有时候会遇到“快照太旧”回闪失败的情况。我这边提供一个不用回闪的方法来找回数据:用查看最近正确时间点数据的方法,找到正确的数据,然后导出正确的数据(最好是json格式)我们在用程序读取一下导出的数据更新一下数据库。

4、spring boot 读取json文件
4.1、jar引入

    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
        <version>1.2.35</version>
    </dependency>

4.2、程序实现

 public void  jsonData(){
    String path = "d:\\json\\test.json";
    File file = new File(path);
    String jsonData = this.jsonRead(file);
    JSONObject jsonObject = JSONObject.parseObject(jsonData);
    JSONArray array = JSONArray.parseArray(jsonObject.get("RECORDS").toString());
    for(int i=0;i<array.size();i++){
        JSONObject jsonObject2 = array.getJSONObject(i);
        Map<String,Object> map = new HashMap<>();
        map.put("id",jsonObject2.get("id"));
        map.put("value",jsonObject2.get("value"));
        qxdmsSurfGuojiaDataMonthService.updateData1(map);

}

private String jsonRead(File file){
    Scanner scanner = null;
    StringBuilder buffer = new StringBuilder();
    try {
        scanner = new Scanner(file, "utf-8");
        while (scanner.hasNextLine()) {
            buffer.append(scanner.nextLine());
        }
    } catch (Exception e) {

    } finally {
        if (scanner != null) {
            scanner.close();
        }
    }
    return buffer.toString();
}

相关文章

网友评论

      本文标题:oracle 数据的找回

      本文链接:https://www.haomeiwen.com/subject/hdcyjctx.html