四川华远建设工程有限公司网站,郑州网站建设哪家专业,优化深圳seo,好学校平台网站模板各种数据类型#xff08;日期/时间、integer、floating point和numeric#xff09;转换成格式化的字符串及反过来从格式化的字符串转换成指定的数据类型#xff0c;在实际操作中经常遇到。下面总结了一些常用的函数。
日期操作函数
函数返回类型描述实例to_char(timestamp…各种数据类型日期/时间、integer、floating point和numeric转换成格式化的字符串及反过来从格式化的字符串转换成指定的数据类型在实际操作中经常遇到。下面总结了一些常用的函数。
日期操作函数
函数返回类型描述实例to_char(timestamp,text)text把时间间隔转换为字符串to_char(current_timestamp,HH12:MI:SS)to_char(interval,text)text把时间间隔转换为字串to_char(interval15h 12m 12s,HH24:MI:SS)to_char(int,text)text把整型转换为字串to_char(125,999)to_char(double,precision)text把实数/双精度数转换为字串to_char(125.8::real,999D9)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_timetamp(text,text)timestamp把字串转换为时间戳to_timestamp(05 Dec 2000,DD Mon YYYYto_timetamp(double)timestamp把unix纪元转换为时间戳to_timestamp(200120400)to_number(text,text)numeric把字串转换为numericto_number(12 454.8-,99G999D9S
用于日期/时间格式化的模式
模式描述HH一天的小时数(01-12)HH12一天的小时数(01-12)HH24一天的小时数(00-23)MI分钟(00-59)SS秒(00-59)MS毫秒(000-999)US微秒(000000-999999)AM正午标识(大写)Y,YYY带逗号的年(4和更多位)YYYY年(4和更多位)YYY年的后三位
字符串转换为整型
* 把12345 转换为整数
select cast (12345 as integer);
* 用substring截取字符串从第8个字符开始截取2个字符
select cast (substring(123344654,8,2) as integer);替换字符串方法及字符串操作函数
替换字符串实例
* 把字段coulmn_name里的字符aaa替换为0
update table_name set coulmn_namereplace(a,aaa,0);