LEFT()
Description
This function LEFT() returns the leftmost len characters from the string str, or NULL if any argument is NULL.
This function is multibyte safe.
Syntax
1. > LEFT(str,len)
Arguments
| Arguments | Description |
|---|---|
| str | Required. The string to extract from. |
| len | Required. The number of characters to extract. If this parameter is larger than the number of characters in string, this function will return string |
Examples
1. mysql> select left('abcde', 3) from dual;
2. +----------------+
3. | left(abcde, 3) |
4. +----------------+
5. | abc |
6. +----------------+
7. 1 row in set (0.00 sec)
9. drop table if exists t1;
10. CREATE TABLE t1 (str VARCHAR(100) NOT NULL, len INT);
11. insert into t1 values('abcdefghijklmn',3);
12. insert into t1 values(' ABCDEFGH123456', 3);
13. insert into t1 values('ABCDEF GHIJKLMN', 20);
14. insert into t1 values('ABCDEFGHijklmn ', -1);
15. insert into t1 values('ABCDEFGH123456', -35627164);
16. insert into t1 values('', 3);
17. mysql> select left(str, len) from t1;
18. +------------------+
19. | left(str, len) |
20. +------------------+
21. | abc |
22. | A |
23. | ABCDEF GHIJKLMN |
24. | |
25. | |
26. | |
27. +------------------+
28. 6 rows in set (0.01 sec)
30. mysql> select left('sdfsdfsdfsdf', len) from t1;
31. +-------------------------+
32. | left(sdfsdfsdfsdf, len) |
33. +-------------------------+
34. | sdf |
35. | sdf |
36. | sdfsdfsdfsdf |
37. | |
38. | |
39. | sdf |
40. +-------------------------+
41. 6 rows in set (0.01 sec)
