Oracle插入循环 - PLS-00103错误

时间:2013-05-20 16:59:10

标签: oracle plsql

我正在尝试创建一个基于循环的插入语句但是我得到了PLS-00103当遇到以下其中一项时遇到符号“文件结束”:;

脚本的要点是根据连接表中另一个字段的值从另一个表中选择所有ID,然后将这些ID插入到第二个表中,当然一次一行。

这是我到目前为止所做的,我不知道为什么会收到错误。行号指向最后一个CURRENT_DATE条目。

BEGIN
 For v_apv_cmp_id IN (
                            select distinct
                              paa.APV_CMP_ID
                            from APV_APVR paa
                            join APV_CMP pac on pac.apv_cmp_id = paa.apv_cmp_id
                            join SEC_DISPLAY ssd on ssd.app_level_id = pac.app_level_id
                            where ssd.field_table_name = 'application_name'
                        )
 LOOP
 INSERT INTO APV_APVR
        (APV_APVR_ID, APV_CMP_ID, APVR_USR_ID, ORG_USR_ACV_TS, ORG_USR_NU, LTS_UPD_USR_NU, LTS_UPD_USR_TS)
 values (
        (
          select MAX(APV_APVR_ID)+1 from APV_APVR
        )
          , v_apv_cmp_id
          , 'tssao18'
          , 'tssetac'
          , CURRENT_DATE
          , 'tssetac'
          , CURRENT_DATE
        );
 END LOOP;
END;

2 个答案:

答案 0 :(得分:1)

DECLARE
    new_id number;
BEGIN
    SELECT NVL(MAX(APV_APVR_ID),0) + 1 into new_id FROM APV_APVR;
    FOR v_apv_cmp_id IN (
                                SELECT DISTINCT
                                  paa.APV_CMP_ID
                                FROM APV_APVR paa
                                JOIN APV_CMP pac ON pac.apv_cmp_id = paa.apv_cmp_id
                                JOIN SEC_DISPLAY ssd ON ssd.app_level_id = pac.app_level_id
                                WHERE ssd.field_table_name = 'application_name'
                            )
     LOOP
         INSERT INTO APV_APVR
            (APV_APVR_ID, APV_CMP_ID, APVR_USR_ID, ORG_USR_ACV_TS, ORG_USR_NU, LTS_UPD_USR_NU, LTS_UPD_USR_TS)
     VALUES (  new_id
              , v_apv_cmp_id
              , 'tssao18'
              , 'tssetac'
              , CURRENT_DATE
              , 'tssetac'
              , CURRENT_DATE
            );
         new_id := new_id + 1;
     END LOOP;
END;

答案 1 :(得分:0)

BEGIN
 For v_apv_cmp_id IN (
                            select distinct
                              paa.APV_CMP_ID
                            from APV_APVR paa
                            join APV_CMP pac on pac.apv_cmp_id = paa.apv_cmp_id
                            join SEC_DISPLAY ssd on ssd.app_level_id = pac.app_level_id
                            where ssd.field_table_name = 'application_name'
                        )
 LOOP
 INSERT INTO APV_APVR
        (APV_APVR_ID, APV_CMP_ID, APVR_USR_ID, ORG_USR_ACV_TS, ORG_USR_NU, LTS_UPD_USR_NU, LTS_UPD_USR_TS)
 values (
        (
          select MAX(APV_APVR_ID)+1 from APV_APVR;
        )
          , v_apv_cmp_id
          , 'tssao18'
          , 'tssetac'
          , CURRENT_DATE
          , 'tssetac'
          , CURRENT_DATE
        );
 END LOOP;
END;