Oracle 等效于 SQL 函数“转换”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4179953/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Oracle equivalent to SQL function 'convert'
提问by Derek
For e.g in SQL I have:
例如在 SQL 我有:
CONVERT(VARCHAR(10), mydate, 120)
CONVERT(DECIMAL(18,2), cost)
Is there an equivalent for these in Oracle?
Oracle 中是否有这些等价物?
回答by OMG Ponies
This in TSQL:
这在 TSQL 中:
CONVERT(VARCHAR(10), mydate, 120)
...returns a string, so you should probably use TO_CHAR:
...返回一个字符串,因此您可能应该使用TO_CHAR:
TO_CHAR(mydate, 'yyyy-mm-dd hh24:mi:ss')
You'd use TO_DATEif the value is not already an Oracle DATE data type, using the same format mask:
如果值还不是 Oracle DATE 数据类型,您将使用TO_DATE,使用相同的格式掩码:
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:
这在 TSQL 中:
CONVERT(DECIMAL(18,2),cost)
...needs to use the CAST function:
...需要使用CAST 函数:
CAST(cost AS DECIMAL(18,2))