SELECT TO_CHAR(your_numeric_column, 'FM99999990.99') FROM your_table; 在上面的例子中,'FM99999990.99' 是格式化模式,其中 FM 前缀用于去除多余的空格,9 表示数字位,0 表示在数字不足时填充零,. 表示小数点,99 表示小数点后的位数。你可以根据需要调整这个模式。 去除尾随零: 如果你想去除转换后的字符
to_char 函数 to_char(expre, format) 函数用于将 timestamp、interval、integer、double precision 或者 numeric 类型的值转换为指定格式的字符串。 SELECT to_char(current_timestamp, 'HH24:MI:SS'), to_char(interval '5h 12m 30s', 'HH12:MI:SS'), to_char(-125.8, '999D99'); to_char |to_...
to_number(text, text) numeric 把字串转换成 numeric to_number('12,454.8-', '99G999D9S') 在输出模板字串里(对 to_char 而言),该函数族可以识别一些特定的模式,并且 把待格式化的数值正确地格式化成相应的数据。 任何不属于模板模式的文本都简单地照字拷贝。同样,在一个输入 模板字串里(对除 to_char...
to_char 函数 to_char(expre, format)函数用于将timestamp、interval、integer、double precision或者numeric类型的值转换为指定格式的字符串 SELECTto_char(current_timestamp,'HH24:MI:SS'),to_char(interval'5h 12m 30s','HH12:MI:SS'),to_char(-125.8,'999D99');14:46:1105:12:30-125.80 to_number ...
to_char(numeric_type,text) →text 根据给定的格式将数字转换为字符串;适用于integer,bigint,numeric,real,double precision。 to_char(125, '999')→125 to_char(125.8::real, '999D9')→125.8 to_char(-125.8, '999D99S')→125.80- to_date(text,text) →date ...
各种数据类型(日期/时间、integer、floating point和numeric)转换成格式化的字符串及反过来从格式化的字符串转换成指定的数据类型,在实际操作中经常遇到。但是具体调用那些数据库自带函数可以解决呢?接下来让我们一起去了解一下吧 日期操作函数 函数返回类型描述实例 to_char(timestamp,text) text 把时间间隔转换为字符串...
CREATEORREPLACEFUNCTIONformat_number_with_commas(numeric)RETURNStextAS$$BEGINRETURNto_char($1,'FM999999999999999999');END;$$LANGUAGEplpgsql; 然后,你可以在查询中使用这个函数: 代码语言:sql 复制 SELECTformat_number_with_commas(number_column)ASformatted_numberFROMyour_table; ...
To_char(int,text) text 把整数类型转换成字符串 to_char(numeric,text) text 把数字转换成字符串 to_date(text,text) date 把字符转换成日期 to_number(text,text) numeric 把字符转换成数字 to_timestamp(text,text) Timestamp with time zone 把字符串转换成时间戳 用case 转换 select cast(varch...
to_char(numeric, text) text 把numeric转换成字串 to_char(-125.8, '999D99S') to_date(text, text) date 把字串转换成日期 to_date('05 Dec 2000', 'DD Mon YYYY') to_timestamp(text, text) timestamp 把字串转换成时间戳 to_timestamp('05 Dec 2000', 'DD Mon YYYY') to_timestamp(doubl...
to_char(double precision, text) text 双精度转换为字符串 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 转...