恢复误删的gl_balances表中数据

本文介绍了一种在Oracle数据库中恢复被误删数据的方法。通过创建临时表并利用已有的日记账信息,重新构建了被删除的数据记录。此过程分为两部分:一是恢复已生成日记账的数据;二是补充未生成日记账的部分。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    同事没有注意把gl_balances表中的数据删除了,然后对日记账进行了过账,导致镜像被覆盖,数据无法恢复,为了防止后期出错,就需要手动恢复被删除的数据。

下面是个人写的代码,还有很多需要优化的地方,但是鉴于还有很多工作量就先往后放放吧,哈哈哈。

declare
  -- --4,7,10月 季度发生额为当月发生额
  -- Local variables here
  --create table cux_test as select * from gl_balances;
  l_b_period_name varchar2(20) := '2018-10';
  l_period_name   varchar2(20) := '2018-11';
begin
  -- Test statements here
  --更新当月生成了日记账的内容
insert into cux_test
(ledger_id,
 code_combination_id,
 currency_code,
 period_name,
 actual_flag,
 last_update_date,
 last_updated_by,
 period_type,
 period_year,
 period_num,
 period_net_dr,
 period_net_cr,
 quarter_to_date_dr,
 quarter_to_date_cr,
 project_to_date_dr,
 project_to_date_cr,
 begin_balance_dr,
 begin_balance_cr,
 period_net_dr_beq,
 period_net_cr_beq,
 begin_balance_dr_beq,
 begin_balance_cr_beq,
 quarter_to_date_dr_beq,
 quarter_to_date_cr_beq,
 project_to_date_dr_beq,
 project_to_date_cr_beq)
select l.ledger_id,
       l.code_combination_id,
       l.currency_code,
       l.period_name,
       l.actual_flag,
       sysdate,
       fnd_global.user_id,
       '41',
       to_number(substr(l_period_name, 1, 4)),
       to_number(substr(l_period_name, 6, 2)),
       nvl(l.entered_dr, 0), --借方发生(原)
       nvl(l.entered_cr, 0), --贷方发生(原)
       nvl(gb.quarter_to_date_dr, 0) + nvl(l.entered_dr, 0),
       nvl(gb.quarter_to_date_cr, 0) + nvl(l.entered_cr, 0),
     /*  nvl(l.entered_dr, 0), --季初贷方(当月发生额)
       nvl(l.entered_cr, 0), --季初借方(当月发生额) */
       nvl(gb.project_to_date_dr, 0) + nvl(l.entered_cr, 0),
       nvl(gb.project_to_date_cr, 0) + nvl(l.entered_cr, 0),
       nvl(gb.period_net_dr, 0) + nvl(gb.begin_balance_dr, 0), --三月份期初借方(原)
       nvl(gb.period_net_cr, 0) + nvl(gb.begin_balance_cr, 0), --期初贷方(原)
       nvl(l.accounted_dr, 0), --借方(本)
       nvl(l.accounted_cr, 0), --贷方(本)
       nvl(gb.period_net_dr_beq, 0) + nvl(gb.begin_balance_dr_beq, 0), --期初借方(本)
       nvl(gb.period_net_cr_beq, 0) + nvl(gb.begin_balance_cr_beq, 0), --期初贷方(本)
       nvl(gb.quarter_to_date_dr_beq, 0) + nvl(l.accounted_dr, 0), --季度借方
       nvl(gb.quarter_to_date_cr_beq, 0) + nvl(l.accounted_cr, 0), --季度贷方
     /*  nvl(l.accounted_dr, 0),  --季初贷方(当月发生额)
       nvl(l.accounted_cr, 0),  --季初借方(当月发生额)*/
       nvl(gb.project_to_date_dr_beq, 0) + nvl(l.accounted_dr, 0), --项目借方
       nvl(gb.project_to_date_cr_beq, 0) + nvl(l.accounted_cr, 0) --项目贷方
  from (select jl.ledger_id,
               jl.code_combination_id,
               h.currency_code,
               jl.period_name,
               h.actual_flag,
               sum(nvl(jl.entered_dr, 0)) entered_dr,
               sum(nvl(jl.entered_cr, 0)) entered_cr,
               sum(nvl(jl.accounted_dr, 0)) accounted_dr,
               sum(nvl(jl.accounted_cr, 0)) accounted_cr
          from gl_je_lines jl, gl_je_headers h
         where jl.je_header_id = h.je_header_id
           and jl.period_name = l_period_name
           and jl.status = 'P'
           and jl.ledger_id = 2082
           and h.actual_flag = 'A'
         group by jl.ledger_id,
                  jl.code_combination_id,
                  h.currency_code,
                  jl.period_name,
                  h.actual_flag) l,
       (select *
          from gl_balances b
         where b.period_name = l_b_period_name) gb
 where l.code_combination_id = gb.code_combination_id(+)
   and l.currency_code = gb.currency_code(+);
   
   --更新当月未生成日记账的内容
