0

在我的包装规格中,我放了:

type table_info is record (table_name varchar2(20), col_info c_info);

在我身体的申报区,我有:

t_info table_info := table_info();

当我编译时,我得到:

错误:PLS-00222:此范围内不存在名称为“TABLE_INFO”的函数

有什么错误?

4

1 回答 1

1

您不需要初始化记录类型的变量:

SQL> DECLARE
  2     TYPE typ_rec IS RECORD (a NUMBER, b NUMBER);
  3     rec typ_rec;
  4  BEGIN
  5     rec.a := 1;
  6     rec.b := 2;
  7     dbms_output.put_line(rec.a + rec.b);
  8  END;
  9  /

3

PL/SQL procedure successfully completed

但是,如果您使用的是嵌套记录表,则需要初始化集合:

SQL> DECLARE
  2     TYPE typ_rec IS RECORD (a NUMBER, b NUMBER);
  3     TYPE typ_tab IS TABLE OF typ_rec;
  4     tab typ_tab := typ_tab(); -- initialization
  5  BEGIN
  6     tab.extend;
  7     tab(1).a := 1;
  8     tab(1).b := 2;
  9     dbms_output.put_line(tab(1).a + tab(1).b);
 10  END;
 11  /

3

PL/SQL procedure successfully completed

您可以混合记录类型和集合类型(不需要初始化 varray):

SQL> DECLARE
  2     TYPE column_info IS RECORD(
  3        col_name  VARCHAR2(20),
  4        col_value VARCHAR2(1000)
  5     );
  6     TYPE c_info IS VARRAY(10) OF column_info;
  7     TYPE table_info IS RECORD(
  8        table_name VARCHAR2(20),
  9        col_info   c_info
 10     );
 11     l_table  table_info;
 12  BEGIN
 13     l_table.table_name := 'TABLE_NAME';
 14     l_table.col_info.extend;
 15     l_table.col_info(1).col_name := 'COL_NAME';
 16     l_table.col_info(1).col_value := 'COL_VALUE';
 17  END;
 18  /

PL/SQL procedure successfully completed

进一步阅读:PL/SQL 集合文档

于 2013-03-06T13:07:42.457 回答