Best way to do multi-row insert in Oracle?

前端 未结 9 1418
悲&欢浪女
悲&欢浪女 2020-11-22 02:52

I\'m looking for a good way to perform multi-row inserts into an Oracle 9 database. The following works in MySQL but doesn\'t seem to be supported in Oracle.



        
9条回答
  •  鱼传尺愫
    2020-11-22 03:27

    Whenever I need to do this I build a simple PL/SQL block with a local procedure like this:

    declare
       procedure ins
       is
          (p_exch_wh_key INTEGER, 
           p_exch_nat_key INTEGER, 
           p_exch_date DATE, exch_rate NUMBER, 
           p_from_curcy_cd VARCHAR2, 
           p_to_curcy_cd VARCHAR2, 
           p_exch_eff_date DATE, 
           p_exch_eff_end_date DATE, 
           p_exch_last_updated_date DATE);
       begin
          insert into tmp_dim_exch_rt 
          (exch_wh_key, 
           exch_nat_key, 
           exch_date, exch_rate, 
           from_curcy_cd, 
           to_curcy_cd, 
           exch_eff_date, 
           exch_eff_end_date, 
           exch_last_updated_date) 
          values
          (p_exch_wh_key, 
           p_exch_nat_key, 
           p_exch_date, exch_rate, 
           p_from_curcy_cd, 
           p_to_curcy_cd, 
           p_exch_eff_date, 
           p_exch_eff_end_date, 
           p_exch_last_updated_date);
       end;
    begin
       ins (1, 1, '28-AUG-2008', 109.49, 'USD', 'JPY', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008'),
       ins (2, 1, '28-AUG-2008', .54, 'USD', 'GBP', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008'),
       ins (3, 1, '28-AUG-2008', 1.05, 'USD', 'CAD', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008'),
       ins (4, 1, '28-AUG-2008', .68, 'USD', 'EUR', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008'),
       ins (5, 1, '28-AUG-2008', 1.16, 'USD', 'AUD', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008'),
       ins (6, 1, '28-AUG-2008', 7.81, 'USD', 'HKD', '28-AUG-2008', '28-AUG-2008', '28-AUG-2008');
    end;
    /
    

提交回复
热议问题