Spring Batch: SQL error ORA-01858: a non-numeric character was found where a numeric was expected - oracle

I'm trying to use this SQL in my spring batch reader. The SQL seems to have a problem:
select DISTINCT ces.COR_ENBL_STG_ID
from HBX_BATCH_COR_ENBL_STG ces
Inner JOIN HBX_INDV_NEG_ACTION ina ON ces.INDV_ID=ina.INDV_ID
where ces.DISP_PROCESSED_FLAG='Y'
AND ina.NEG_ACTION_RUN_RSN_CD in('11054','11055','11065')
AND ces.PGM_BGN_DT+90<'#{jobExecutionContext['latest.completed.startTime']}'
The value of latest.completed.start.time is coming as '07-Oct-16 12:38:58.000000109 PM' from a tasklet using jdbctemplate and hence the SQL is throwing the following error : ORA-01858: a non-numeric character was found where a numeric was expected.
Just FYI the column ces.PGM_BGN_DT is a Date Type. I tried TO_DATE function but it didn't help. Any suggestions please?

As I understand latest.completed.startTime - is a string of characters.
And its look like as oracle timestamp datatype.
If my suggestion are true, You should use format to convert string to timestamp
to_timestamp(latest.completed.startTime, 'dd-mon-yy HH12:MI:SS.FF AM');

Related

Convert a date string in oracle pl/sql [duplicate]

How can I convert this string date to datetime in oracle.
2011-07-28T23:54:14Z
Using this code throws an error:
TO_DATE('2011-07-28T23:54:14Z', 'YYYY-MM-DD HH24:MI:SS')
How can this be done?
Error report:
SQL Error: ORA-01861: literal does not match format string
01861. 00000 - "literal does not match format string"
*Cause: Literals in the input must be the same length as literals in
the format string (with the exception of leading whitespace). If the
"FX" modifier has been toggled on, the literal must match exactly,
with no extra whitespace.
*Action: Correct the format string to match the literal.
Update:-
TO_DATE('2011-07-28T23:54:14Z', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')
I only see the date not time in the column
28-JUL-11
Try this:
TO_DATE('2011-07-28T23:54:14Z', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')
Hey I had the same problem. I tried to convert '2017-02-20 12:15:32' varchar to a date with TO_DATE('2017-02-20 12:15:32','YYYY-MM-DD HH24:MI:SS') and all I received was 2017-02-20 the time disappeared
My solution was to use TO_TIMESTAMP('2017-02-20 12:15:32','YYYY-MM-DD HH24:MI:SS') now the time doesn't disappear.
You can use a cast to char to see the date results
select to_char(to_date('17-MAR-17 06.04.54','dd-MON-yy hh24:mi:ss'), 'mm/dd/yyyy hh24:mi:ss') from dual;

Phoenix: Convert String column to Integer column

I am looking for a Built-in UDF or any other method to convert values of a string column to integer in my phoenix table for sorting using SELECT and ORDER BY. I searched in the apache language Manual, but no use. Any other suggestions also welcome.
Actual Query
select "values" from "test_table"
I tried below approach but did not work
select TO_NUMBER("values", '\u00A4') from "test_table"
TO_NUMBER returns decimal but you can cast the result to INTEGER
SELECT CAST(TO_NUMBER(MY_COLUMN) AS INTEGER) FROM MY_DB
select TO_NUMBER(values) from test_table;
see https://phoenix.apache.org/language/functions.html#to_number

Cannot convert String to date in Oracle 11g

I'm trying to insert Date into table from user input but something doesn't work.
I have the following Query :
INSERT INTO DOCTORS.TREATMENTS
(START_OF_TREATMENT, END_OF_TREATMENT, DOCTORS_ID,PACIENTS_ID, DIAGNOSIS_ID)
VALUES (TO_DATE(&startdate, 'yyyy/mm/dd'), TO_DATE(&enddate, 'yyyy/mm/dd'), 3, 1, 1);
For start date I set :
2000/10/01
And for end date I set :
2000/11/01
It seem ok for me but I've got the following error :
Error report -
ORA-01858: a non-numeric character was found where a numeric was expected
ORA-06512: at "SYS.STANDARD", line 167
ORA-06512: at line 2
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.
Any one can explain to me why this error occurred.
Best regards,
Petar.
The value of the first parameter passed to TO_DATE must be a string. After substitution with the value you've given your code will look like
TO_DATE(2000/10/01, 'yyyy/mm/dd')
which fails as shown.
The solution is to put the parameter usage in single-quotes to make the substituted value a string, as in
TO_DATE('&startdate', 'yyyy/mm/dd')
This way, when &startdate is substituted you'll get
TO_DATE('2000/10/01', 'yyyy/mm/dd')
which will work as expected.
Do the same for &enddate.
Best of luck.

SQLPLus vs SQLDeveloper behavior

I'm experiencing a different behavior between SQLPlus and SQL Developer.
Example data:
create table test (
INIT_DATE DATE
);
INSERT INTO test(INIT_DATE) values (sysdate);
COMMIT;
Now I run the following query (notice we're doing an unnecessary to_date because INIT_DATE is already a date):
select to_date(INIT_DATE, 'dd/mm/rrrr') from test;
The result is:
SQLPlus => Return 20/09/16
SQLDeveloper => Throw ORA-01861
I found this answer, so in SQLDeveloper I changed NLS>Format Date to 'DD/MM/RR' and now SQLDeveloper return 20/09/16.
But, if in SQLDeveloper I change NLS to 'DD/MM/RR HH24:MI:SS' again, and I change the query mask to 'DD/MM/RR', SQLDeveloper return an error again:
select to_date(INIT_DATE, 'DD/MM/RR') from test;
Can anyone explain this behavior?
Why SQLDeveloper throw an error if the query mask is 'DD/MM/RR' but not when NLS is 'DD/MM/RR'?
Use TO_CHAR instead of TO_DATE. TO_DATE function converts char argument in specific format given by second parameter to date value.
Your statement
select to_date(INIT_DATE, 'DD/MM/RR') from test;
does first implicit conversion to char, because INIT_DATE is a date. This conversion is in nls default format, depending on your machine settings.
You try convert DATE to DATE through TO_DATE function, but TO_DATE function arguments are strings and as result Oracle convert INIT_DATE column to string and then pass this string into TO_DATE function.
If you use implicit conversion 'string to date' or 'date to string' , then Oracle use the default date format. In different environments default date format may be different.
Try to use an explicit conversion and an appropriate format.
For example:
select to_date(to_char(INIT_DATE, 'dd/mm/rrrr'), 'dd/mm/rrrr') from test;

How to Save Date in Yii with Oracle

How does one save the date in Yii with Oracle?
$trx->DATE_TRX=date('Y-m-d');
CDbCommand failed to execute the SQL statement:
SQLSTATE[HY000]: General error: 1861
OCIStmtExecute: ORA-01861: literal does not match format string
(ext\pdo_oci\oci_statement.c:148).
The SQL statement executed was:
INSERT INTO "TRX" ("IDMEMBER", "DATE_TRX") VALUES (:yp0, :yp1) RETURNING "ID" INTO :RETURN_ID
I would guess that you're supplying a character literal as the date, in a format such as 'yyyy-mm-dd'. If so then you should explicitly convert that to a date as part of the insert statement ...
INSERT INTO "TRX" ("IDMEMBER", "DATE_TRX")
VALUES (:yp0, to_date(:yp1,'yyyy-mm-dd'))
RETURNING "ID" INTO :RETURN_ID

Resources