SELECTtruncate(1314.1314*100, -3); #131000SELECTtruncate(1314.1314, 0); #1314SELECTFORMAT(423423234.65534453,2); #423,423,234.66SIGN(X):1、x>0rtn12、x<0rtn-13、x==0rtn0RAND(X):返回一个[0,1)之间的数,如果RAND(2)==0.123456;下次再运行RAND(2)还是等于0.123456,类似一个标识一样。
CONCAT():如果字符串中包含NULL,返回拼接结果就是NULL。CONCAT_WS():SELECTCONCAT_WS('-','a','b','c'); a-b-cSELECTCONCAT_WS('-','a','b','c',null); a-b-cSELECTCONCAT_WS(null,'a','b','c'); NULLLPAD() |RPAD():用字符串填充到指定长度SELECTLPAD('abc',10,'?'); ???????abcSELECTRPAD('abc',10,'!'); abc!!!!!!!REPEAT():重复指定的次数SELECTREPEAT('hello',3); hellohellohelloREPLACE():替换指定的字符串SELECTREPLACE('hello king','king','queen'); helloqueenSUBSTRING():截取字符串,从1开始SELECTSUBSTRING('abcdef',1,3); abc
返回当前的日期时间SELECTNOW(), CURRENT_TIMESTAMP(), SYSDATE(); 星期天、星期一……星期六return1、2……7SELECTYEAR(NOW()),MONTH(NOW()),DAY(NOW()),HOUR(NOW()),MINUTE(NOW()),SECOND(NOW()); DATEDIFF():计算两个日期相差的天数SELECTDATEDIFF('2017-03-06','2017-03-02'); 4
SELECTMD5('king'); PASSWORD():密码加密算法SELECTPASSWORD('root');
六、其他常用函数
SELECTVERSION(), CONNECTION_ID(); SELECTUSER(), CURRENT_USER(), SYSTEM_USER(), SESSION_USER(); 得到上一步插入操作产生AUTO_INCREMENT的值SELECTLAST_INSERT_ID();