# 差異比較

|           | SQL Server                                        | Oracle                                                     |
| --------- | ------------------------------------------------- | ---------------------------------------------------------- |
| SQL風格     | T-SQL                                             | PL/SQL                                                     |
| 查詢當前日期和時間 | SELECT GETDATE(), SYSDATETIME()                   | SELECT SYSDATE, SYSTIMESTAMP FROM dual                     |
| 格式化日期和時間  | CONVERT() or FORMAT()                             | to\_char() (近似convert()，但側重轉為字串)                           |
|           | SELECT FORMAT(getdate(), 'd', 'en-gb')            | SELECT to\_char(sysdate, 'MM/DD/YY HH24:MI:SS') FROM dual; |
|           | SELECT FORMAT(getdate(), 'MM/dd/yy hh:mm.ss')     |                                                            |
|           | SELECT CONVERT(varchar(8), getdate(), 112) (\*註1) |                                                            |
| 最小日期      | DATETIME (1753/1/1)                               | DATE(公元前4712/1/1)                                          |
|           | DATETIME2(0001/1/1)                               |                                                            |
|           |                                                   |                                                            |
|           |                                                   |                                                            |
|           |                                                   |                                                            |
|           |                                                   |                                                            |
|           |                                                   |                                                            |
|           |                                                   |                                                            |
|           |                                                   |                                                            |
|           |                                                   |                                                            |
|           |                                                   |                                                            |
|           |                                                   |                                                            |
|           |                                                   |                                                            |
|           |                                                   |                                                            |
|           |                                                   |                                                            |
|           |                                                   |                                                            |
|           |                                                   |                                                            |

註1:[https://docs.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql](https://docs.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql)

|      | ISNULL | COALESCE |
| ---- | ------ | -------- |
| ANSI | X      | O        |
| 速度   | fast   | slow     |
|      |        |          |
