I am getting Getting ORA-01858 (a non numeric character was found where a numeric was expected) while running a query in sql transformation in informatica.
I am using TO_DATE function in my query like.
TO_DATE('31/DEC/9999','DD/MON/YYYY')
NVL(PROFIT,TO_DATE('31/DEC/9999','DD/MON/YYYY')
TO_DATE(A.SELL_DATE,'DD/MM/YY HH24:MI:SS') >= TO_DATE('01/JAN/22','DD/MM/YY HH24:MI:SS')
TO_DATE(A.SELL_DATE,'DD/MM/YY HH24:MI:SS') <= TO_DATE('18/APR/22','DD/MM/YY HH24:MI:SS')
TO_DATE(A.BUY_DATE,'DD/MM/YY HH24:MI:SS') = TO_DATE('18/APR/22','DD/MM/YY HH24:MI:SS')
Can anyone help me where i am going wrong.
Related
I was building an application in NestJS and I need to get the date from the Oracle, but I don't know how convert this query:
SELECT TO_CHAR
(SYSDATE, 'MM-DD-YYYY HH24:MI:SS') "NOW"
FROM DUAL;
In a TypeORM query.
Can you help me?
I found this way to get what I wanted:
await getManager().query(`SELECT TO_CHAR(SYSDATE, 'MM-DD-YYYY HH24:MI:SS') "NOW" FROM DUAL`);
This question already has answers here:
Encountering SQL Error: ORA-01843: not a valid month
(5 answers)
ORACLE - ORA-01843: not a valid month
(2 answers)
Closed 4 years ago.
My Oracle table has 1,000 observations the following 2 variables: (Both fields are varchar)
ID datecreate
ABC 24/12/2016 05:32:07
I would like to filter the dates. I tried the following but to no avail...
select *
from table
where datecreate >= to_date('01/02/2018 00:00:00', 'dd/mm/yyyy hh24:mi:ss') and
datecreate <= to_date('28/02/2018 23:59:00', 'dd/mm/yyyy hh24:mi:ss')
I keep getting the following error...
ORA-01843: not a valid month
01843. 00000 - "not a valid month"
*Cause:
*Action:
Did I miss something obvious?
Thanks
It has been emphasized several times that in databases, DATE and TIME should not be stored as strings. Yet, there are several questions raised everyday, arising solely due to this poor practice.
Note that in Oracle, datetimes can either be stored as DATE type or TIMESTAMP( with or without TIMEZONE ). The DATE type contains the time component as well.
TO_DATE function comes to our rescue in cases where date strings have to be dealt with for conversion. While using dates, it is a good practice to use standard DATE literals in 'YYYY-MM-DD' format which most DBMSes understand. ( eg:- DATE '2018-02-28' ).
Also, you need not use '28/02/2018 23:59:00' or TRUNC function for such boundary cases, when you can use DATE literals. So, your query could be rewritten as
SELECT *
FROM yourtable
WHERE TO_DATE(datecreate, 'dd/mm/yyyy hh24:mi:ss') >= DATE '2018-02-01'
AND TO_DATE(datecreate, 'dd/mm/yyyy hh24:mi:ss') < DATE '2018-02-28' + 1
or < DATE '2020-02-29' if you know that it's a leap year.
If you really want to consider till 23:59 minutes, then TIMESTAMP literals could be used with TO_TIMESTAMP function.
.. AND TO_TIMESTAMP(datecreate, 'dd/mm/yyyy hh24:mi:ss') <
TIMESTAMP '2018-02-28 23:59:00'
The default NLS_DATE_FORMAT currently is DD-MON-RR. Thus your datecreate column defined as string will be implicitly converts to that format. The value 12 is not the same as DEC, thus the error. Either you use the right format or convert it to date similar below.
select *
from tbl
where to_date(datecreate, 'dd/mm/yyyy hh24:mi:ss') >=
to_date('01/02/2016 00:00:00', 'dd/mm/yyyy hh24:mi:ss')
and to_date(datecreate, 'dd/mm/yyyy hh24:mi:ss') <=
to_date('28/02/2018 23:59:00', 'dd/mm/yyyy hh24:mi:ss')
What is the query in Oracle to fetch the data for current_date
the column end_date is like the following
end_date
27-10-16 03:35:00.000000000 PM
23-11-16 11:15:00.000000000 AM
02-11-16 03:00:00.000000000 PM
08-11-16 09:00:00.000000000 AM
Like I am running the following query as
Select * from table1
where end_date < TO_DATE('2017-04-11 00:00:00', 'YYYY-MM-DD HH24:MI:SS')
it is running successfully, but when i replace the query with the current date ... it is not giving the results
Select * from table1
where end_date < TO_DATE(current_date, 'YYYY-MM-DD HH24:MI:SS')
could someone tell me what is the cause the second query is not giving results.
CURRENT_DATE returns date. There is no need to use TO_DATE. The below query should be enough.
Select * from table1
where end_date < current_date;
If you run the below query you'll understand what went wrong for you. Year becomes 0011.
SELECT TO_DATE(current_date, 'YYYY-MM-DD HH24:MI:SS') FROM DUAL;
Please note that CURRENT_DATE returns the current date in the session time zone. SYSDATE returns the current date and time set for the operating system on which the database resides. This means that CURRENT_DATE and SYSDATE can return different results. You can have a look at this
The query worked like this :
Select * from table1
where trunc(end_date) < trunc(sysdate)
Trunc is used to compare the both dates and it fetch the results.
CURRENT_DATE is already a DATE value. You can format the output using to_char if you want.
end_date < CURRENT_DATE should do the job. Or you can set the nls parameter accordingly for a better readability.
If you are comparing only date, without timestamp, you can go with trunc()
I am trying to get data for a specific date range, I do it like this:
select EntryID
min(dtUsedDate) dtFirstUsedDate,
max(dtUsedDate) dtLastUsedDate
from tblEntrance e
where e.dtUsedDate between to_date('2016-02-08 10:00:00', 'yyyy-mm-dd hh24:mi:ss')
AND to_date('2016-02-08 10:15:59', 'yyyy-mm-dd hh24:mi:ss')
(dtFirstUsedDate and dtLastUsedDate are getting called in a outer select, so don't worry much about them for now)
What I get are the entrances (records) that are only between those dates/time, so dtFirstUsedDate and dtLastUsedDate, both toghether in between that date range. But what I need is those two to be independent, like the dtFirstUsed must be between that max and min date and dtLastUsed must be between that max and min date.
I hope my question is understandable and someone can help me.
I think you are looking for this..
SELECT e.EntryID
,MIN(e.dtUsedDate) dtFirstUsedDate
,MAX(e.dtUsedDate) dtLastUsedDate
FROM tblEntrance e
GROUP
BY e.EntryID
HAVING MIN(e.dtUsedDate) BETWEEN TO_DATE('2016-02-08 10:00:00', 'yyyy-mm-dd hh24:mi:ss')
AND TO_DATE('2016-02-08 10:15:59', 'yyyy-mm-dd hh24:mi:ss')
AND MAX(e.dtUsedDate) BETWEEN TO_DATE('2016-02-08 10:00:00', 'yyyy-mm-dd hh24:mi:ss')
AND TO_DATE('2016-02-08 10:15:59', 'yyyy-mm-dd hh24:mi:ss')
My below query is not returning any values when i pass the START_DATE and END_DATE as parameter to my oracle procedure. But when i set actual date in the query i am getting results. Kindly help me what is the mistake i have done here. Thanks in advance.
SELECT INCIDENT_ID
FROM INC_SM1 I
WHERE
I.CLOSE_TIME >= TO_DATE(START_DATE,'DD-MON-YYYY HH24:MI:SS')
AND I.CLOSE_TIME < TO_DATE(END_DATE,'DD-MON-YYYY HH24:MI:SS')
The below query is returning values, when I run my procedure
SELECT INCIDENT_ID
FROM INC_SM1 I
WHERE
I.CLOSE_TIME >= TO_DATE('01-JUL-2013 00:00','DD-MON-YYYY HH24:MI')
AND I.CLOSE_TIME < TO_DATE('01-AUG-2013 00:00','DD-MON-YYYY HH24:MI')
Note: My input to procedure is TO_DATE('01-JUL-2013 00:00','DD-MON-YYYY HH24:MI')
Since you're already forcing the date format, you can use the following query instead:
SELECT INCIDENT_ID
FROM INC_SM1 I
WHERE
I.CLOSE_TIME >= START_DATE
AND I.CLOSE_TIME < END_DATE