从 Firebird 中删除制表

Removing Tabulation from Firebird

我正在尝试,但我似乎无法在 Firebird 的 varchar 末尾获得制表符。有人知道怎么做吗?

更具体地说:

Select guia, convenio, nome, trim (matricula) from table where guia = '142'
Group by guia, convenio, nome, trim (matricula)

结果

142 | 1 | Name of patient | 111222
142 | 1 | Name of patient | 111222

但是,如果我删除注册字段,这是一个带有选项卡的 varchar(40):

Select guia, convenio, nome, matricula from table where guia = '142'
Group by guia, convenio, nome

结果是:

142 | 1 | nome do paciente

我发现问题出在注册上:

借助这个函数:char_length(matricula)

Select guia, convenio, nome, matricula, Char_Length(matricula) from table where guia = '142'
Group by guia, convenio, nome, matricula

结果:

142 | 1 | nome do paciente | 111222 | 6
142 | 1 | nome do paciente | 111222 | 10

如果您想删除值末尾的制表符,您有多种选择:

  • 使用带有显式字符串的 TRIM

     trim(trailing ascii_char(9) from theColumn)
    

    9 是制表符。此解决方案假定末尾没有 space 和制表符的组合。

  • 为了解决之前方案的不足,用REPLACE把tab换成space然后trim:

      trim(trailing from replace(theColumn, ascii_char(9), ' '))
    

然而,最好的解决方案是通过更新数据和更改应用程序来清理数据,以便这些尾随选项卡(和 spaces)不会最终出现在数据库中。或者,您可以添加一个为您执行此操作的触发器。