mysql functions

1.  IF(expr1,expr2,expr3)

  -> if expr1 then expr2 else expr3 end

2 . ISNULL(expr)

  -> return 0 || 1

3.  SELECT IFNULL(1/0,10)       

  -> 10

4.  NULLIF (1, 1 )

  -> null

5.  char(ascii('M'));

  -> 'M'

6.  char_length('中国');

  -> 2

7. length('中国')

  -> 6

8.  concat('my','s','ql');

  -> mysql

9.  select concat('my',null,'sql');

  -> null

10. select concat('my','sql');

  -> mysql

11. select locate('bar','foobar');

  -> 4

12. select instr('foobar','bar');

  -> 4

 

13. select lpad('00','10','1');

  -> 1111111100

14.  select rpad('00','10','1');

  -> 0011111111

15. select left('1234567',3);

  -> 3

16. select substring('1234567890',1,2); #  = mid

  -> 2

17. select char_length( trim('    1   '));

  -> 1

18. select trim(leading 'x' from 'xxx1xxx');

  -> 1xxx

19. select trim(trailing 'x' from 'xxx1xxx');

  -> xxx1

20. select trim(both 'x' from 'xxx1xxx');

  -> 1

21. select char_length( space(6) );

  -> 6

22. select repeat('a',3);

  -> aaa

23. select reverse('abc');

  -> cba

24. select lcase('ABC');

  -> abc

25. select upper('abc');

  -> ABC

26. select now();

  -> ==  select sysdate();

27. select curdate();  

  -> select current_date();

28. select curtime();

posted @   丝滑课  阅读(139)  评论(0编辑  收藏  举报
编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?
点击右上角即可分享
微信分享提示