For e.g in SQL I have:
CONVERT(VARCHAR(10), mydate, 120)
CONVERT(DECIMAL(18,2), cost)
Is there an equivalent for these in Oracle?
Explicit Data Type Conversion SQL Conversion functions are single row functions which are capable of typecasting column value, literal or an expression . TO_CHAR, TO_NUMBER and TO_DATE are the three functions which perform cross modification of data types.
The CONVERT() function converts a value (of any type) into a specified datatype.
TO_CHAR (datetime) converts a datetime or interval value of DATE , TIMESTAMP , TIMESTAMP WITH TIME ZONE , or TIMESTAMP WITH LOCAL TIME ZONE datatype to a value of VARCHAR2 datatype in the format specified by the date format fmt .
This in TSQL:
CONVERT(VARCHAR(10), mydate, 120)
...returns a string, so you should probably use TO_CHAR:
TO_CHAR(mydate, 'yyyy-mm-dd hh24:mi:ss')
You'd use TO_DATE if the value is not already an Oracle DATE data type, using the same format mask:
TO_DATE(mydate, 'yyyy-mm-dd hh24:mi:ss')
...or I would anyways, preferring explicit data type conversion when dealing with temporal data types.
This in TSQL:
CONVERT(DECIMAL(18,2),cost)
...needs to use the CAST function:
CAST(cost AS DECIMAL(18,2))
You want to look at the built-in functions for PLSQL.
to_date('15/11/2010''dd/MM/yyyy')
and
to_number('1234.567','999.99')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With