insert into cux_test
(ledger_id,
 code_combination_id,
 currency_code,
 period_name,
 actual_flag,
 last_update_date,
 last_updated_by,
 period_type,
 period_year,
 period_num,
 period_net_dr,
 period_net_cr,
 quarter_to_date_dr,
 quarter_to_date_cr,
 project_to_date_dr,
 project_to_date_cr,
 begin_balance_dr,
 begin_balance_cr,
 period_net_dr_beq,
 period_net_cr_beq,
 begin_balance_dr_beq,
 begin_balance_cr_beq,
 quarter_to_date_dr_beq,
 quarter_to_date_cr_beq,
 project_to_date_dr_beq,
 project_to_date_cr_beq)
select ledger_id,
       code_combination_id,
       currency_code,
       l_period_name,
       actual_flag,
       sysdate,
       fnd_global.user_id,
       period_type,
       period_year,
       period_num + 1,
       0, --借方发生(原)
       0, --贷方发生(原)
       quarter_to_date_dr,
       quarter_to_date_cr,
      /*  0,
       0,*/
       project_to_date_dr,
       project_to_date_cr,
       nvl(period_net_dr, 0) + nvl(begin_balance_dr, 0), --期初借方(原)
       nvl(period_net_cr, 0) + nvl(begin_balance_cr, 0), --期初贷方(原)
       0, --借方(本)
       0, --贷方(本)
       nvl(period_net_dr_beq, 0) + nvl(begin_balance_dr_beq, 0), --期初借方(本)
       nvl(period_net_cr_beq, 0) + nvl(begin_balance_cr_beq, 0), --期初贷方(本)
       quarter_to_date_dr_beq, --季度借方
       quarter_to_date_cr_beq, --季度贷方
      /* 0,
       0,*/
       project_to_date_dr_beq, --项目借方
       project_to_date_cr_beq --项目贷方
  from (select *
          from cux_test b
         where b.period_name = l_b_period_name
           and b.ledger_id = 2082) gb1
 where gb1.code_combination_id not in
       (select gb.code_combination_id
          from cux_test gb, cux_test c
         where gb.code_combination_id = c.code_combination_id
           and gb.period_name = l_b_period_name
           and c.period_name = l_period_name);
commit;
end;

/ SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract TokenTrade { // 代币元数据 string public constant name = "TradeToken"; string public constant symbol = "TRADE"; uint8 public constant decimals = 18; uint256 public totalSupply; // 余额映射 mapping(address => uint256) private _balances; // 授权映射(owner => (spender => amount)) mapping(address => mapping(address => uint256)) private _allowances; // 事件定义 event Transfer(address indexed from, address indexed to, uint256 value); event Approval(address indexed owner, address indexed spender, uint256 value); // 构造函数:初始化供应量 constructor(uint256 initialSupply) { totalSupply = initialSupply * 10 ** decimals; _balances[msg.sender] = totalSupply; emit Transfer(address(0), msg.sender, totalSupply); } // 查询余额 function balanceOf(address account) public view returns (uint256) { return _balances[account]; } // 代币转账 function transfer(address to, uint256 amount) public returns (bool) { require(to != address(0), "Invalid recipient"); require(_balances[msg.sender] >= amount, "Insufficient balance"); _balances[msg.sender] -= amount; _balances[to] += amount; emit Transfer(msg.sender, to, amount); return true; } // 授权额度 function approve(address spender, uint256 amount) public returns (bool) { _allowances[msg.sender][spender] = amount; emit Approval(msg.sender, spender, amount); return true; } // 查询授权额度 function allowance(address owner, address spender) public view returns (uint256) { return _allowances[owner][spender]; } // 委托转账(使用他人授权额度) function transferFrom( address from, address to, uint256 amount ) public returns (bool) { require(to != address(0), "Invalid recipient"); require(_balances[from] >= amount, "Insufficient balance"); require(_allowances[from][msg.sender] >= amount, "Allowance exceeded"); _balances[from] -= amount; _balances[to] += amount; _allowances[from][msg.sender] -= amount; emit Transfer(from, to, amount); return true; } // 铸币功能(仅合约所有者) function mint(address account, uint256 amount) public { require(account != address(0), "Mint to zero address"); totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); } // 销毁代币 function burn(uint256 amount) public { require(_balances[msg.sender] >= amount, "Insufficient balance"); _balances[msg.sender] -= amount; totalSupply -= amount; emit Transfer(msg.sender, address(0), amount); } }
最新发布
06-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值