strleft

Description

Syntax

VARCHAR STRLEFT (VARCHAR str, INT len)

It returns the left part of a string of specified length, length is char length not the byte size. Another alias for this function is left. If the function parameters contain a NULL value, the function will always return NULL. If the integer parameter is less than or equal to 0, it will return an empty value.

example

  1. mysql> select strleft("Hello doris",5);
  2. +------------------------+
  3. | strleft('Hello doris', 5) |
  4. +------------------------+
  5. | Hello |
  6. +------------------------+
  7. mysql> select strleft("Hello doris",-5);
  8. +----------------------------+
  9. | strleft('Hello doris', -5) |
  10. +----------------------------+
  11. | |
  12. +----------------------------+
  13. mysql> select strleft("Hello doris",NULL);
  14. +------------------------------+
  15. | strleft('Hello doris', NULL) |
  16. +------------------------------+
  17. | NULL |
  18. +------------------------------+
  19. mysql> select strleft(NULL,3);
  20. +------------------+
  21. | strleft(NULL, 3) |
  22. +------------------+
  23. | NULL |
  24. +------------------+

keywords

  1. STRLEFT, LEFT