SQL PHP HTML ASP JavaScript articles and free scripts to download
SQL String Functions

Getting the actual number of characters present in a field

We can find out the length of the data or characters actually present in a field of a mysql table by using character_length function. For example we are storing titles for a image in a mysql table. We have assigned 100 as length of this varchar field. Here 100 is the maximum length of title allowed but it is not always that we will be using the total 100 characters. So how to know how many characters we have used? Now let us find out the length of the title used for the image with id 47. Here is the query

SELECT character_length(title) as no, title FROM `photo_img` where img_id=47

Without giving any where clause we can display length of the all the titles along with the title for the total table. Let us try to find out what are the titles using maximum space or the titles of maximum length. This will display records with maximum character in title field. This we will manage by using sql order by clause. Check this query.

SELECT character_length(title) as no, title FROM `photo_img` order by no desc

Be the first to post comment on this article :


Google+

Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked




HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer