I have a table in a MySQL database that I am running simple SELECT queries on (for quick diagnostics/analysis - since I am not running phpmyadmin on the server - for security reasons).
I would like to be able to truncate the returned data using something like this:
select id, LEFT(full_name, 32), age FROM user
where user is a table that contains the columns id, full_name and age
开发者_C百科I tried the above statement and it didn't work. anyone knows how to do this?
[Edit]
Sorry, when I said it dosen't work, I mean mySQL simply returns the STRING "LEFT(full_name, 32)" as an alias for the column 'full_name' and outputs the field value - which in this case, can be as long as 256 chars.
select id, SUBSTRING(full_name,1, 32), age FROM user
Quoting mysql.com:
For all forms of
SUBSTRING()
, the position of the first character in the string from which the substring is to be extracted is reckoned as 1.
select id, SUBSTRING(full_name,1, 32), age FROM user
select id, SUBSTR(full_name, 1, 32), age FROM user;
OR
select id, SUBSTRING(full_name, 1, 32), age FROM user;
OR
select id, SUBSTRING(full_name, FROM 1 FOR 32), age FROM user
Note: SUBSTR()
is a synonym for SUBSTRING()
.
found on mysql doc
精彩评论