日期:2014-05-16  浏览次数:20431 次

存储过程实现表的多条记录插入
CREATE OR REPLACE PROCEDURE P_InsertSubject IS
  v_rownum      int(10);
  v_COMPANYCODE varchar2(20);
  v_COMPANYNAME varchar2(100);
  i_id          INTEGER := 1;
  CURSOR occupancy_cur IS
    SELECT COMPANYCODE, COMPANYNAME FROM Lnssc_Company_Info;

BEGIN
  SELECT max(rownum) into v_rownum FROM Lnssc_Company_Info;
  OPEN occupancy_cur;
  LOOP
 
    FETCH occupancy_cur
      INTO v_COMPANYCODE, v_COMPANYNAME;
    EXIT WHEN occupancy_cur%NOTFOUND;
    i_id     := i_id + 1;
    v_rownum := v_rownum + 1;
    insert into LNSSC_DIC_COMPANYS
      (id, DISPLAYTEXT, VALUECOL, ORDERCOL, VISABLECOL)
    values
      (v_rownum, v_COMPANYNAME, v_COMPANYCODE, i_id, i_id);
 
  END LOOP;
  commit;
  CLOSE occupancy_cur;
END;