pg学习_函数类型

函数类型


函数的类型可以分为两种:单行函数和多行函数


1、单行函数


1.1 数值型函数
常用的数值型函数有: 
Round() 按指定精度对十进制数四舍五入  
Sin() 求正弦三角函数 
Cos() 求余弦三角函数 
Abs() 求绝对值函数 
Sqrt() 求平方根函数 
mod() 求除法余数 
power() 求幂函数 
floor() 求小于等于某数的最大整数 
ceil() 求大于等于某数的最小整数 
Trunc() 向零的方向截断浮点数 
highgo=# select round(45.923,2),round(45.923,0),round(45.923,-1);
 round | round | round 
-------+-------+-------
 45.92 |    46 |    50
(1 row)


1.2字符串函数
#小写转换函数: 
LOWER :将字符串中大写转换成小写 
UPPER :将字符串中小写转换成大写 
INITCAP :将单词中首个字母转换成大写 
highgo=# select id,initcap(name) from test1;
 id | initcap 
----+---------
  1 | Adam
  2 | Lilith
(2 rows)
#字符操作函数 
SUBSTR() : 取字符串
LENGTH() : 求字符串的长度 
LPAD() : 左补指定的长度 
RPAD() : 右补指定的长度 
REPLACE() : 替换字符串 
TRIM():从左边或者右边删除指定字符串 
highgo=# select substr('asdfg',2,3);
 substr 
--------
 sdf
(1 row)
highgo=# select length('asdfg');
 length 
--------
      5
(1 row)
highgo=# select position('w' in 'qwert');
 position 
----------
        2
(1 row)
highgo=# select lpad('asdf',10,'*');
    lpad    
------------
 ******asdf
(1 row)
highgo=# select rpad('asdf',10,'*');
    rpad    
------------
 asdf******
(1 row)
highgo=# select replace('asdfg asdfg','d','w');
   replace   
-------------
 aswfg aswfg
(1 row)
highgo=# select trim('ha' from 'hasdfg');
 btrim 
-------
 sdfg
(1 row)


1.3时间日期函数
Abstime()取当前的时间
注意:该函数与 oracle 中 sysdate 函数对应。Oracle 里面的用法:select sysdate from dual ;
highgo=# select abstime(timestamp 'now');
        abstime         
------------------------
 2017-04-01 08:28:29+08
(1 row)


1.4格式化函数 
格式化函数提供一套有效的工具用于把各种数据类型(日期/时间,int,float,numeric) 转换成格式化的字符串以及反过来从格式化的字符串转换成原始的数据类型。 To_char()将时间 int float numeic 其中的之一的转换成字符串 
To_date()将字符串转换成日期 
To_number()将字符串转换成numeric 类型的实数。 
highgo=# select abstime(timestamp 'now');
        abstime         
------------------------
 2017-04-01 08:28:29+08
(1 row)
highgo=# select to_char(234,'999'); 
 to_char 
---------
  234
(1 row)
highgo=#  select to_date('05 dec 2011','dd mon yyyy'); 
  to_date   
------------
 2011-12-05
(1 row)
highgo=#  select to_number('12,454.8$','99G999D9S'); 
 to_number 
-----------
   12454.8
(1 row)


2、多行函数
多行函数有: 
AVG()   求平均值 
SUM()   求总和 
MIN()   求最小值 
MAX()   求最大值 
COUNT() 统计总记录数 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值