Plsql 在pl/sql过程中实现水平分段表

Plsql 在pl/sql过程中实现水平分段表,plsql,procedure,Plsql,Procedure,我有两个表。服务器上的account和站点上的account1,它们具有相同的属性,但数据不同 创建表帐户 会计国际, 平衡整数, Acctype varchar220, 阿克扎尔220, 主键号 创建表ACCOUNT1 会计国际, 平衡整数, Acctype varchar220, 阿克扎尔220, 主键号 现在,我想做一个程序,使提款银行交易。用户将提供输入一个帐号,可以从帐户表或account1表和提款金额。然后,该过程将更新特定表中的余额,该表包含用户作为输入提供的帐号。 我的代码适用于

我有两个表。服务器上的account和站点上的account1,它们具有相同的属性,但数据不同

创建表帐户 会计国际, 平衡整数, Acctype varchar220, 阿克扎尔220, 主键号

创建表ACCOUNT1 会计国际, 平衡整数, Acctype varchar220, 阿克扎尔220, 主键号

现在,我想做一个程序,使提款银行交易。用户将提供输入一个帐号,可以从帐户表或account1表和提款金额。然后,该过程将更新特定表中的余额,该表包含用户作为输入提供的帐号。 我的代码适用于一个表。但无法理解如何处理两个水平分段的表Account和account1。 有谁能给我建议一个更好的解决办法吗。 这是我的程序

CREATE OR REPLACE  PROCEDURE test(x IN number, y IN number)
AS
    cur_balance number;
    new_balance number;

BEGIN
    select Balance into cur_balance
    from Account  
    where Accno = x;

if (cur_balance < y)then
    dbms_output.put_line('Insufficient balance');
else
    new_balance:=cur_balance-y;
    update Account
    set Balance = new_balance
    where Accno = x;

end if; 
    dbms_output.put_line('Money has been withdrawn successfully');
    dbms_output.put_line('Current Balance:' || new_balance);
commit;
END;
/ 
检查两个表格;如果accno在其中不存在,我假设没有找到任何数据。然后再检查另一个

下面是一个例子:

CREATE OR REPLACE  PROCEDURE test(x IN number, y IN number)
AS
    cur_balance number;
    new_balance number;
    which_table varchar2(20);
BEGIN
  begin
    select Balance 
      into cur_balance
      from Account 
      where Accno = x;

    which_table := 'account';
  exception
    when no_data_found then
      -- ACCNO wasn't found in ACCOUNT, so - check ACCOUNT1
      select balance
        into cur_balance
        from account1
        where accno = x;

      which_table := 'account1';        
  end;

  if (cur_balance < y)then
     dbms_output.put_line('Insufficient balance');
  else
     new_balance := cur_balance - y;

     if which_table = 'account' then
        update Account
          set Balance = new_balance
          where Accno = x;
     else
        update account1
          set balance = new_balance
          where accno = x;
     end if;

     dbms_output.put_line('Money has been withdrawn successfully');
     dbms_output.put_line('Current Balance:' || new_balance);

     commit;
  end if;  
END;
/ 

工作正常。感谢分享您的想法。是否可以通过在两个表之间使用并集或其他操作来找到解决方案不客气。协会您可以以某种方式获取当前余额,但关键是如何知道要更新哪个表。我想我发布的代码非常简单,易于维护,所以-我不会把它复杂化。