1. 程式人生 > 其它 >【TcaplusDB知識庫】如何在遊戲區刪除zone

【TcaplusDB知識庫】如何在遊戲區刪除zone

本題連結
表結構如下所示。

+----+--------+-----------------+------------+------------+
| id | emp_no | title           | from_date  | to_date    |
+----+--------+-----------------+------------+------------+
|  1 |  10001 | Senior Engineer | 1986-06-26 | 9999-01-01 |
|  2 |  10002 | Staff           | 1996-08-03 | 9999-01-01 |
|  3 |  10003 | Senior Engineer | 1995-12-03 | 9999-01-01 |
|  4 |  10004 | Senior Engineer | 1995-12-03 | 9999-01-01 |
|  5 |  10001 | Senior Engineer | 1986-06-26 | 9999-01-01 |
|  6 |  10002 | Staff           | 1996-08-03 | 9999-01-01 |
|  7 |  10003 | Senior Engineer | 1995-12-03 | 9999-01-01 |
+----+--------+-----------------+------------+------------+

如果僅僅是更新資料,只需使用一條UPDATE語句即可:

UPDATE titles_test
SET emp_no = '10005'
WHERE id = 5;

但本題限定必須使用REPLACE()函式,實質上是為了考察對該函式的理解。
該函式的用法請參見這裡:SQL51 查詢字串中逗號出現的次數
至此,給出本題在使用了REPLACE()函式之後的解:

UPDATE titles_test
SET emp_no = REPLACE(emp_no, 10001, 10005) # 存在從int到string的隱式轉換
WHERE id = 5;