> For the complete documentation index, see [llms.txt](https://docs.postgresql.tw/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.postgresql.tw/19/client-interfaces/ecpg/ecpg-sql-commands.md). Agents can also search and read this documentation through its [MCP server](https://docs.postgresql.tw/~gitbook/mcp).

# 34.14. 嵌入式 SQL 命令 \#

### 34.14. 嵌入式 SQL 命令 [#](#ecpg-sql-commands) <a href="#ecpg-sql-commands" id="ecpg-sql-commands"></a>

[ALLOCATE DESCRIPTOR](https://docs.postgresql.tw/19/client-interfaces/ecpg/ecpg-sql-commands/ecpg-sql-allocate-descriptor.md) — 配置 SQL 描述區

[CONNECT](https://docs.postgresql.tw/19/client-interfaces/ecpg/ecpg-sql-commands/ecpg-sql-connect.md) — 建立資料庫連線

[DEALLOCATE DESCRIPTOR](https://docs.postgresql.tw/19/client-interfaces/ecpg/ecpg-sql-commands/ecpg-sql-deallocate-descriptor.md) — 釋放 SQL 描述區

[DECLARE](https://docs.postgresql.tw/19/client-interfaces/ecpg/ecpg-sql-commands/ecpg-sql-declare.md) — 定義游標

[DECLARE STATEMENT](https://docs.postgresql.tw/19/client-interfaces/ecpg/ecpg-sql-commands/ecpg-sql-declare-statement.md) — 宣告 SQL 陳述式識別字

[DESCRIBE](https://docs.postgresql.tw/19/client-interfaces/ecpg/ecpg-sql-commands/ecpg-sql-describe.md) — 取得預備陳述式或結果集的相關資訊

[DISCONNECT](https://docs.postgresql.tw/19/client-interfaces/ecpg/ecpg-sql-commands/ecpg-sql-disconnect.md) — 結束資料庫連線

[EXECUTE IMMEDIATE](https://docs.postgresql.tw/19/client-interfaces/ecpg/ecpg-sql-commands/ecpg-sql-execute-immediate.md) — 動態準備並執行陳述式

[GET DESCRIPTOR](https://docs.postgresql.tw/19/client-interfaces/ecpg/ecpg-sql-commands/ecpg-sql-get-descriptor.md) — 從 SQL 描述區取得資訊

[OPEN](https://docs.postgresql.tw/19/client-interfaces/ecpg/ecpg-sql-commands/ecpg-sql-open.md) — 開啟動態游標

[PREPARE](https://docs.postgresql.tw/19/client-interfaces/ecpg/ecpg-sql-commands/ecpg-sql-prepare.md) — 準備陳述式以供執行

[SET AUTOCOMMIT](https://docs.postgresql.tw/19/client-interfaces/ecpg/ecpg-sql-commands/ecpg-sql-set-autocommit.md) — 設定目前工作階段的自動提交行為

[SET CONNECTION](https://docs.postgresql.tw/19/client-interfaces/ecpg/ecpg-sql-commands/ecpg-sql-set-connection.md) — 選取資料庫連線

[SET DESCRIPTOR](https://docs.postgresql.tw/19/client-interfaces/ecpg/ecpg-sql-commands/ecpg-sql-set-descriptor.md) — 在 SQL 描述區中設定資訊

[TYPE](https://docs.postgresql.tw/19/client-interfaces/ecpg/ecpg-sql-commands/ecpg-sql-type.md) — 定義新的資料型別

[VAR](https://docs.postgresql.tw/19/client-interfaces/ecpg/ecpg-sql-commands/ecpg-sql-var.md) — 定義變數

[WHENEVER](https://docs.postgresql.tw/19/client-interfaces/ecpg/ecpg-sql-commands/ecpg-sql-whenever.md) — 指定 SQL 陳述式引發特定類別條件時要採取的動作

本節說明所有嵌入式 SQL 特有的 SQL 命令。另請參閱[SQL 命令](https://docs.postgresql.tw/19/reference/sql-commands.md)中列出的 SQL 命令；除非另有說明，這些命令也可以用於嵌入式 SQL。

***

原文：[PostgreSQL 18.6 Documentation](https://www.postgresql.org/docs/18/ecpg-sql-commands.html)（原文版本：18.6；核對日期：2026-10-18）


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.postgresql.tw/19/client-interfaces/ecpg/ecpg-sql-commands.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
