2017-02-10 133 views
1

下午好! 反正我正在嘗試,但我似乎無法得到一個選項卡在火鳥varchar的結尾。 有誰知道該怎麼做?從Firebird中刪除表格

在此先感謝。

編輯留下更具體的:

例:

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 
+0

爲什麼在沒有聚合函數(例如MAX,SUM,COUNT)時執行GROUP BY?另外,一般的GROUP BY規則指出:如果指定了GROUP BY子句,則SELECT列表中的每個列引用必須標識分組列或作爲set函數的參數! – jarlh

+0

我不清楚問題是什麼。你能否添加更多信息?因爲你說_「我似乎無法得到一個varchar末尾的選項卡」_,但是其餘的描述似乎表明了相反的情況(即:要刪除製表符)。請注意,真正的解決方案是防止這些角色首先進入數據庫。 –

+0

這正是我告訴我的老闆......但他希望這樣做......我需要重新記錄字段選項卡,所以通過看到相同的註冊併成爲一行。但是對於選項卡,字符大小因行而異...... – sounobre

回答

0

如果要刪除值末尾的選項卡,可以使用幾個選項:

  • 使用TRIM有一個明確的字符串

    trim(trailing ascii_char(9) from theColumn) 
    

    9是製表符。此解決方案假定最後沒有空格和製表符的組合。

  • 爲了解決以前的解決方案的不足,使用REPLACE用空格替換選項卡,然後修剪:

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

然而,最好的辦法是通過更新它來淨化你的數據,並更改您的應用程序,以便這些尾隨製表符(和空格)不會在數據庫中結束。或者,你可以添加一個觸發器,爲你做到這一點。