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 @ 2015-06-13 09:40  丝滑课  阅读(151)  评论(0)    收藏  举报