Hướng dẫn how do i replace a character in a column in mysql? - làm cách nào để thay thế một ký tự trong một cột trong mysql?

Thay thế các ký tự bên dưới

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

< > ?
, . 

với SQL này

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, '\"', ''],
                                                                                        '.', ''],
                                                                                    '?', ''],
                                                                                '`', ''],
                                                                            ' SELECT REPLACE['w3resource','ur','r'];
+--------------------------------+
| REPLACE['w3resource','ur','r'] |
+--------------------------------+
| w3resorce                      | 
+--------------------------------+
1 row in set [0.02 sec]

Trình bày bằng hình ảnh:

Ví dụ về hàm mysql thay thế [] với mệnh đề WHERE

Tuyên bố MySQL sau đây thay thế tất cả các lần xuất hiện của ‘K, với 'SA' trong quốc gia cột từ nhà xuất bản bảng cho các hàng đó, trong đó giá trị cột của quốc gia là Vương quốc Anh.

Code:

SELECT pub_city,country,
REPLACE[country,'K','SA'] 
FROM publisher 
WHERE country='UK';

Bảng mẫu: Nhà xuất bản

Đầu ra mẫu:

mysql> SELECT pub_city,country,
    -> REPLACE[country,'K','SA'] 
    -> FROM publisher 
    -> WHERE country='UK';
+-----------+---------+---------------------------+
| pub_city  | country | REPLACE[country,'K','SA'] |
+-----------+---------+---------------------------+
| London    | UK      | USA                       | 
| Cambridge | UK      | USA                       | 
+-----------+---------+---------------------------+
2 rows in set [0.05 sec]

Trình bày bằng hình ảnh:






example-replace-function - php mysql examples | w3resource




A list of Publishers those who belong to USA. Right column shows the name of the publisher enclosed with single quotes:

Publishers cityPublishers countryValue of Publishers country where string 'k' is replaced with 'sa':

Bài Viết Liên Quan

Chủ Đề