Derek
Derek

Reputation: 51

Oracle equivalent to SQL function 'convert'

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

Answers (2)

OMG Ponies
OMG Ponies

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

Related Questions