码迷,mamicode.com
首页 > 其他好文 > 详细

常用函数

时间:2016-12-12 23:18:05      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:name   登录   常用   ifnull   table   repeat   data   null   日期函数   

字符串函数:

concat (‘xiao‘,‘qun‘);
=====>xiaoqun

insert(‘woshixiaozou‘,10,3,‘qun‘);
=====> woshixiaoqun

select lower(‘XIAOQUN‘),upper(‘xiaoqun‘);
=====> xiaoqun XIAOQUN

select left(‘xiaoqunwoshi‘,7),right(‘xiaoqunwoshi‘,5);
=====>xiaoqun woshi

select lpad(‘xiaoqun‘,15,‘woshi‘);
=====>woshiwosxiaoqun

select rpad(‘xiaoqun‘,15,‘woshi‘);
=====>xiaoqunwoshiwos

select ltrim(‘ |xiaoqun),rtrim(‘xiaoqun| ‘);
=====>|xiaoqun xiaoqun|

select repeat(‘xiao‘,5);
=====>xiaoxiaoxiaoxiaoxiao

select replace(‘xiaoqun0318‘,‘0318‘,‘1314‘);
=====>xiaoqun1314
数值函数:

select abs(n); 返回n的绝对值
select ceil(n); 返回大于n的最小整数
select floor(n); 返回小于n的最大整数
select mod(m,n); 返回m/n的模
select rand( ); 随机返回一个0-1之间的数据
select round(m,n); 返回m的四舍五入的有n位的数值
select truncate(m,n);返回m截断为n位的值


时间和日期函数:

select curdate(); 返回当前日期0000-00-00
select curtime(); 返回当前时间00:00:00
select now(); 返回日期加时间
select unix_timestamp(now()); 返回日期date的Unix的时间戳
select from_unixtime(); 返回Unix的日期 与上面的互为逆运算
select hour(curtime()),minute(curtime()); 返回所给时间的时间 与 分钟
select week(now()),year(now());前面返回现在是今年的第几周,后面返回时哪一年;
select monthname(now()); 返回现在月份的英文月份函数;


select if(value,t,f) from table_name; 如果value为真 则 返回t
select ifnull(value1,value2) from table_name; 如果value值不为空返回value1,如果是则返回value2 一般用于替换null
select case when value1 then result.....else default end from table_name;


其他常用函数:

select database(); 返回当前数据库的名
select version(); 返回当前数据库的版本
select user(); 返回当前登录用户名
select inet_aton(ip);返回当前IP的数字表示
select inet_ntoa(num);返回数字代表的IP地址
select password(str); 返回字符串str的加密版本
select md5(); 返回字符串str的md5值

 

常用函数

标签:name   登录   常用   ifnull   table   repeat   data   null   日期函数   

原文地址:http://www.cnblogs.com/zouxiaopq/p/6165824.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!