我正在尝试更新输入日期为字符串类型
的表格 SELECT FromDate FROM MyTbl where NUM=3;
*output:*
FromDate
-------------------------
24-APR-16
UPDATE MyTbl SET FLAG='Y' WHERE FromDate=to_date(2016-04-24 00:00:00.0)
String FromDate= 2016-04-24 00:00:00.0
SQL Error: ORA-01861: literal does not match format string
01861. 00000 - "literal does not match format string"
*Cause: Literals in the input must be the same length as literals in
the format string (with the exception of leading whitespace). If the
"FX" modifier has been toggled on, the literal must match exactly,
with no extra whitespace.
*Action: Correct the format string to match the literal.
答案 0 :(得分:0)
to_date()
期望一个字符串常量,并在SQL中将字符串放入单引号中。您还需要提供格式掩码:
UPDATE MyTbl SET FLAG='Y'
WHERE FromDate=to_date('2016-04-24 00:00:00', 'yyyy-mm-dd hh24:mi:ss');
有关详细信息,请参阅手册:
答案 1 :(得分:0)
Oracle date
类型只有第二种解决方案。如果您想保留有关毫秒的信息,请考虑使用timestamp
并转换为date
:
UPDATE MyTbl
SET FLAG='Y'
WHERE FromDate = CAST(TO_TIMESTAMP('2016-04-24 00:00:00.0', 'YYYY-MM-DD HH24:MI:SS,FF1') AS DATE)
如果您确实希望保持毫秒精度,请考虑将FromDate
列更改为timestamp
。