Reputation: 51
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?
Upvotes: 5
Views: 11583
Reputation: 332731
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))
Upvotes: 8
Reputation: 12304
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')
Upvotes: 3