Oracle error message input value not long enough - sql

I need help with the below query. I am getting an error message :
ERROR: Error fetching from cursor. ORACLE error is ORA-01840: input
value not long enough for date format.
What input value is this referring to not being in date format? I can't figure this out. I do see where it refers to AND Removed>= TO_DATE('08162011', 'MMDDYYYY').
Removed

Probably you have a value like TO_DATE('0816', 'MMDDYYYY') for
TR_EFF_DT input, and that does not fit with respect to the date
format, as in the following statement :
with tab(TR_EFF_DT) as
(
select TO_DATE('0816', 'MMDDYYYY') from dual
)
select *
from tab
where TR_EFF_DT>= TO_DATE('08162011', 'MMDDYYYY');
Error:
ORA-01861: literal does not match format string
OR you probably have a mismatch for your DB server's Date Format with your current session's Date Format. In this case you
may issue :
ALTER SESSION SET nls_date_format='MMDDYYYY';

Related

java dateformat with oracle format gives ORA-01722: invalid number

The date field in oracle DB is stored in '10-FEB-99' format. My calander function in UI accepts date in this format '02/30/2023'.
When i search date in UI, i have to query the DB with date field from UI to what exists in DB.
select * from case where TO_CHAR(p.OCCASION_FROM_DATE,'dd-MON-yyyy') = TO_CHAR('02/10/1999','MM/dd/yyyy');
When I execute this query I get below exception
**ORA-01722: invalid number
00000 - "invalid number"
Cause: The specified number was invalid.
Action: Specify a valid number.
Tried this
select * from case where TO_CHAR(p.OCCASION_FROM_DATE,'dd-MON-yyyy') = TO_CHAR('02/10/1999','MM/dd/yyyy');
The date field in oracle DB is stored in '10-FEB-99' format.
Is it? Perhaps. It depends on column datatype. What is it? If it is VARCHAR2, then yes - it might be stored that way, and that's wrong. You should always store dates into DATE datatype columns.
Let's presume it is a varchar2 column. In that case, you should match two values: first convert a string (02/10/1999) to a valid date value (using to_date with appropriate format model), and then back to string - again with format model that matches string stored into the column:
select * from case p
where p.OCCASION_FROM_DATE =
to_char(to_date('02/10/1999','MM/dd/yyyy'), 'dd-mon-rr', 'nls_date_language = english);
On the other hand, if values stored in table are in date datatype column (yes, that should be the case!), note that dates aren't stored in human-readable format. That's a 7-byte value representing century/year/month/day/hour/minute/second. The fact that you see it as 10-feb-99 is because your current NLS settings say so.
Query then gets somewhat simpler because you just have to convert string 02/10/1999 to date:
select * from case p
where p.occasion_from_date = to_date('02/10/1999', 'mm/dd/yyyy')

BigQuery - Error while reading table:Could not convert value to date. Error: Invalid date:

I'm trying to read a Google Sheet in BQ. After selecting auto-detect schema, I get this error on trying to run the query. I'm not sure what do I need to adjust in the date schema to make the query work.
SELECT date FROM proejct.dataset.table LIMIT 1000
Sharing the error and two screenshots from the query
Error while reading table: project.dataset.table, error message: Could not convert value to date. Error: Invalid date: '1/15/2011'. Row 1; Col 2.
The format YYYY-MM-DD should work for you
select DATE "2021-1-1"

format date in oracle SQL

I was trying to learn how to format date in oracle pl oracle, when I ran below query its returns error
SELECT TO_DATE('01-JAN-00', 'YYYY-DD-MM') FROM dual;
the error message is
ORA-01858: a non-numeric character was found where a numeric was expected
01858. 00000 - "a non-numeric character was found where a numeric was expected"
*Cause: The input data to be converted using a date format model was
incorrect. The input data did not contain a number where a number was
required by the format model.
*Action: Fix the input data or the date format model to make sure the
elements match in number and type. Then retry the operation.
You are either not using the correct format specifier, or not passing the correct string. You want:
SELECT TO_DATE('2000-01-01', 'YYYY-DD-MM') FROM DUAL;
Or:
SELECT TO_DATE('01-JAN-00', 'DD-MON-YY') FROM DUAL;
Or you can simply declare a DATE litteral:
SELECT DATE'2000-01-01' FROM DUAL;
for my scenario I had to use to_char which perfectly solve the formatting issue.
SELECT TO_CHAR('01-JAN-00', 'yyyy-DD-MM') FROM dual;

Change system date suggestions nedded

We have a new software package that allows the company to write SQL code to be place on Query portals. We have several reports we wish to code using the previous day as one of the selections. If a report is ran on MONDAY we want to automatically select the previous FRIDAY as the selection date, We have ORACLE SQL DEVELOPER 4.1. The code we are trying to use is listed below:
SELECT ALERT_CD,ALERT_KEY,CHG_DTM,
CASE
WHEN TO_CHAR(SYSDATE,'fmday')='sunday'
THEN SYSDATE-2
WHEN TO_CHAR(SYSDATE,'fmday')='monday'
THEN SYSDATE-3
ELSE SYSDATE-1
END "change"
FROM SG00400T
WHERE ALERT_CD='AUTO'
and CHG_DTM >= to_date('SYSDATE', 'mm/dd/yyyy')
The error we are receiving:
ORA-01858: a non-numeric character was found where a numeric was expected
01858. 00000 - "a non-numeric character was found where a numeric was expected"
*Cause: The input data to be converted using a date format model was
incorrect. The input data did not contain a number where a number was
required by the format model.
*Action: Fix the input data or the date format model to make sure the
elements match in number and type. Then retry the operation.
The CHG_DTM is a date/time field which could be part of the problem we do not full understand at this time.
Any help would be greatly appreciated.
The expression to_date('SYSDATE', 'mm/dd/yyyy') is are trying to convert the string constant 'SYSDATE' to a date - which can't work.
But you should never, ever call to_date() on a value that is already a date. That will first convert the date value to a varchar just to convert that varchar back to a date which it was to begin with.
So the to_date() function is wrong at that place to begin with. Most probably you want:
and CHG_DTM >= trunc(SYSDATE)

Asking User to input date in sql giving ORA-00932: inconsistent datatypes: expected DATE got NUMBER Error

I am trying to input a date value from the user and then using that value in the query.
select * from TB_MNP_GTY_TRANS_STEPS where CREATE_DATETIME>=&startdate
Now when i run the sql statement in Toad and input 8/1/2012 as date data type i am getting
ORA-00932: inconsistent datatypes: expected DATE got NUMBER
Can someone suggest where i am wrong.Note that CREATE_DATETIME is of Date Type.
You should really specify what date format you are using in your parameter:
SELECT *
FROM TB_MNP_GTY_TRANS_STEPS
where CREATE_DATETIME >= TO_DATE(&startdate, 'DD/MM/YYYY');
Read about date formats here
Currently your session is expecting the date to be in its default NLS_DATE default fomat and obviously the format of the date you're entering is different.
Explicitly specifying date formats prevents this issue from occurring.
Hope it helps...
EDIT:
If you want to pass in the 8th January 2012 then you could specify your variable value as:
08/01/2012
And your select would be:
SELECT *
FROM TB_MNP_GTY_TRANS_STEPS
where CREATE_DATETIME >= TO_DATE(&startdate, 'DD/MM/YYYY');
Depending upon your environment you might need to wrap the variable in single quotes (for TOAD you definiely will) i.e.
SELECT *
FROM TB_MNP_GTY_TRANS_STEPS
where CREATE_DATETIME >= TO_DATE('&startdate', 'DD/MM/YYYY');
The error you are getting is caused by the format of the date string you are entering not matching EXACTLY the format you are specifying (see the leading "0" before the 8 and 1 in the day and month!)
Date casting necessary
select * from TB_MNP_GTY_TRANS_STEPS where CREATE_DATETIME>=to_date(&startdate, 'MM-DD-YYYY')
and while passing parameter you should pass value in quoets as '08-09-1999'