Inserting date text into table returns `not a valid month` - oracle

My NLS_DATE_FORMAT is DD/MM/YY
When I enter values like these
Insert into EVENTREQUEST (EVENTNO,DATEHELD,DATEREQ,FACNO,CUSTNO,DATEAUTH,STATUS,ESTCOST,ESTAUDIENCE,BUDNO) values ('E100',to_date('25/10/13'),to_date('06/06/13'),'F100','C100',to_date('08/06/13'),'Approved',5000,80000,'B1000');
The row is inserted but when I use the following Format this error message appears.
Error starting at line 2 in command:
Insert into EVENTREQUEST (EVENTNO,DATEHELD,DATEREQ,FACNO,CUSTNO,DATEAUTH,STATUS,ESTCOST,ESTAUDIENCE,BUDNO)
values ('E101',to_date('26-OCT-13','DD-MON-RR'),to_date('28-JUL-13','DD-MON-RR'),'F100','C100',null,'Pending',5000,80000,'B1000')
Error report:
SQL Error: ORA-01843:not a valid month
01843. 00000 - "not a valid month"
*Cause:
*Action:
Can anybody help?

Exists somewhere else: Oracle insert failure : not a valid month
Maybe if you specify NLS_DATE_LANGUAGE?
Insert into EVENTREQUEST (EVENTNO,DATEHELD,DATEREQ,FACNO,CUSTNO,DATEAUTH,STATUS,ESTCOST,ESTAUDIENCE,BUDNO)
values ('E101',to_date('26-OCT-13','DD-MON-RR', 'NLS_DATE_LANGUAGE = AMERICAN'),to_date('28-JUL-13','DD-MON-RR', 'NLS_DATE_LANGUAGE = AMERICAN'),'F100','C100',null,'Pending',5000,80000,'B1000')

Related

Invalid date format in datatype column in BODS job to Oracle

I am using SAP BODS and I am trying to fetch data from an ORACLE server using SQL query transormation. Now The table has a column named latest_changed_date which is a datetime column. I only want yesterday and current day data from that table. Now since the column is datetime, I need to convert it to date, but when I am using to_date function I get the following error.
SELECT *
FROM ABC.TEST
WHERE TO_DATE(LATEST_CHANGED_DATE) = TO_DATE(SYSDATE-1)
The database error message is
ORA-01843: not a valid month
I tried giving date format in TO_DATE condition as below:
SELECT *
FROM ABC.TEST
WHERE TO_DATE(LATEST_CHANGED_DATE,'YYYY-MM-DD') >= TO_DATE(SYSDATE-1,'YYYY-MM-DD')
Here I got the error:
date format picture ends before converting entire input string
I used trunc function also and again got either:
not a valid month
or
inconsistent datatypes: expected NUMBER got DATE
Below is a sample data for the column. I just need data for current and day before data from the column.
Update: I think the main issue is that I am not able to determine the proper datatype for the column in the source table and currently I don't have an option to determine that.
Rather than trying to implicitly cast your dates to strings and convert them back using TO_DATE( string_value, format_model ) you can use TRUNC() to truncate SYSDATE to the start of the day:
SELECT *
FROM ABC.TEST
WHERE LATEST_CHANGED_DATE >= TRUNC( SYSDATE-1 )
this will work:
SELECT *
FROM ABC.TEST
where sysdate-LATEST_CHANGED_DATE<=sysdate-(sysdate-2);
for example take this:
ALTER SESSION SET NLS_DATE_FORMAT = ' DD-MON-YYYY HH24:MI:SS';
SELECT * FROM d061_dates ;
03-DEC-2018 17:44:38
25-AUG-2018 17:44:42
30-AUG-2018 17:44:46
01-DEC-2018 17:44:49
02-DEC-2018 17:46:31
SELECT * FROM d061_dates
where sysdate-a<=sysdate-(sysdate-2);
03-DEC-2018 17:44:38
02-DEC-2018 17:46:31
you have to take sysdate minus on both sides to get comparision by a number which is less than equal to 2 to get day and day before yesterday and its giving the correct output.
thank you!!!!!!!!!!!!!

How to convert the varchar data type in date through query in Oracle

I have a table in database in oracle where the field TIMESTAMP_MAIN is of VARCHAR2(255 CHAR) ..
TIMESTAMP_MAIN
2016-11-23T14:58:22
How do i convert the column to the date in the given format. I am trying the below query:
SELECT TO_DATE(TIMESTAMP_MAIN, 'yyyy-MM-dd'T'HH:mm:ss') from ACCOUNT;
It is giving the following error:
ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Error at Line: 1 Column: 44
what could be the reason for the error..
thanks in advance
You have to handle the T with double quotes and to fix MM into MI for minutes:
SELECT TO_DATE(TIMESTAMP_MAIN, 'YYYY-MM-DD"T"HH24:MI:SS') from ACCOUNT;
I also edited HH into HH24, given that in your example you have hours written in 24H format

oracle cannot insert values into a nested table field

