在列的尾部添加额外的空格
当我将数据保存到表中时,额外的空格会添加到尾部的值中。我观察到,由于列长度为 5,如果我插入 3 个字符长度的值,则会添加 2 个额外空格。任何人都可以如何解决这个问题。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
列类型是
CHAR(5)
而不是VARCHAR(5)
吗?CHAR(x)
创建一个始终存储 x 个字符的列,并用空格填充数据。VARCHAR(x)
创建一个列,该列会改变字符串的长度以匹配插入的数据。Is the column type
CHAR(5)
instead ofVARCHAR(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.这是
CHAR
数据类型的属性。如果您不需要额外的空格,则需要使用VARCHAR
,尽管对于小字段来说,与标准CHAR
相比,开销很小。话虽如此,现在我们相信VARCHAR
与CHAR
一样好。This is a property of
CHAR
data type. If you want no extra spaces, you need to useVARCHAR
although for a small field there is a minimal overhead compared to standardCHAR
. Having said that, it is believed thatVARCHAR
nowadays is as good asCHAR
.CHAR 变量将存储这个额外的填充,也许您需要使用 VARCHAR2 变量?
CHAR variables will store this extra padding, maybe you need to be using VARCHAR2 variables instead?