MySQL - Replace Character in Columns

后端 未结 4 1355
离开以前
离开以前 2020-11-29 20:08

Being a self-taught newbie, I created a large problem for myself. Before inserting data in to my database, I\'ve been converting apostrophes (\') in a string, to double quot

4条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 20:30

    Replace below characters

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

    with this 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
    

提交回复
热议问题