数据类型格式化转换,在查询时会比较常见。
Function |
Return Type |
Description |
Example |
to_char(timestamp, text) |
text |
转换时间戳为字符串 |
to_char(current_timestamp, 'HH12:MI:SS') |
to_char(interval, text) |
text |
转换时间间隔为字符串 |
to_char(interval '15h 2m 12s', 'HH24:MI:SS') |
to_char(int, text) |
text |
转换数字为字符 |
to_char(125, '999') |
to_char(double precision,text) |
text |
转换数字精度,最多D999 |
to_char(125.8::real, '999D9') |
to_char(numeric, text) |
text |
转换数字为字符 |
to_char(-125.8, '999D99S') |
to_date(text, text) |
date |
转换字符为日期格式 |
to_date('05 Dec 2000', 'DD Mon YYYY') |
to_number(text, text) |
numeric |
转换数字格式 |
to_number('12,454.8-', '99G999D9S') |
to_timestamp(text, text) |
timestamp with time zone |
转换字符为时间 |
to_timestamp('05 Dec 2000', 'DD Mon YYYY') |