# 差異比較

|           | 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>

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://brianwu.gitbook.io/brian/zi-liao-ku/sql-ri-qi-shi-jian.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
