

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

# 將具有超過 100 個引數的 Oracle 函數和程序遷移至 PostgreSQL
<a name="migrate-oracle-functions-and-procedures-that-have-more-than-100-arguments-to-postgresql"></a>

*Srinivas Potlachervoo，Amazon Web Services*

## 總結
<a name="migrate-oracle-functions-and-procedures-that-have-more-than-100-arguments-to-postgresql-summary"></a>

此模式說明如何將具有超過 100 個引數的 Oracle 資料庫函數和程序遷移至 PostgreSQL。例如，您可以使用此模式將 Oracle 函數和程序遷移至下列其中一個 PostgreSQL 相容 AWS 資料庫服務：
+ PostgreSQL 的 Amazon Relational Database Service (Amazon RDS)
+ Amazon Aurora PostgreSQL-Compatible Edition

PostgreSQL 不支援具有超過 100 個引數的函數或程序。做為解決方法，您可以定義具有符合來源函數引數之類型欄位的新資料類型。然後，您可以建立並執行使用自訂資料類型做為引數的 PL/pgSQL 函數。

## 先決條件和限制
<a name="migrate-oracle-functions-and-procedures-that-have-more-than-100-arguments-to-postgresql-prereqs"></a>

**先決條件**
+ 作用中的 AWS 帳戶
+ [Amazon RDS Oracle 資料庫 (DB) 執行個體](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_Oracle.html)
+ [Amazon RDS for PostgreSQL 資料庫執行個體](https://aws.amazon.com/getting-started/hands-on/create-connect-postgresql-db/)或 [Aurora PostgreSQL 相容資料庫執行個體](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/CHAP_GettingStartedAurora.CreatingConnecting.AuroraPostgreSQL.html)

**產品版本**
+ Amazon RDS Oracle 資料庫執行個體 10.2 版及更新版本
+ Amazon RDS PostgreSQL 資料庫執行個體 9.4 版及更新版本，或 Aurora PostgreSQL 相容資料庫執行個體 9.4 版及更新版本
+ Oracle SQL Developer 18 版及更新版本
+ pgAdmin 第 4 版及更新版本

## Architecture
<a name="migrate-oracle-functions-and-procedures-that-have-more-than-100-arguments-to-postgresql-architecture"></a>

**來源技術堆疊**
+ Amazon RDS Oracle 資料庫執行個體 10.2 版及更新版本

**目標技術堆疊**
+ Amazon RDS PostgreSQL 資料庫執行個體 9.4 版及更新版本，或 Aurora PostgreSQL 相容資料庫執行個體 9.4 版及更新版本

## 工具
<a name="migrate-oracle-functions-and-procedures-that-have-more-than-100-arguments-to-postgresql-tools"></a>

**AWS 服務**
+ [適用於 PostgreSQL 的 Amazon Relational Database Service (Amazon RDS) ](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html)可協助您在 AWS 雲端中設定、操作和擴展 PostgreSQL 關聯式資料庫。
+ [Amazon Aurora PostgreSQL 相容版本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html)是完全受管的 ACID 相容關聯式資料庫引擎，可協助您設定、操作和擴展 PostgreSQL 部署。

**其他服務**
+ [Oracle SQL Developer](https://www.oracle.com/database/technologies/appdev/sqldeveloper-landing.html) 是一種整合的開發環境，可簡化傳統和雲端部署中 Oracle 資料庫的開發和管理。
+ [pgAdmin](https://www.pgadmin.org/) 是 PostgreSQL 的開放原始碼管理工具。它提供圖形界面，可協助您建立、維護和使用資料庫物件。

## 最佳實務
<a name="migrate-oracle-functions-and-procedures-that-have-more-than-100-arguments-to-postgresql-best-practices"></a>

請確定您建立的資料類型符合來源 Oracle 函數或程序中包含的類型欄位。

## 史詩
<a name="migrate-oracle-functions-and-procedures-that-have-more-than-100-arguments-to-postgresql-epics"></a>

### 執行具有超過 100 個引數的 Oracle 函數或程序
<a name="run-an-oracle-function-or-procedure-that-has-more-than-100-arguments"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立或識別具有超過 100 個引數的現有 Oracle/PLSQL 函數或程序。 | 建立具有超過 100 個引數的 Oracle/PLSQL 函數或程序。-或-識別具有超過 100 個引數的現有 Oracle/PLSQL 函數或程序。如需詳細資訊，請參閱 Oracle 資料庫文件中的第 [14.7 節 CREATE FUNCTION 陳述式](https://docs.oracle.com/en/database/oracle/oracle-database/12.2/lnpls/CREATE-FUNCTION-statement.html#GUID-B71BC5BD-B87C-4054-AAA5-213E856651F2)和 [14.11 CREATE PROCEDURE 陳述式。](https://docs.oracle.com/en/database/oracle/oracle-database/12.2/lnpls/CREATE-PROCEDURE-statement.html#GUID-5F84DB47-B5BE-4292-848F-756BF365EC54) | Oracle/PLSQL 知識 | 
| 編譯 Oracle/PLSQL 函數或程序。 | 編譯 Oracle/PLSQL 函數或程序。如需詳細資訊，請參閱 Oracle 資料庫文件中[的編譯函數](https://docs.oracle.com/cd/E37097_01/doc.42/e35128/GUID-6B7B6F82-616D-4915-82BE-D4AE7F59CF37.htm#AEUTL165)。 | Oracle/PLSQL 知識 | 
| 執行 Oracle/PLSQL 函數。 | 執行 Oracle/PLSQL 函數或程序。然後，儲存輸出。 | Oracle/PLSQL 知識 | 

### 定義符合來源函數或程序引數的新資料類型
<a name="define-a-new-data-type-that-matches-the-source-functionapos-s-or-procedureapos-s-arguments"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 在 PostgreSQL 中定義新的資料類型。 | 在 PostgreSQL 中定義新的資料類型，其中包含出現在來源 Oracle 函數或程序引數中的所有相同欄位。如需詳細資訊，請參閱 PostgreSQL 文件中的 [CREATE TYPE](https://www.postgresql.org/docs/current/sql-createtype.html)。 | PostgreSQL PL/pgSQL 知識 | 

### 建立 PostgreSQL 函數，其中包含新的 TYPE 引數
<a name="create-a-postgresql-function-that-includes-the-new-type-argument"></a>


| 任務 | Description | 所需的技能 | 
| --- | --- | --- | 
| 建立包含新資料類型的 PostgreSQL 函數。 | 建立包含新`TYPE`引數的 PostgreSQL 函數。若要檢閱範例函數，請參閱此模式**的其他資訊**區段。 | PostgreSQL PL/pgSQL 知識 | 
| 編譯 PostgreSQL 函數。 | 在 PostgreSQL 中編譯 函數。如果新的資料類型欄位符合來源函數的 或程序的引數，則函數會成功編譯。 | PostgreSQL PL/pgSQL 知識 | 
| 執行 PostgreSQL 函數。 | 執行 PostgreSQL 函數。 | PostgreSQL PL/pgSQL 知識 | 

## 疑難排解
<a name="migrate-oracle-functions-and-procedures-that-have-more-than-100-arguments-to-postgresql-troubleshooting"></a>


| 問題 | 解決方案 | 
| --- | --- | 
| 函數會傳回下列錯誤：**錯誤：「<statement>」附近的語法錯誤** | 確定所有函數的陳述式都以分號 () 結尾`;`。 | 
| 函數會傳回下列錯誤：**錯誤：「<variable>」不是已知的變數** | 確定函數內文中使用的變數已列在函數的 `DECLARE`區段中。 | 

## 相關資源
<a name="migrate-oracle-functions-and-procedures-that-have-more-than-100-arguments-to-postgresql-resources"></a>
+ [使用 Amazon Aurora PostgreSQL](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraPostgreSQL.html) (*Amazon Aurora 使用者指南*)
+ [CREATE TYPE](https://www.postgresql.org/docs/11/sql-createtype.html) (PostgreSQL 文件）

## 其他資訊
<a name="migrate-oracle-functions-and-procedures-that-have-more-than-100-arguments-to-postgresql-additional"></a>

**包含 TYPE 引數的範例 PostgreSQL 函數**

```
CREATE OR REPLACE FUNCTION test_proc_new
(
    IN p_rec type_test_proc_args
) 
RETURNS void
AS
$BODY$
BEGIN

    /*
    **************
    The body would contain code to process the input values.
    For our testing, we will display couple of values.
    ***************
    */
    RAISE NOTICE USING MESSAGE = CONCAT_WS('', 'p_acct_id: ', p_rec.p_acct_id);
    RAISE NOTICE USING MESSAGE = CONCAT_WS('', 'p_ord_id: ', p_rec.p_ord_id);
    RAISE NOTICE USING MESSAGE = CONCAT_WS('', 'p_ord_date: ', p_rec.p_ord_date);
   
END;
$BODY$
LANGUAGE plpgsql 
COST 100;
```