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 |