How to convert the varchar data type in date through query in Oracle - 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

Related

Oracle - ORA-00907: missing right parenthesis in query generated by Odata query generator

this is the query generated by an Odata Sql query generator and I am on Oracle 12c
SELECT ID
FROM MY_TABLE
WHERE (
NAME LIKE 'abc' = true
)
;
and the error it generates is
ORA-00907: missing right parenthesis
00907. 00000 - "missing right parenthesis"
*Cause:
*Action:
Error at Line: 4 Column: 14
Any ideas on how to fix the query ?
Thanks in advance
I know nothing about "Odata Sql query generator", but - if you want to fix this query, then it would be
select id from my_table where name like 'abc'
On the other hand, that's same as
select id from my_table where name = 'abc'
so perhaps you actually meant to use wildcards:
select id from my_table where name like '%abc%'

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;

Why do I get an ORA-00922 when trying to create a partitioned table in Oracle?

I'm trying to create partitioned on oracle table but getting ORA-00922 error.
Error starting at line : 1 in command -
CREATE TABLE "RATE_REQUEST_BKP_PARIATIONED"
(
"RATE_REQUEST_ID" NUMBER(10,0),
"PRODUCT_CUSTOMER_ID" NUMBER(10,0),
"DESTINATION_ID" NUMBER(10,0),
"CREATED_DT" DATE,
"CREATED_BY" NUMBER(10,0),
"MODIFIED_DT" DATE,
"MODIFIED_BY" NUMBER(10,0),
"RATE_STATUS_ID" NUMBER(10,0)
)
PARTITION BY RANGE
(
CREATED_DT
)
INTERVAL
(
NUMTOYMINTERVAL(1, 'MONTH')
)
(
PARTITION p0 VALUES LESS THAN (TO_DATE('1-3-2017', 'DD-MM-YYYY')),
PARTITION p1 VALUES LESS THAN (TO_DATE('1-4-2017', 'DD-MM-YYYY')),
PARTITION p2 VALUES LESS THAN (TO_DATE('1-5-2017', 'DD-MM-YYYY'))
)
Error report -
SQL Error: ORA-00922: missing or invalid option
00922. 00000 - "missing or invalid option"
*Cause:
*Action:
Table "RATE_REQUEST_BKP_PARIATIONED" dropped.
Commit complete.
Please help me finding out the issue with query.
May this Help you
If an invalid option is specified while defining a storage clause or column, ORA-00922 will be thrown. ORA-00922 mentions that to specify that the column is not able to contain any NULL values, the valid option while specifying a column is NOT NULL, and solely constraints can follow the datatype.
Also notable to ORA-00922, which can also cause this error to be thrown, is that specifying a maximum length on LOG or DATE datatype.
Correcting ORA-00992 consists of correcting the syntax in your specifications, minding to take out the erroneous option or length specification from the storage of column specification
Answer got from this link
http://www.dba-oracle.com/t_ora_00922_missing_or_invalid_option.htm

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.

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

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

Resources