Cannot convert String to date in Oracle 11g - oracle

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.

Related

"ORA-12401: invalid label string: " error

I am trying to run a simple update statement in Oracle to modify an Integer field of a specific row.
UPDATE Mytable
SET field1 = 2
WHERE field2 = 11111;
But I receive this error
SQL Error: ORA-12401: invalid label string:
ORA-06512: at "LBACSYS.NUMERIC_LABEL_TO_CHAR", line 1
ORA-06512: at "LBACSYS.LBAC$BU0_92924", line 1
ORA-04088: error during execution of trigger 'LBACSYS.LBAC$BU0_92924'
12401. 00000 - "invalid label string: %s"
*Cause: The policy could not convert the label string to a valid
internal label.
*Action: Correct the syntax of the label string.
Google search did not bring much results. Do you have any idea about the solution of this error?

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

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');

PLSQL Invalid Month

Why am I getting invalid month when I test this code? How does PLSQL and XML handle data types?
CURSOR c_DATA_INF is
select * from xmltable ('/' PASSING i_XML COLUMNS READING_DT DATE PATH 'DATE',
Actual NUMBER PATH 'ACTUAL',
Eligible NUMBER PATH 'ELIGIBLE'
);
begin
for d in c_DATA_INF loop
insert into table_name(READING_DT, actual, eligible)
values (to_date('d.READING_DT', 'MM/DD/YYYY'), d.ACTUAL, d.ELIGIBLE);
end loop;
end;
I'm not sure if it's incorrect in my insert statement or in my cursor.
Thanks!
You are passing d.READING_DT as string. within quotes. Please remove the quotes and try
The parameter types are invalid in to_date(DATE, "DATE FORMAT STRING");
Link to Example
Instead of passing 'd.READING_DT', remove the quotes. Pass: d.READING_DT
The error is thrown becasue Oracle does not recognize 'd.READING_DT' as a valid date/ or date string.

ORA-01722: invalid number for Number datatype in oracle

I am trying to insert a value in KPI_DEFINITION table and i am getting amn error ORA-01722: invalid number. The error is for KPI_FREQUENCY field which NUMBER datatype and it has trying to insert value '0,5'. I think number datatype allows integer as well as float values. But still its giving an error.
Insert into RATOR_MONITORING_CONFIGURATION.KPI_DEFINITION (KPI_DEF_ID,KPI_NAME,KPI_DESC,KPI_FREQUENCY) values ('10003881','Backlog Resul11t','Backlog Result11','0,5');
In SQL numbers are not specified using single quotes.
Additionally: fractional digits are separated using a dot . not a comma. So you need to write this as:
Insert into RATOR_MONITORING_CONFIGURATION.KPI_DEFINITION
(KPI_DEF_ID,KPI_NAME,KPI_DESC,KPI_FREQUENCY)
values
('10003881','Backlog Resul11t','Backlog Result11', 0.5);
^
Here
If KPI_DEF_ID is also a number column, remove the single quotes for that value as well:
For a complete documentation on how to specify numbers or string literals, please see the manual:
https://docs.oracle.com/database/121/SQLRF/sql_elements003.htm#i139891
Possible data type for KPI_FREQUENCY in your case is number(2,1)
Modification of your insert statement
Insert into RATOR_MONITORING_CONFIGURATION.KPI_DEFINITION (KPI_DEF_ID,KPI_NAME,KPI_DESC,KPI_FREQUENCY)
values ('10003881','Backlog Resul11t','Backlog Result11',0.5);

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