REPLACE() 函數 (SQL REPLACE() Function)
REPLACE() 函數用來以新字串取代原字串內容。
REPLACE() 語法 (SQL REPLACE() Syntax)
SELECT REPLACE(str, from_str, to_str) FROM table_name;
函數意義為,在字串 str 中,將所有字串 from_str,取代為字串 to_str。
REPLACE() 函數查詢用法 (Example)
假設我們有一個 customers 資料表:
| C_Id | Name |
|---|---|
| 1 | Smith |
| 2 | Brad |
我們可以如此:
SELECT REPLACE(Name, 'Smith', 'ReplaceSmith') FROM customers;
返回的結果如下:
| REPLACE(Name, 'Smith', 'ReplaceSmith') |
|---|
| ReplaceSmith |
| Brad |