sql - 从 Firebird 中删除制表

标签 sql 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 是制表符。此解决方案假定末尾没有空格和制表符的组合。

  • 为了解决之前解决方案的不足,使用REPLACE用空格替换制表符然后修剪:

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

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

关于sql - 从 Firebird 中删除制表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42157862/

相关文章:

php - 相当于 mysql_num_rows() 的 Interbase/Firebird

Firebird 2.5.1 列出服务器正在使用的数据库( super 服务器模式)

sql - Firebird(如何使用 SQL 查找父类别)

php - 仅更新 1 行 While 循环错误

sql - 在 Firebird 中,如何在过程中编写多个 if 语句?

php - 如何获得最节省 SQL PHP

MySql Join with Sum 返回错误的输出

delphi - IBquery 在执行查询时卡住主窗体 - 如何防止卡住?

sql - oracle 对象和集合

sql - 需要找出表之间的差异