我有一个将某些输入参数作为日期的过程。 当我尝试执行SP时,这是分配给每个参数的值
但是,当我执行时,在p_schedule_value参数上收到有关日期格式的错误消息。实际上,我们可以看到它没有以指定的格式传递日期。相反,它会截断时间并将其作为yyyy-MMM-dd传递 您可以在下面的屏幕截图中看到带有错误消息和p_schedule_value值的输出中的dynamic_sql
为什么我的时间被截断了?似乎它忽略了TO_DATE转换 谢谢
答案 0 :(得分:1)
在“ insert_or_upd .....”过程中,参数p_schedule_value已经是一个DATE,因此请删除merge语句中的TO_DATE。
最新答案
似乎立即执行将以varchar2的形式传递日期,因此最好以日期格式明确。
plsql_block :=
'merge into MOVEMENTS m
using (select :id as movement_id, '||q'"to_date(:dt,'YYYYMMDDHH24MI')"'||' as movement_date from dual) s
on (m.MOVEMENT_ID = s.movement_id and m.MOVEMENT_DATE = s.movement_date)
when matched then update set ' ||'colname'||q'" = to_date('"'||to_char(sysdate,'YYYYMMDDHH24MI')||q'"','YYYYMMDDHH24MI')
when not matched then insert (MOVEMENT_ID, MOVEMENT_DATE,MOVEMENT_ETD)
(:id,:dt,to_date(:value1,'YYYYMMDDHH24MI'))"' from dual;
execute immediate plsql_block USING (...... ,to_char(p_mvt_date,'YYYYMMDDHH24MI'),to_char(p_schedule_value,'YYYYMMDDHH24MI'));
您执行的语句将如下所示。
"merge into MOVEMENTS m
using (select :id as movement_id, to_date(:dt,'YYYYMMDDHH24MI') as movement_date from dual) s
on (m.MOVEMENT_ID = s.movement_id and m.MOVEMENT_DATE = s.movement_date)
when matched then update set colname = to_date('201903151837','YYYYMMDDHH24MI')
when not matched then insert (MOVEMENT_ID, MOVEMENT_DATE,MOVEMENT_ETD)
(:id,:dt,to_date(:value1,'YYYYMMDDHH24MI'))"