MySQL - Replace Character in Columns

后端 未结 4 1353
离开以前
离开以前 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:13

    Just running the SELECT statement will have no effect on the data. You have to use an UPDATE statement with the REPLACE to make the change occur:

    UPDATE photos
       SET caption = REPLACE(caption,'"','\'')
    

    Here is a working sample: http://sqlize.com/7FjtEyeLAh

    0 讨论(0)
  • 2020-11-29 20:16

    If you have "something" and need 'something', use replace(col, "\"", "\'") and viceversa.

    0 讨论(0)
  • 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
    
    0 讨论(0)
  • 2020-11-29 20:35

    maybe I'd go by this.

     SQL = SELECT REPLACE(myColumn, '""', '\'') FROM myTable
    

    I used singlequotes because that's the one that registers string expressions in MySQL, or so I believe.

    Hope that helps.

    0 讨论(0)
提交回复
热议问题