Oracle循环批量插入数据

Oracle循环批量插入数组数据

涉及Oracle知识点

循环、Oracle数组、变量

Oracle完整脚本

declare  
	  v_f_user_id VARCHAR2(16); 
      v_f_flow_no VARCHAR2(64) :='FN'+to_char(sysdate,'yyyyMMddHHmmss');
      v_f_type INTEGER :=5;
      v_f_account_id INTEGER ;
      v_f_last_balance NUMBER(12,4) :=1;
      v_f_amount NUMBER(12,4) :=1;
      v_f_balance NUMBER(12,4) :=1; 
      type user_array is table of varchar2(16);/*声明数组*/
      v_array user_array :=user_array('18702725261','18702725262','18702725263','18702725264','18702725265','18702725266','18702725267','18702725268','18702725269','18702725270','18702725271'); /*数组赋值*/
begin
  for i in 1..v_array.count loop
    v_f_account_id := (select f_id from t_account where f_user_id = v_f_user_id);
    for j in 1..100 loop     
      insert into t_account_flow
        (f_user_id, f_flow_no, f_type, f_description, f_account_id, f_last_balance, f_amount, f_balance)
      values
        (v_f_user_id, v_f_flow_no, v_f_type, '压测数据', v_f_account_id, v_f_last_balance+1.1, v_f_amount+2.3, v_f_balance+2.8);
    end loop;
  end loop;  
end;

/*查询当前日期的值*/
select to_char(sysdate,'yyyyMMddHHmmss') from dual;

你可能感兴趣的:(数据库)