保留写入的“sql语句忽略”和“值不足”

h5qlskok  于 2021-07-24  发布在  Java
关注(0)|答案(2)|浏览(255)

这是我的密码:

declare
    cursor c1 is
        select * from PUTRAJAYA.STRATA_PJ_BORANG4
            WHERE HM_DETAIL_NOHMDETAIL is NOT NULL;

      err_num   number;
        err_msg   varchar2(250);

      begin
    for c1rec in c1 loop

  BEGIN
                insert into ET_MAIN_WPPJ_JOZRIN.IND_HKMLK
                        (HKMLK_ID, CREATED_BY, CREATED_DATE, LAST_MODIFIED_BY, LAST_MODIFIED_DATE, VERSION, 
            ID_HAKMILIK,NO_HAKMILIK, NO_BANGUNAN,NO_TINGKAT,NO_PETAK,UPI,FLAG_GANTUNG,
            FLAG_TUKARGANTI,TARIKH_KUTIPAN_ETANAH
                        )
                values (
                        SEQ_HKMLK.NEXTVAL,'DMS', SYSDATE, 'DMS', SYSDATE,'0', 
            (select substr(HM_DETAIL_NOHMDETAIL,1,17),
            substr(HM_DETAIL_NOHMDETAIL,-8) from strata_PJ_BORANG4),
          --  substr(STRATA_PJ_BORANG4.HM_DETAIL_NOHMDETAIL,1,17),
          --  substr(STRATA_PJ_BORANG4.HM_DETAIL_NOHMDETAIL,-8),
            (SELECT 
            HM_DETAIL_NOBGN,
            HM_DETAIL_NOTKT, 
            HM_DETAIL_NOPETAK,
            HM_DETAIL_NOHMDETAIL,
            'N','N',
            HM_DETAIL_PUNGUT_DATETIME
            FROM STRATA_PJ_BORANG1 A, STRATA_PJ_BORANG4 B
            WHERE A.DAF_HM_NOFAIL = B.HM_DETAIL_NOFAIL));

        END;
END LOOP;
END;

以下是错误:
错误报告-ora-06550:第18行第5列:pl/sql:ora-00947:值不足ora-06550:第13行第5列:pl/sql:sql语句忽略06550。00000-“行%s,列%s:\n%s”*原因:通常是pl/sql编译错误。

44u64gxh

44u64gxh1#

首先让我们试着理解错误“值不够”的含义。它表明,对于insert into claues中的某些列,values子句中没有提供值。在您的例子中,insert into有15列,而values子句只有8个值。我已经在value子句中重新编写了您的子查询。请尝试执行这个,看看这是否适合你。

declare
    cursor c1 is
        select * from PUTRAJAYA.STRATA_PJ_BORANG4
            WHERE HM_DETAIL_NOHMDETAIL is NOT NULL;

      err_num   number;
        err_msg   varchar2(250);

      begin
    for c1rec in c1 loop

  BEGIN
                insert into ET_MAIN_WPPJ_JOZRIN.IND_HKMLK (
                HKMLK_ID, 
                CREATED_BY, 
                CREATED_DATE, 
                LAST_MODIFIED_BY, 
                LAST_MODIFIED_DATE, 
                VERSION, 
                ID_HAKMILIK,
                NO_HAKMILIK, 
                NO_BANGUNAN,
                NO_TINGKAT,
                NO_PETAK,
                UPI,
                FLAG_GANTUNG,
                FLAG_TUKARGANTI,
                TARIKH_KUTIPAN_ETANAH
                )
                values (
               SEQ_HKMLK.NEXTVAL,
               'DMS', 
               SYSDATE, 
               'DMS', 
               SYSDATE,
               '0', 
            (select substr(HM_DETAIL_NOHMDETAIL,1,17) from strata_PJ_BORANG4),
            (select substr(HM_DETAIL_NOHMDETAIL,-8) from strata_PJ_BORANG4),
          --  substr(STRATA_PJ_BORANG4.HM_DETAIL_NOHMDETAIL,1,17),
          --  substr(STRATA_PJ_BORANG4.HM_DETAIL_NOHMDETAIL,-8),
            (SELECT HM_DETAIL_NOBGN FROM STRATA_PJ_BORANG1 A, STRATA_PJ_BORANG4 B WHERE A.DAF_HM_NOFAIL = B.HM_DETAIL_NOFAIL),
            (SELECT HM_DETAIL_NOTKT FROM STRATA_PJ_BORANG1 A, STRATA_PJ_BORANG4 B WHERE A.DAF_HM_NOFAIL = B.HM_DETAIL_NOFAIL),
            (SELECT HM_DETAIL_NOPETAK FROM STRATA_PJ_BORANG1 A, STRATA_PJ_BORANG4 B WHERE A.DAF_HM_NOFAIL = B.HM_DETAIL_NOFAIL),
            (SELECT HM_DETAIL_NOHMDETAIL FROM STRATA_PJ_BORANG1 A, STRATA_PJ_BORANG4 B WHERE A.DAF_HM_NOFAIL = B.HM_DETAIL_NOFAIL),
            'N',
            'N',
            SELECT HM_DETAIL_PUNGUT_DATETIME FROM STRATA_PJ_BORANG1 A, STRATA_PJ_BORANG4 B WHERE A.DAF_HM_NOFAIL = B.HM_DETAIL_NOFAIL),

        );

        END;
