

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 使用 建立預備陳述式 AWS CLI
<a name="querying-with-prepared-statements-creating-prepared-statements-using-the-aws-cli"></a>

若要使用 AWS CLI 建立預備陳述式，您可以使用下列其中一個`athena`命令：
+ 使用 `create-prepared-statement` 命令並提供具有執行參數的查詢陳述式。
+ 使用 `start-query-execution` 指令並提供使用 `PREPARE` 語法的查詢字串。

## 使用 create-prepared-statement
<a name="querying-with-prepared-statements-cli-using-create-prepared-statement"></a>

在 `create-prepared-statement` 命令中，在 `query-statement` 引數中定義查詢文字，如以下範例所示。

```
aws athena create-prepared-statement 
--statement-name PreparedStatement1 
--query-statement "SELECT * FROM table WHERE x = ?" 
--work-group athena-engine-v2
```

## 使用 start-query-execution 和 PREPARE 語法
<a name="querying-with-prepared-statements-cli-using-start-query-execution-and-the-prepare-syntax"></a>

使用 `start-query-execution` 命令。將 `PREPARE` 陳述式放置在 `query-string` 引數中，如以下範例所示：

```
aws athena start-query-execution 
--query-string "PREPARE PreparedStatement1 FROM SELECT * FROM table WHERE x = ?" 
--query-execution-context '{"Database": "default"}' 
--result-configuration '{"OutputLocation": "s3://amzn-s3-demo-bucket/..."}'
```