Hsqldb - 如何删除char字段上的填充

时间:2010-06-01 15:28:05

标签: hsqldb

我发现Char字段正在填充。

有没有办法阻止这种情况发生。

我尝试过使用该属性

SET PROPERTY“sql.enforce_strict_size”FALSE

但似乎没有帮助。

2 个答案:

答案 0 :(得分:0)

我认为'char'的定义是空间填充以填充该字段。它们被认为是固定长度,并且空间填充为固定长度。

数据类型'varchar'被定义为变量char,它们空间填充以填充该字段。

我可能错了,因为我通常在SQL Server上工作。

答案 1 :(得分:0)

实际上,MySQL docs指定“当检索CHAR值时,删除尾随空格”。这很奇怪,因为其他数据库似乎总是保持填充(我可以确认对于Oracle)。 SQL-92 standard表示右边填充空格是char的一部分,例如在p上的CAST函数的定义中。 148.当源(SV =源值)和目标(TV =目标值,LTD =目标数据类型的长度)时,则:

ii)  If the length in characters of SV is larger than LTD, then
     TV is the first LTD characters of SV. If any of the re-
     maining characters of SV are non-<space> characters, then a
     completion condition is raised: warning-string data, right
     truncation.

iii) If the length in characters M of SV is smaller than LTD,
     then TV is SV extended on the right by LTD-M <space>s.

也许这只是MySQL的许多odditiesgotchas中的另一个。

回答你的问题:如果你不想要尾随空格,你应该使用VARCHAR。