

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 将含有 100 多个参数的 Oracle 函数和过程迁移到 PostgreSQL
<a name="migrate-oracle-functions-and-procedures-that-have-more-than-100-arguments-to-postgresql"></a>

*Srinivas Potlachervoo，Amazon Web Services*

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

此模式显示如何将含有 100 多个参数的 Oracle 数据库函数和过程迁移到 PostgreSQL。例如，您可以使用此模式将 Oracle 函数和过程迁移到以下与 PostgreSQL 兼容的 AWS 数据库服务之一：
+ Amazon Relational Database Service (Amazon RDS) for PostgreSQL
+ Amazon Aurora PostgreSQL 兼容版

PostgreSQL 不支持含有 100 多个参数的函数和过程。解决方法是，您可以定义一种新的数据类型，其类型字段与源函数的参数相匹配。然后，您可以创建并运行使用自定义数据类型作为参数的 PL/pgSQL 函数。

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

**先决条件**
+ 一个有效的 Amazon Web Services account
+ [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-Compatible 数据库实例](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-Compatible 数据库实例版本 9.4 及更高版本
+ Oracle SQL 开发人员版本 18 及更高版本
+ pgAdmin 版本 4 及更高版本

## 架构
<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-Compatible 数据库实例版本 9.4 及更高版本

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

**Amazon Web Services**
+ [Amazon Relational Database Service（Amazon RDS）for PostgreSQL](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_PostgreSQL.html) 可帮助您在 Amazon Web Services Cloud 中设置、操作和扩展 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>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 创建或标识具有超过 100 个参数的现有 Oracle/PLSQL 函数或过程。 | 创建参数超过 100 的 Oracle/PLSQL 函数或过程。–或者–标识具有超过 100 个参数的现有 Oracle/PLSQL 函数或过程。有关更多信息，请参阅 Oracle 数据库文档中的[第 14.7 节 创建函数语句](https://docs.oracle.com/en/database/oracle/oracle-database/12.2/lnpls/CREATE-FUNCTION-statement.html#GUID-B71BC5BD-B87C-4054-AAA5-213E856651F2)和[第 14.11 节创建过程语句](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>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 在 PostgreSQL 中定义一种新的数据类型。 | 在 PostgreSQL 中定义一种新的数据类型，该数据类型包括源 Oracle 函数或过程的参数中出现的所有相同字段。有关更多信息，请参阅 PostgreSQL 文档中的[创建类型](https://www.postgresql.org/docs/current/sql-createtype.html)。 | PostgreSQL 知识 PL/pgSQL  | 

### 创建一个包含新的 TYPE 参数的 PostgreSQL 函数
<a name="create-a-postgresql-function-that-includes-the-new-type-argument"></a>


| Task | 说明 | 所需技能 | 
| --- | --- | --- | 
| 创建一个包含新的数据类型的 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)（*适用于 Aurora 的 Amazon Aurora 用户指南*）
+ [创建类型](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;
```