I have the sample CUSTOMERS table.
I exported the values from table as INSERT script.
I took one row, modified the value from PK and re-executed the insert.
Insert into oe.customers (CUSTOMER_ID,
CUST_FIRST_NAME,
CUST_LAST_NAME,
CUST_ADDRESS,
PHONE_NUMBERS,
NLS_LANGUAGE,
NLS_TERRITORY,
CREDIT_LIMIT,
CUST_EMAIL,
ACCOUNT_MGR_ID,
CUST_GEO_LOCATION,
DATE_OF_BIRTH,
MARITAL_STATUS,
GENDER,
INCOME_LEVEL,
CREDIT_CARDS)
values ( oe.customer_seq.nextval,
'Donald',
'Hunter',
OE.CUST_ADDRESS_TYP('5122 Sinclair Ln','21206','Baltimore','MD','US'),
OE.PHONE_LIST_TYP('+1 410 123 4795'),
'us',
'AMERICA',
2600,
'Donald.Hunter#CHACHALACA.EXAMPLE.COM',
145,
MDSYS.SDO_GEOMETRY(2001,8307,MDSYS.SDO_POINT_TYPE(-76.545732,39.322775,NULL),NULL,NULL),
to_date('20-JAN-60','DD-MON-RR'),
'married',
'M',
'G: 130,000 - 149,999',
OE.TYP_CR_CARD_NST(OE.TYP_CR_CARD('Visa',100000000000011)));
and I have the following error message:
Error at Command Line : 32 Column : 29 Error report - SQL Error:
ORA-00904: : invalid identifier
00904. 00000 - "%s: invalid identifier"
*Cause:
*Action:
which refers to line:
OE.TYP_CR_CARD_NST(OE.TYP_CR_CARD('Visa',100000000000011)));
The definition of types are:
create or replace type typ_cr_card as object
( card_type VARCHAR2(25)
, card_num NUMBER);
create or replace type typ_cr_card_nst as table of typ_cr_card;
Can someone tell me, please, what is wrong with this insert line as it is the one provided by SQL DEVELOPER?
NOTE: Also, I tried to use a procedure which inserts values in this table and the error refers to TYP_CR_CARD_NST datatype.

Leave column out of Oracle insert statement

I have an insert statement that I am trying to run against an Oracle database. The insert statement is very simple, and I only want to insert a value into one column. The table itself has more than one column, but I am only interested in filling one of the columns with data. The format of my query is similar to the one below:
insert into myTable (col1) Values (val1)
However, this throws the following error:
ORA-00904: "col1": invalid identifier
I've checked to make sure that the column is named correctly, and my only other thought is that something is wrong with my syntax. There are no constraints on the table such as primary keys. Is it possible to only insert values into certain columns when executing an insert statement in Oracle?
Check that you didn't quote the column name on creation of the table. If you did, the column name is stored as you quoted it. For example:
create table table1 (
id number(2)
)
has a different column name to this
create table table2 (
"id" number(2)
)
Oracle by default stores the (unquoted) column names in uppercase. Quoted are stored as is.
You can use a DESC table_name to see how the columns are stored.
The following
select id from table1
select iD from table1
select ID from table1
fetch the records, while only
select "id" from table2
will fetch records.
select id from table2
will throw the ORA-00904 : "ID" : invalid identifier error.
You may have inadvertently done the quoting during creation while using tools as established below:
https://community.oracle.com/thread/2349926
Btw: Yes it is possible to insert records for only one column, as long as the other columns do not have a NOT NULL constraint on them.
Actually, I think you may be double quoting the column in the insert statement (not on table creation), although your example is misleading. I guess this because of your error, which says "col1" is invalid, not "COL1" is invalid. Consider this simple test:
SQL> create table mytable
(
col1 varchar2(10)
)
Table created.
SQL> -- incorrect column name, without double quotes
SQL> insert into mytable(col2) values ('abc')
insert into mytable(col2) values ('abc')
Error at line 9
ORA-00604: error occurred at recursive SQL level 1
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 11
ORA-00904: "COL2": invalid identifier
SQL> -- incorrect column name, with double quotes
SQL> insert into mytable("col2") values ('abc')
insert into mytable("col2") values ('abc')
Error at line 12
ORA-00604: error occurred at recursive SQL level 1
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 11
ORA-00904: "col2": invalid identifier
SQL> -- correct column name, without double quotes (works)
SQL> insert into mytable(col1) values ('abc')
1 row created.
SQL> -- correct column name, with double quotes (fails)
SQL> insert into mytable("col1") values ('abc')
insert into mytable("col1") values ('abc')
Error at line 18
ORA-00604: error occurred at recursive SQL level 1
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at line 11
ORA-00904: "col1": invalid identifier
The last failed insert attempt is what I think you may be doing:
insert into mytable("col1") values ...
based on the error message:
ORA-00904: "col1": invalid identifier
So the solution would simply be remove the double quoting around the column name in the insert.
It's most probably a syntax error
Desc myTable;
insert into myTable (col1) Values ('val1')
Ensure col1 is a valid column in the table, and you're simply not trying to say 'select the left-most column.
edit: Is it possible to only insert values into certain columns when executing an insert statement in Oracle?
Yes if you want to only insert into certain columns then simply specify it
e.g.
insert into myTable (col1, col2, col6) Values ('val1', 'val2', 'val3');
This will only work if the column itself doesn't have a NOT NULL constraint - in which case it will not allow a value to be enetered (unless again there's a default value).

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