简体   繁体   English

ORA-01858: 在需要数字的地方发现了一个非数字字符

[英]ORA-01858: a non-numeric character was found where a numeric was expected

I am beginner in oracle and need help regarding following query:我是 oracle 的初学者,需要有关以下查询的帮助:

select admin_id, to_date(date_created, 'DD-MM-YYYY'), name, mobile, email, (select status from status where status.status_id = admin.status_id) from admin;

Here are my tables:这是我的表:

SQL> desc admin
 Name                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 ADMIN_ID                  NOT NULL NUMBER(5)
 STATUS_ID                 NOT NULL NUMBER(5)
 DATE_CREATED                       TIMESTAMP(6)
 STATUS_DATE                        DATE
 NAME                           VARCHAR2(45)
 MOBILE                         VARCHAR2(20)
 EMAIL                          VARCHAR2(110)

SQL> desc status
 Name                      Null?    Type
 ----------------------------------------- -------- ----------------------------
 STATUS_ID                 NOT NULL NUMBER(5)
 STATUS                         VARCHAR2(36)

The main problem is I want to get status.status on basis of admin.status_id.主要问题是我想根据 admin.status_id 获取 status.status。 The date could be fixed by using it as char to_char(date_created,'DD/MM/YYYY')日期可以通过将其用作 char to_char(date_created,'DD/MM/YYYY')来固定

to_date(date_created, 'DD-MM-YYYY') doesn't make a whole lot of sense. to_date(date_created, 'DD-MM-YYYY')没有多大意义。

  • date_created is a timestamp with 6 decimal digits of sub-second precision. date_created是具有亚秒精度的 6 位十进制数字的timestamp
  • to_date takes a string. to_date接受一个字符串。 So Oracle has to first convert the timestamp to a string using the session's nls_timestamp_format .所以 Oracle 必须首先使用会话的nls_timestamp_format将时间戳转换为字符串。 That is the string that gets sent to to_date .那是发送到to_date的字符串。
  • to_date then tries to convert that string back to a date (which will always have a time component) using the "DD-MM-YYYY" format mask. to_date然后尝试使用“DD-MM-YYYY”格式掩码将该字符串转换回date (始终具有时间组件)。 Unless that happens to be what your nls_timestamp_format is set to, that conversion will fail and will probably throw the error you reported.除非这恰好是您的nls_timestamp_format设置的内容,否则该转换将失败并且可能会抛出您报告的错误。

If all this casting worked, you'd end up sending the Java application a date that has the time set to midnight.如果所有这些转换都有效,您最终会向 Java 应用程序发送一个将时间设置为午夜的日期。 As a general rule, though, it would normally make more sense to just send the timestamp back to the Java application and let it handle how to convert that to a string and what components of the timestamp needed to be shown.但是,作为一般规则,通常将时间戳发送回 Java 应用程序并让它处理如何将其转换为字符串以及需要显示时间戳的哪些组件会更有意义。 So my default would be to just select date_created .所以我的默认设置是 select date_created

If you really want Oracle to do the data type conversion and to set the time component of the date to midnight, you can use trunc and cast instead.如果您确实希望 Oracle 进行数据类型转换并将date的时间部分设置为午夜,则可以使用trunccast代替。 This avoids implicit data type conversion and eliminates dependencies on the session's nls_timestamp_format .这避免了隐式数据类型转换并消除了对会话的nls_timestamp_format的依赖。

trunc( cast( date_created as date ) )
  1. Check the values in the admin_id and status_id columns.检查admin_idstatus_id列中的值。 Make sure they are correct data types.确保它们是正确的数据类型。

  2. Can you rearrange the query below and check output.您能否重新排列下面的查询并检查 output。 Try to use join where possible instead of the nested query to improve the performance of the database:尽量使用连接而不是嵌套查询来提高数据库的性能:

     select ad.admin_id, to_date(ad.date_created, 'DD-MM-YYYY'), ad.name, ad.mobile, ad.email,st.status from admin ad,status st where ad.admin_id=st.status_id;
  3. Here is link for a similar issue: Getting Error - ORA-01858: a non-numeric character was found where a numeric was expected (Stackoverflow)以下是类似问题的链接: Getting Error - ORA-01858: a non-numeric character was found where a numeric is expected (Stackoverflow)

ORA-01858: a non-numeric character was found where a numeric was expected
select ad.admin_id, to_date(ad.date_created, 'DD-MM-YYYY'), 
       ad.name, ad.mobile, ad.email,st.status  
from admin ad,status st 
where ad.admin_id=st.status_id;

暂无
暂无

声明:本站的技术帖子网页,遵循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: 在需要数字的地方发现了一个非数字字符(时间戳、解码) - ORA-01858: a non-numeric character was found where a numeric was expected (timestamp, decode) 可能的日期分配错误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? 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