【问题标题】:Hsqldb - how to remove the padding on char fieldsHsqldb - 如何删除 char 字段上的填充
【发布时间】:2010-06-01 15:28:05
【问题描述】:

我发现 Char 字段正在被填充。

有什么办法可以阻止这种情况的发生。

我尝试过使用该属性

SET PROPERTY "sql.enforce_strict_size" FALSE

但似乎没有帮助。

【问题讨论】:

    标签: hsqldb


    【解决方案1】:

    确实,MySQL docs 指定“检索 CHAR 值时,将删除尾随空格”。这很奇怪,因为其他数据库似乎总是保留填充(我可以确认对于 Oracle)。 SQL-92 standard 表示右填充空格是字符的一部分,例如在 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。

    【讨论】:

      【解决方案2】:

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

      数据类型“varchar”被定义为变量 char,它们填充空格以填充字段。

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

      【讨论】:

      • 你可能是对的,但在 mysql 中它似乎确实修剪了 char 字段。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多