0

あるテーブルのデータを別のテーブルに挿入する必要があります。のプロシージャを作成しました。手順1のvarchar2変数コードは以下のとおりです-

create or replace procedure proc_OneTimeLoad

 as
  query varchar2(5000);

begin

  OneTimeLoad_query := 'INSERT INTO trgt_table
              (Originterminal,
               Destinationterminal,
               Scheduledepartdate,
               Scheduledeparttime,
               Runtypenbr,
               DOW,
               Sched_Slip_Arr_Tm,
               DAY,
               Sched_Arr_Tm,
               Drivercode,
               Puprunflag,
               Sched_Cd,
               Status_Cd)

             SELECT Orgn_Term_Cd,
   Dest_Term_Cd,
   sysdate,
   Sched_Dep_Tm,
   Run_Nbr,
   DOW,
   to_date(
   LPAD(nvl(substr(tn.Sched_Slip_Arr_Tm,1,length(Sched_Slip_Arr_Tm)- 2),0),2,0)
   ||'''':''''||
   RPAD(nvl(TRUNC(TO_NUMBER(substr(Sched_Slip_Arr_Tm,3,length(Sched_Slip_Arr_Tm) - 2)) * .60,0),0),2,0)      
   ||'''':00''''
   ,''''HH24:MI:SS'''')
   as Sched_Slip_Arr_Tm,
   Day,
   to_date(
   LPAD(nvl(substr(tn.sched_arr_tm,1,length(sched_arr_tm)- 2),0),2,0)
   ||'''':''''||
   RPAD(nvl(TRUNC(TO_NUMBER(substr(sched_arr_tm,3,length(sched_arr_tm) - 2)) * .60,0),0),2,0)      
   ||'''':00''''
   ,''''HH24:MI:SS'''') 
   as Sched_Arr_Tm,
   Drvr_Cd,
   Pup_Run_Flg,
   ''''B'''',
   ''''1P''''
FROM src_table tn
WHERE tn.dow = to_char(sysdate - 1, ''''D'''')
AND tn.sched_dep_tm between
       TO_NUMBER(SUBSTR(TO_CHAR(sysdate, ''''HH24:MI:SS''''), 1, 2) ||
                 TRUNC(SUBSTR(TO_CHAR(sysdate, ''''HH24:MI:SS''''), 4, 2) * 100/60,0)) 
  AND
       TO_NUMBER(TO_NUMBER(SUBSTR(TO_CHAR(sysdate, ''''HH24:MI:SS''''), 1, 2)) + 12 ||
                 TRUNC(SUBSTR(TO_CHAR(sysdate, '''' HH24 :MI :SS ''''), 4, 2) * 100 / 60, 0))';

  execute immediate query;


  dbms_output.put_line(' Data loaded successfully');

end;

ここで、この手順の実行中にエラーが発生します'右括弧がありません。[']の問題があると思います。文字列を連結するためにクエリで''を使用したい。時間を稼ぐのと同じように

ここで、time = to_date(HH ||':' || mi ||':' || ss、'' HH24:MI:SS')

誰か助けてください。

4

1 に答える 1

2

動的 SQL がエスケープされすぎているようです。つまり、次のようにより正確に見えます。

   OneTimeLoad_query := 'INSERT INTO trgt_table
               (Originterminal,
                Destinationterminal,
                Scheduledepartdate,
                Scheduledeparttime,
                Runtypenbr,
                DOW,
                Sched_Slip_Arr_Tm,
                DAY,
                Sched_Arr_Tm,
                Drivercode,
                Puprunflag,
                Sched_Cd,
                Status_Cd)    
              SELECT Orgn_Term_Cd,
    Dest_Term_Cd,
    sysdate,
    Sched_Dep_Tm,
    Run_Nbr,
    DOW,
    to_date(
    LPAD(nvl(substr(tn.Sched_Slip_Arr_Tm,1,length(Sched_Slip_Arr_Tm)- 2),0),2,0)
    ||'':''||
    RPAD(nvl(TRUNC(TO_NUMBER(substr(Sched_Slip_Arr_Tm,3,length(Sched_Slip_Arr_Tm) - 2)) * .60,0),0),2,0)
    ||'':00''
    ,''HH24:MI:SS'')
    as Sched_Slip_Arr_Tm,
    Day,
    to_date(
    LPAD(nvl(substr(tn.sched_arr_tm,1,length(sched_arr_tm)- 2),0),2,0)
    ||'':''||
    RPAD(nvl(TRUNC(TO_NUMBER(substr(sched_arr_tm,3,length(sched_arr_tm) - 2)) * .60,0),0),2,0)
    ||'':00''
    ,''HH24:MI:SS'')
    as Sched_Arr_Tm,
    Drvr_Cd,
    Pup_Run_Flg,
    ''B'',
    ''1P''
 FROM src_table tn
 WHERE tn.dow = to_char(sysdate - 1, ''D'')
 AND tn.sched_dep_tm between
        TO_NUMBER(SUBSTR(TO_CHAR(sysdate, ''HH24:MI:SS''), 1, 2) ||
                  TRUNC(SUBSTR(TO_CHAR(sysdate, ''HH24:MI:SS''), 4, 2) * 100/60,0))
   AND
        TO_NUMBER(TO_NUMBER(SUBSTR(TO_CHAR(sysdate, ''HH24:MI:SS''), 1, 2)) + 12 ||
                  TRUNC(SUBSTR(TO_CHAR(sysdate, ''HH24:MI:SS ''), 4, 2) * 100 / 60, 0))';

   execute immediate OneTimeLoad_query;

あなたの例では、SQLを動的に構築していないため、ここで静的SQLが使用されない理由がわかりません。つまり、なぜあなたはただ発砲しないのですか:

INSERT INTO trgt_table
              (Originterminal,
               Destinationterminal,
               Scheduledepartdate,
               Scheduledeparttime,
               Runtypenbr,
               DOW,
               Sched_Slip_Arr_Tm,
               DAY,
               Sched_Arr_Tm,
               Drivercode,
               Puprunflag,
               Sched_Cd,
               Status_Cd)
             SELECT Orgn_Term_Cd,
   Dest_Term_Cd,
   sysdate,
   Sched_Dep_Tm,
   Run_Nbr,
   DOW,
   to_date(
   LPAD(nvl(substr(tn.Sched_Slip_Arr_Tm,1,length(Sched_Slip_Arr_Tm)- 2),0),2,0)
   ||':'||
   RPAD(nvl(TRUNC(TO_NUMBER(substr(Sched_Slip_Arr_Tm,3,length(Sched_Slip_Arr_Tm) - 2)) * .60,0),0),2,0)
   ||':00'
   ,'HH24:MI:SS')
   as Sched_Slip_Arr_Tm,
   Day,
   to_date(
   LPAD(nvl(substr(tn.sched_arr_tm,1,length(sched_arr_tm)- 2),0),2,0)
   ||':'||
   RPAD(nvl(TRUNC(TO_NUMBER(substr(sched_arr_tm,3,length(sched_arr_tm) - 2)) * .60,0),0),2,0)
   ||':00'
   ,'HH24:MI:SS')
   as Sched_Arr_Tm,
   Drvr_Cd,
   Pup_Run_Flg,
   'B',
   '1P'
FROM src_table tn
WHERE tn.dow = to_char(sysdate - 1, 'D')
AND tn.sched_dep_tm between
       TO_NUMBER(SUBSTR(TO_CHAR(sysdate, 'HH24:MI:SS'), 1, 2) ||
                 TRUNC(SUBSTR(TO_CHAR(sysdate, 'HH24:MI:SS'), 4, 2) * 100/60,0))
  AND
       TO_NUMBER(TO_NUMBER(SUBSTR(TO_CHAR(sysdate, 'HH24:MI:SS'), 1, 2)) + 12 ||
                 TRUNC(SUBSTR(TO_CHAR(sysdate, 'HH24:MI:SS '), 4, 2) * 100 / 60, 0))
于 2013-02-01T08:06:34.630 に答える