开发者

Extra spaces being added at the tail in the column

When I am saving data into a table, extra spaces being added to the valued at the tail. I observed that开发者_高级运维 as the column length is 5, if I am inserting a value of 3 char length, 2 extra spaces are being added. Can any one how to solve this problem.


Is the column type CHAR(5) instead of VARCHAR(5)?

  • CHAR(x) creates a column that always stores x characters, and pads the data with spaces.
  • VARCHAR(x) creates a column that varies the lengths of the strings to match the data inserted.


This is a property of CHAR data type. If you want no extra spaces, you need to use VARCHAR although for a small field there is a minimal overhead compared to standard CHAR. Having said that, it is believed that VARCHAR nowadays is as good as CHAR.


CHAR variables will store this extra padding, maybe you need to be using VARCHAR2 variables instead?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