openGauss SQL参考—函数和操作符:类型转换函数(1)
类型转换函数
类型转换函数
-
cash_words(money)
描述:类型转换函数,将money转换成text。
示例:
openGauss=# SELECT cash_words('1.23'); cash_words ----------------------------------- One dollar and twenty three cents (1 row) -
cast(x as y)
描述:类型转换函数,将x转换成y指定的类型。
示例:
openGauss=# SELECT cast('22-oct-1997' as timestamp); timestamp --------------------- 1997-10-22 00:00:00 (1 row) -
hextoraw(raw)
描述:将一个十六进制构成的字符串转换为raw类型。
返回值类型:raw
示例:
openGauss=# SELECT hextoraw('7D'); hextoraw ---------- 7D (1 row) -
numtoday(numeric)
描述:将数字类型的值转换为指定格式的时间戳。
返回值类型:timestamp
示例:
openGauss=# SELECT numtoday(2); numtoday ---------- 2 days (1 row) -
pg_systimestamp()
描述:获取系统时间戳。
返回值类型:timestamp with time zone
示例:
openGauss=# SELECT pg_systimestamp(); pg_systimestamp ------------------------------- 2015-10-14 11:21:28.317367+08 (1 row) -
rawtohex(string)
描述:将一个二进制构成的字符串转换为十六进制的字符串。
结果为输入字符的ACSII码,以十六进制表示。
返回值类型:varchar
示例:
openGauss=# SELECT rawtohex('1234567'); rawtohex ---------------- 31323334353637 (1 row) -
to_bigint(varchar)
描述:将字符类型转换为bigint类型。
返回值类型:bigint
示例:
openGauss=# SELECT to_bigint('123364545554455'); to_bigint ---------------- 123364545554455 (1 row) -
to_binary_float(expr [default return_vaue on conversion error])
描述:将输入内容转换为单精度浮点数。
-
支持的入参类型:real、double precision、text和NULL值。
-
可选的[DEFAULT return_expr ON CONVERSION ERROR]指定在
expr转换失败时该函数返回的值。
返回值类型:real
示例:
openGauss=# select to_binary_float('3.456'); to_binary_float ----------------- 3.456 (1 row) openGauss=# select to_binary_float('3.456Ab'); ERROR: invalid input syntax for type real CONTEXT: referenced column: to_binary_float SQL function "to_binary_float" statement 1 referenced column: to_binary_float openGauss=# openGauss=# select to_binary_float('3.456Ab' default '1.23' on conversion error); to_binary_float ----------------- 1.23 (1 row) -

浙公网安备 33010602011771号