END LOOP;
END;
1hdlvixo

1hdlvixo2#

与要插入的列数相比,在代码中没有提供足够的值。这是因为子选择用于一列,而不是多列。我把你的陈述改写成了一个没有循环的插入。我使用cte(公共表表达式)将逻辑放在一个位置:

insert into ET_MAIN_WPPJ_JOZRIN.IND_HKMLK
(HKMLK_ID, CREATED_BY, CREATED_DATE, LAST_MODIFIED_BY, LAST_MODIFIED_DATE, VERSION, 
            ID_HAKMILIK,NO_HAKMILIK, NO_BANGUNAN,NO_TINGKAT,NO_PETAK,UPI,FLAG_GANTUNG,
            FLAG_TUKARGANTI,TARIKH_KUTIPAN_ETANAH
)
with borang4_data as
(
select 
   SEQ_HKMLK.NEXTVAL                           HKMLK_ID,
   'DMS'                                       CREATED_BY,
   SYSDATE                                     CREATED_DATE,
   'DMS'                                       LAST_MODIFIED_BY,
   SYSDATE                                     LAST_MODIFIED_DATE,
   '0'                                         VERSION,

   substr(borang4.HM_DETAIL_NOHMDETAIL, 1, 17) ID_HAKMILIK,
   substr(borang4.HM_DETAIL_NOHMDETAIL, -8)    NO_HAKMILIK,

   borang1.NO_BANGUNAN                         NO_BANGUNAN,
   borang1.NO_TINGKAT                          NO_TINGKAT,
   borang1.NO_PETAK                            NO_PETAK,
   borang1.UPI                                 UPI,
   borang1.FLAG_GANTUNG                        FLAG_GANTUNG,
   borang1.FLAG_TUKARGANTI                     FLAG_TUKARGANTI,
   borang1.TARIKH_KUTIPAN_ETANAH               TARIKH_KUTIPAN_ETANAH          

from PUTRAJAYA.STRATA_PJ_BORANG4 borang4

left join
   (SELECT HM_DETAIL_NOBGN                     NO_BANGUNAN,
           HM_DETAIL_NOTKT                     NO_TINGKAT,
           HM_DETAIL_NOPETAK                   NO_PETAK,
           HM_DETAIL_NOHMDETAIL                UPI,
           'N'                                 FLAG_GANTUNG,
           'N'                                 FLAG_TUKARGANTI,
           HM_DETAIL_PUNGUT_DATETIME           TARIKH_KUTIPAN_ETANAH
      FROM STRATA_PJ_BORANG1) borang1
on borang1.DAF_HM_NOFAIL = borang4.HM_DETAIL_NOFAIL

WHERE borang4.HM_DETAIL_NOHMDETAIL is NOT NULL
)
select * from borang4_data;

我做了一些关于连接的假设,看看你的代码。请确认这是否适合你。

相关问题