00936. 00000 - "missing expression" CAST EXPRESSION - ora-00936

I am trying to change a date format on a column labeled ADDED_DATE.
the current results are 30-FEB-17 I wanted to convert to mm/dd/yyyy
I tried using the statement below but it is giving me an error.
CAST(varchar(10), cast (ADDED_DATE AS date) , 101) ,
ORA-00936: missing expression
00936. 00000 - "missing expression"
*Cause:
*Action:
Thank you for your time.

Try to do directly this:
to_date(ADDED_DATE,'DD/MM/YYYY');

needed to add To_char
TO_CHAR(TO_DATE('01-JAN-16','DD-MON-YY'),'MM/DD/YYYY')

Related

Inavlid timestamp Teradata

I have Ship_Date as 12/14/2013 20:27 and defined as varachar datatype in the source table.How can I convert this to timestamp format and load as is 12/14/2013 20:27?I'm using CAST (SHIP_DATE AS TIMESTAMP(0) FORMAT 'MM/DD/YYYYHH:MI:SS') AS SHIP_DATE but terdata is throwing invalid timestamp error.Please help in resolving the issue
You were missing the B indicating a blank/space in your original cast. But Teradata casts chokes on a single digit month. You can add a leading zero using a RegEx:
Cast(RegExp_Replace(SHIP_DATE,'\b([\d])\b', '0\1') AS TIMESTAMP(0) FORMAT'dd/mm/yyyyBhh:mi')
select to_timestamp('12/14/2013 20:27','MM/DD/YYYY HH24:MI');
The problem with your cast as you have it written is you are telling Teradata you have seconds in your string when you don't. You can use:
select cast ('12/14/2014 20:27' as TIMESTAMP(0) FORMAT 'MM/DD/YYYYBHH:MI')
However, this still won't handle single digit months.
The issue here is the empty space between 2013 and 20 and the missing zeros for the seconds.
I did oreplace to remove the space and concatenation and it worked.
SELECT
CAST (
( OREPLACE('12/14/2013 20:27', ' ','') ||':00')
AS TIMESTAMP(0) FORMAT 'MM/DD/YYYYHH:MI:SS'
) AS SHIP_DATE
And the result is below:

insert statment make error

I am using oracle 12c with the username system. My problem is when I execute this insert statement that I took from oracle live sql site:
insert into emp
values(7788, 'SCOTT', 'ANALYST', 7566,to_date('13-JUL-87','dd-mm-rr') - 85,3000, null, 20);
it shows :
sql error ora-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.
what is this -85 after the to_date(..)
To handle dates, you would better use the ANSI format (date 'yyyy-mm-dd'):
insert into emp values(7788, 'SCOTT', 'ANALYST', 7566, date '1987-07-13'- 85,3000, null, 20);
If you need to use a to_date for some reason, you have to be sure that the format of your string exactly matches the format mask you use: if your month is written as 'JUL' you need 'MON' in the format mask and not 'mm'. 'mm' would match a month written as '07'.
Please notice that even with the right format mask, this way to write dates is dangerous, because it's based on the language of your DB.
The -85 means "subtract 85 days".

Getting invalid datatype error while parsing xml in Oracle

I am trying to parse XML in PL SQL. But getting following error
Error report:
ORA-06550: line 21, column 43:
PL/SQL: ORA-00902: invalid datatype
ORA-06550: line 17, column 1:
PL/SQL: SQL Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
I am trying to run below query
DECLARE
l_xml xmltype:= xmltype('<Table>
<Data>
<DataKey>Test</DataKey>
<DataTypeID>8</DataTypeID>
<DataValue>test1</DataValue>
<Id>eb96c9c1-6236-403d-9afa-6d45ec623dbc</Id>
</Data>
</Table>');
begin
select * FROM
xmltable ('/Table/Data' passing l_xml
columns
DataKey nvarchar2(50) path '/Data/DataKey'
,DataTypeID int, path '/Data/DataTypeID'
, DataValue nvarchar2(1024) path '/Data/DataValue');
end;
/
I am new to PL/SQL, so not able to figure out the error. Can anybody help me here?
Thanks
You have an extra comma between int and path:
,DataTypeID int, path '/Data/DataTypeID'
should be
,DataTypeID int path '/Data/DataTypeID'
Or you could use number instead of int.
Your select also has to be selecting into something, since this is in a PL/SQL context. So now you'll get a PLS-00428 error. Without knowing what you plan to do with the results it isn't entirely obvious how you should correct that - whether you don't actually need PL/SQL, or you want to loop over the results to do something with them, or insert into another table, or...

SSIS datetime trucation error

I'm using following expression in Derived Column Component to get hour and minute from datetime field. e.g. Get "12:13" from "2012-08-14 12:13:03.650"
LKPStartTime:
(DT_STR,5,1252)SUBSTRING((DT_STR,10,1252)(DT_DBTIME)StartTime,1,5)
However, it pops up error message of
"Derived Column" failed because truncation occurred, and the
truncation row disposition on output column "LKPStartTime" specifies
failure on truncation. "
Is there any problem of my expression? Thanks for any answers!
I think it should be 12,5 instead of 1,5

Oracle: Error when executing query

I have a table SyncTokenLock that has column lockName that is of CLOB type. When I run following query from SQLDeveloper -
select * from SyncTokenLock where
lockName='com.vmware.horizon.datastore.impl.ProvisioningStateDataServiceImpl';
I get following exception -
ORA-00932: inconsistent datatypes: expected - got CLOB
00932. 00000 - "inconsistent datatypes: expected %s got %s"
I get similar error when this query is executed through Hibernate (3.6.10) against Oracle 11g. Hibernate throws following exception -
ORA-00932: inconsistent datatypes: expected - got CLOB
Any idea what could the reason be.
Correct, you can't use equality with a CLOB in the WHERE clause. But you can do this:
SELECT * FROM SyncTokenLock
WHERE dbms_lob.substr(lockName, 100) =
'com.vmware.horizon.datastore.impl.ProvisioningStateDataServiceImpl';
Does your column really need to be a CLOB? Are you expecting values over 4000 characters? If not, use a VARCHAR2.
Instead of using the equal sign, you may use like:
select * from SyncTokenLock where lockName like 'com.vmware.horizon.datastore.impl.ProvisioningStateDataServiceImpl';

Resources