Oracle 执行'时出错;立即执行';查询
我必须将一个表的数据插入到另一个表中。我已经为您创建了一个过程。 在过程中,一个varchar2变量 代码如下-Oracle 执行'时出错;立即执行';查询,oracle,Oracle,我必须将一个表的数据插入到另一个表中。我已经为您创建了一个过程。 在过程中,一个varchar2变量 代码如下- create or replace procedure proc_OneTimeLoad as query varchar2(5000); begin OneTimeLoad_query := 'INSERT INTO trgt_table (Originterminal, Destinationtermina
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;
在这里,我在执行此过程时遇到错误“缺少右括号”。我认为[']存在一些问题。
我想将查询中的用户“”连接到字符串。
就像争取时间一样
where time=to|u date(HH | |':'| | | | | |':':'| | | ss,'HH24:mi:ss')
请帮帮我。您的动态SQL似乎漏掉了太多。i、 e.它看起来更正确,如下所示:
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))
当你陷入困境时,你应该尽量简化你的问题。这个过程通常会为你解决问题。在本例中,当您应该使用2时,您使用了4个引号。或者,为了使事情更加简化,请使用。例如,
query:=q'!选择日期“2000-01-01”…!'代码>。另外,您应该接受前面问题的部分答案,以便让其他人知道答案是正确的。如果我只使用了“”,则会出现错误,认为这些是无效的绑定变量。@user1965381在您的sql中,我看不到使用动态sql的理由,因为您似乎根本没有更改字符串。但是你所有的引号都是加倍的,例如,| |“”:“| |
应该是|
等等。