简体   繁体   English

ORA-01858: 在需要数字的地方发现了一个非数字字符(时间戳、解码)

[英]ORA-01858: a non-numeric character was found where a numeric was expected (timestamp, decode)

I'm getting this error ORA-01858: a non-numeric character was found where a numeric was expected .我收到此错误ORA-01858: a non-numeric character was found where a numeric was expected If I remove the second line in my code I don't get the error, so I'm wondering if the issue has something to do with the DECODE or datatype of the TIME_P variable, which is timestamp.如果我删除代码中的第二行,我不会收到错误消息,所以我想知道问题是否与 TIME_P 变量的 DECODE 或数据类型(即时间戳)有关。

TRUNC(TIME_P) >= TO_DATE('2009-01-01', 'YYYY-MM-DD') AND
TIME_P <= DECODE('2010-01-01', NOW, SYSDATE, TO_DATE('YYYY-MM-DD'))

Could I suggest something like this instead?我可以建议这样的东西吗?

TIME_P >= DATE '2009-01-01' AND
TIME_P < (CASE WHEN NOW = '2010-01-01' THEN DATE '2010-01-01' ELSE SYSDATE END)

This uses date literals, case instead of decode() ( case is standard SQL).这使用日期文字, case而不是decode()case是标准 SQL)。 The initial trunc() is redundant, as well.最初的trunc()也是多余的。

The second line doesn't really make sense to me.第二行对我来说真的没有意义。 If you just want dates that are not in the future, then:如果您只想要不在未来的日期,那么:

TIME_P >= DATE '2009-01-01' AND
TIME_P < sysdate

Or if you want to pass in a parameter and use that instead of sysdate:或者,如果您想传入一个参数并使用它而不是 sysdate:

TIME_P >= DATE '2009-01-01' AND
TIME_P < COALESCE(:parameter, sysdate)

This is what you are asking for I believe:这就是你所要求的,我相信:

DECODE(YOUR_FIRST_PARAMETER_HER, '2010-01-01', SYSDATE, TO_DATE(TRUNC(TIME_P), 'DD-MON-YYYY'))

AS you have mentioned "First arg is optional param" so I have entered the "YOUR_FIRST_PARAMETER_HER" expresion just to note to you that you will put it there.正如您提到的“第一个 arg 是可选参数”,所以我输入了“YOUR_FIRST_PARAMETER_HER”表达式只是为了提醒您,您将把它放在那里。

Your error was occurring because of the format you have entered ('YYYY-MM-DD') because the correct format is 'DD-MON-YYYY' Also, before converting you will need to trunc that timestamp value...您的错误是由于您输入的格式('YYYY-MM-DD')而发生的,因为正确的格式是'DD-MON-YYYY'此外,在转换之前,您需要截断该时间戳值......

Here you can see the errors that will occur if you do not use the right format and if you do not use trunc: https://dbfiddle.uk/?rdbms=oracle_18&fiddle=83cca74815a323bc72283adeb7396617在这里您可以看到如果您不使用正确的格式并且不使用 trunc 会出现的错误: https://dbfiddle.uk/?rdbms=oracle_18&fiddle=83cca74815a323bc72283adeb7396617

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ORA-01858:在期望数字的地方找到了非数字字符? - ORA-01858: a non-numeric character was found where a numeric was expected? 可能的日期分配错误ORA-01858:在期望数字的位置找到了非数字字符 - Possible Date assignment error ORA-01858: a non-numeric character was found where a numeric was expected ORA-01858: 在需要数字的地方发现了一个非数字字符 - ORA-01858: a non-numeric character was found where a numeric was expected ORA-01858:找到一个非数字字符,其中数字是预期的? 即使数值是数字? - ORA-01858: a non-numeric character was found where a numeric was expected? Even when the values are numbers? ORA-01858: 在一个简单的选择查询需要数字的地方发现了一个非数字字符 - ORA-01858: a non-numeric character was found where a numeric was expected for a simple select query ORA-01858:找到一个非数字字符,其中数字是预期的 - oracle 10g - ORA-01858: a non-numeric character was found where a numeric was expected - oracle 10g .NET ORA-01858:找到了一个非数字字符,其中包含数字 - .NET ORA-01858: a non-numeric character was found where a numeric was expected 错误 ORA-01858:在运行查询时应为数字的位置发现了非数字字符 - Error ORA-01858: a non-numeric character was found where a numeric was expected when running query 看到 ORA-01858:在需要数字的地方发现了一个非数字字符 - Seeing ORA-01858: a non-numeric character was found where a numeric was expected ORA-01858:找到非数字字符并期望输入数字 - ORA-01858: a non-numeric character found where a digit was expected
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM