Is there any function like "strlen" in mysql?
            Asked
            
        
        
            Active
            
        
            Viewed 2.9k times
        
    5 Answers
28
            Mysql does have a length function to return the length of a string.
so you could do something like.
select * from some_table where length(some_string) > 0;
 
    
    
        Robby Pond
        
- 73,164
- 16
- 126
- 119
5
            
            
        You can do it with using LENGTH keyword
SELECT * FROM table WHERE LENGTH (name) > 150;
 
    
    
        onurbaysan
        
- 1,248
- 8
- 27
4
            
            
        How to select one text column, which string length >0 ?
You could compare to the empty string:
SELECT yourcolumn
FROM yourtable
WHERE yourcolumn <> ''
 
    
    
        Mark Byers
        
- 811,555
- 193
- 1,581
- 1,452
1
            
            
        For anyone who comes across this answer in Google, keep this in mind:
Actually, CHAR_LENGTH() should be a better choice. For multi-byte charsets LENGTH() will give you the number of bytes the string occupies, while CHAR_LENGTH() will return the number of characters
1
            
            
        The following query would do the job for you.
select length(your_text_column) from sample_table where length(some_column) > 0
 
    
    
        bragboy
        
- 34,892
- 30
- 114
- 171
 
     
    