0

我想在另一种类型(Oracle)中的表类型中填充空值。我将只编写代码,它会更容易解释问题。

DECLARE
  TYPE type_1 is record (col_1 varchar2(255),
                         col_2 varchar2(30),
                         col_3 varchar2(3)
                        );
  TYPE table_1_tbl is table of type_1;

  TYPE table_2 is record (col_1 varchar2(255),
                          col_2 varchar2(30),
                          t1    table_1_tbl
                         );
  TYPE table_2_tbl is table of table_2;

  TYPE type_3 is record (col_1 varchar2(30),
                         col_2 VARCHAR2(19),
                         t2    table_2_tbl
                        );
  TYPE table_3_tbl is table of type_3;

  Obj table_3_tbl;

BEGIN
    select 
           'value_1', 
           'value_2',
           null
      BULK COLLECT INTO 
           Obj
      FROM dual;
END;
/

此代码导致以下结果:

Error report:
ORA-06550: line 32, column 16:
PLS-00382: expression is of wrong type
06550. 00000 -  "line %s, column %s:\n%s"
*Cause:    Usually a PL/SQL compilation error.
*Action:

如您所见,Oracle 不允许我使用 NULL 值来填充变量“obj”的“t3”列。你们知道我该怎么做吗?

注意:我不允许在架构中编译这些类型。

4

1 回答 1

0

尝试以下操作:

...
BEGIN
  obj := new table_3_tbl();
  obj.extend(1);
  obj(1).col_1 := 'value_1';
  obj(1).col_2 := 'value_2';
  obj(1).t2    := NULL;
END;
/
于 2013-08-23T14:34:53.707 回答