create or replace procedure Product5() 
is
  v_ID int;  
  cursor mycursor is select ID from jfsky.Product5;
  begin
  open mycursor;
  loop
  fetch mycursor into v_ID;     
        insert into jfsky.Product4(title,ID) 
        select trim(regexp_substr(title, '[^,]+', 1, lv)) title,ID from (
        select distinct title,ID, level lv  from (
        select title,ID,length(title) - length(replace(title, ',', '')) + 1 rn  
        from JFSKY.Product5 where ID=:v_ID) connect by level <= rn ) order by title;
        commit;
  end loop;
  close mycursor;
  end Product5;
表Product5,Product4结构一样,表Product5中的title字段中“,”号,就是把这样的分行插入到Product4表中,insert ..select .....我已经测试过没问题,, where ID=:v_ID变量
过程与函数无所谓,只要实现功能,先谢过各位大侠了

解决方案 »

  1.   

    DECLARE
      CURSOR CUR_MYCURSOR IS
        SELECT ID FROM JFSKY.PRODUCT5;
    BEGIN
      FOR V_CUR IN CUR_MYCURSOR LOOP
        INSERT INTO JFSKY.PRODUCT4
          (TITLE, ID)
          SELECT TRIM(REGEXP_SUBSTR(TITLE, '[^,]+', 1, LV)) TITLE, ID
            FROM (SELECT DISTINCT TITLE, ID, LEVEL LV
                    FROM (SELECT TITLE,
                                 ID,
                                 LENGTH(TITLE) - LENGTH(REPLACE(TITLE, ',', '')) + 1 RN
                            FROM JFSKY.PRODUCT5
                           WHERE ID = V_CUR.ID)
                  CONNECT BY LEVEL <= RN)
           ORDER BY TITLE;
        COMMIT;
      END LOOP;
      CLOSE V_CURSOR;
    END;
    /不是很明白你的想法,看这样成否?
      

  2.   


    --已测试OK
    create or replace procedure Product5 --没有参数就不要括号 
    is
    begin
            for rs in (select id from product5) loop
            insert into Product4(title,ID)  
            select trim(regexp_substr(title, '[^,]+', 1, lv)) title,ID from (
            select distinct title,ID, level lv from (
            select title,ID,length(title) - length(replace(title, ',', '')) + 1 rn   
            from Product5 where ID=rs.id) connect by level <= rn ) order by title;
            commit;
        end loop;
    end Product5;