首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 操作系统 >

postgres字符串惯用函数整理

2012-07-19 
postgres字符串常用函数整理-- 求字符串的长度select length(field) from table_nameselect char_length(

postgres字符串常用函数整理
-- 求字符串的长度
select length(field) from table_name;
select char_length(field) from table_name;
select character_length(field) from table_name;

-- 转换字符串地大小写
select lower(field) from table_name;
select upper(field) from table_name;

-- 字符串的替换 将field从1开始,2个字符替换为字符串f 按位置替换
select overlay(field placing 'f' from 1 for 2) from table_name;
-- 字符串的替换 将field中的f全部替换为x 按词替换
select replace(field,'f','x') from table_name;
-- 字符串的替换 将field中的f按照一对一的关系替换为x
select translate(field,'f','x') from table_name;

-- 截取字符串 field从1开始,截取2个字符,第一个字符的下标为1
select substring(field from 1 for 2) from table_name;

-- 在指定位置上删除指定字符 在头、尾或者两头删除A字符
select substring(leading|trailing|both 'A' from field) from table_name;

-- 将字符串的首字母大写化
select initcap(field) from table_name;
select overlay(string placing upper(substring(string from 1 for 1)) from 1 for 1) from table_name;

-- 取得当前日期函数
   select now();

-- 用一个表的数据更新另一个表的数据

update table1 set fieldName = value from table2 where condition.

热点排行