[英]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
.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
的时间部分设置为午夜,则可以使用trunc
和cast
代替。 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 ) )
Check the values in the admin_id
and status_id
columns.检查
admin_id
和status_id
列中的值。 Make sure they are correct data types.确保它们是正确的数据类型。
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;
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.