junni lomo
junni lomo

Reputation: 779

size in KB for a field in sql fields

I would appreciate if someone can let me know the way to find out the size of any field in KB which is returned as a result of Sql query.

For example

Select x,y from table A

Result -

x   y
x1  y1y1y1y1y1y1
x2  y2y2y2...........long string character.
x3  y3y3y3y3.........Long string character.
-
-
-
-

I am looking for

x       y
x1      10kb - Size of ( y1y1y1..) in kb
x2      100kb- Size of (y2y2y2...) in kb

any help/suggestion is deeply appreciated.

Upvotes: 0

Views: 1603

Answers (1)

This should work.

SELECT x, LENGTH(y) 
FROM table_name

Some caveats about multibyte characters. If you're using multibyte characters, think about using the VARCHAR() function instead of LENGTH().

For length in kilobytes, divide LENGTH(Y) by 1024.

SELECT x, LENGTH(y)/1024.0 
FROM table_name

Upvotes: 1

Related Questions