2011-02-14 98 views
16

除去不需要的角色,我想從列刪除字符'

列名:

asdsdfgdfg

dfgwerwerwer

,並希望將其替換爲空格

列名稱:

ASDS dfgdfg

dfgwer werwer

+0

其實它的列數據 – 2011-02-14 10:56:06

+0

我想用空間替換那個字符使用更新查詢 – 2011-02-14 11:10:16

+1

More字符通常不是實際在您的數據庫中。它只是意味着您的軟件使用指定的字符集,在該字符集中遇到無法識別的字節序列,跳過處理並向您返回一個 字符。 – 2014-05-06 21:31:02

回答

32

這是一個Unicode replacement character。如果此字符出現在您的表中,則可能是您使用錯誤的字符集發出查詢。您應該檢查列字符集,並且還應該檢查用於發出查詢的連接的字符集。如果用於讀取和記錄數據的連接之間的連接字符集有所不同,或者用於訪問數據的應用程序/腳本之間的期望字符集有所不同,那麼這將解釋這些字符的存在。

如果你只是想用空格來代替它:

UPDATE myTable SET myColumn = REPLACE(myColumn, '�', ' ') 
+0

只是一個注意,請注意,有時你可能必須首先逃避你想要替換的字符「\」:`更新myTable SET myColumn = REPLACE(myColumn,'\\','')` – Ray 2012-12-12 16:51:16

0

執行下面的查詢來設置字符集 SET字符集「UTF-8」;

0

執行下面的查詢來設置字符集

SET CHARSET 'utf8'; 
set names 'utf8' 
7

這個SQL替換下面的字符

~ ! @ # $ %^& * () _ + 
` - = 
{ } | 
[ ] \ 
: " 
; ' 

< > ? 
, . 

SELECT note as note_original, 

    REPLACE(
     REPLACE(
      REPLACE(
       REPLACE(
        REPLACE(
         REPLACE(
          REPLACE(
           REPLACE(
            REPLACE(
             REPLACE(
              REPLACE(
               REPLACE(
                REPLACE(
                 REPLACE(
                  REPLACE(
                   REPLACE(
                    REPLACE(
                     REPLACE(
                      REPLACE(
                       REPLACE(
                        REPLACE(
                         REPLACE(
                          REPLACE(
                           REPLACE(
                            REPLACE(
                             REPLACE(
                              REPLACE(
                               REPLACE(
                                REPLACE(
                                 REPLACE(
                                  REPLACE(
                                   REPLACE(
                                    REPLACE(note, '"', ''), 
                                   '.', ''), 
                                  '?', ''), 
                                 '`', ''), 
                                '<', ''), 
                               '=', ''), 
                              '{', ''), 
                             '}', ''), 
                            '[', ''), 
                           ']', ''), 
                          '|', ''), 
                         '\'', ''), 
                        ':', ''), 
                       ';', ''), 
                      '~', ''), 
                     '!', ''), 
                    '@', ''), 
                   '#', ''), 
                  '$', ''), 
                 '%', ''), 
                '^', ''), 
               '&', ''), 
              '*', ''), 
             '_', ''), 
            '+', ''), 
           ',', ''), 
          '/', ''), 
         '(', ''), 
        ')', ''), 
       '-', ''), 
      '>', ''), 
     ' ', '-'), 
    '--', '-') as note_changed FROM invheader 
0

你可以試試這個了多列

UPDATE myTable SET myColumn1 = REPLACE(myColumn1,' ',''),myColumn2 = REPLACE(myColumn2,' ',''),myColumn3 = REPLACE(myColumn3,' ',''),... ;