如何创建 Oracle 全局类型并在 PL/SQL 中使用它?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12779495/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:09:20  来源:igfitidea点击:

How to create a Oracle global type and use it in PL/SQL?

oracleplsql

提问by Centurion

Oracle RECORD TYPE declared in procedure or function is local, therefore it might be used locally only. How to declare a RECORD TYPE that is global and might be used in all procedures and functions globally in DB?

在过程或函数中声明的 Oracle RECORD TYPE 是本地的,因此它只能在本地使用。如何声明一个全局的 RECORD TYPE 并且可能在 DB 中的所有过程和函数中全局使用?

回答by Nick Krasnov

Recordtypes cannot be created as a separate schema object, so to make a Recordtype publicly available the type is usually declared in a package specification, or a package body to be available only in the scope of that package.

Record类型不能作为单独的模式对象创建,因此要使Record类型公开可用,通常在包规范中声明该类型,或仅在该包的范围内可用的包主体。

回答by Gaurav Soni

A basic example of using object type in your package .

在包中使用对象类型的基本示例。

CREATE OR REPLACE TYPE test_rec IS OBJECT
(
 ID             VARCHAR2(30)
 ,TYPE               VARCHAR2(30)
);
/

CREATE OR REPLACE TYPE test_NT AS TABLE OF test_rec;
/

declare
 v_test_NT   test_NT;

begin
select test_rec (id
                ,type
                 )
        BULK COLLECT INTO v_test_NT  
 FROM test ;

--use it as you want

end;