本文介绍了如何在plsql中初始化一个矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我试图用关联数组映射一个表,但我无法弄清楚如何初始化它。

以下是一个例子:

 类型记录类型记录

value1 NUMBER,
value2 NUMBER,
value3 NUMBER
);
TYPE TblType IS RecType的表格INDEX BY PLS_INTEGER;
TYPE TblOfTblType是TblType INDEX BY PLS_INTEGER的表格;
矩阵TblOfTblType;

现在,当我试图初始化这个矩阵时:

  FOR IN IN matrix.FIRST .. matrix.LAST LOOP 
FOR j IN矩阵(i).FIRST ..矩阵(i).LAST LOOP
矩阵(i)(j):= NULL;
END LOOP;
END LOOP;

这行不通!我也试过

  matrix:= TblOfTblType()(); 

显示以下错误:


解决方案你不需要使用关联数组 - 一个集合就可以工作。

  DECLARE 
TYPE RecType IS RECORD

value1 NUMBER,
value2 NUMBER,
value3 NUMBER
);
TYPE TblType是RecType的表格;
TYPE TblOfTblType是TblType的表格;
矩阵TblOfTblType:= TblOfTblType();
BEGIN
matrix.EXTEND(3);
FOR I IN 1 .. matrix.COUNT LOOP
matrix(i):= TblType();
矩阵(i).EXTEND(4);
FOR j IN 1 ..矩阵(i).COUNT LOOP
矩阵(i)(j).value1:= i;
矩阵(i)(j).value2:= j;
矩阵(i)(j).value3:= DBMS_RANDOM.VALUE;
END LOOP;
END LOOP;

FOR i 1 .. matrix.COUNT LOOP
FOR j IN 1 .. matrix(i).COUNT LOOP
DBMS_OUTPUT.PUT('['|| matrix( i)(j).value1
||','|| matrix(i)(j).value2
||','|| matrix(i)(j).value3 ||' ]'|| CHR(11));
END LOOP;
DBMS_OUTPUT.NEW_LINE;
END LOOP;
END;
/


I've tried to Map a table with associative arrays , but i can't figure out how to initialize it

here is an example :

TYPE RecType IS RECORD
 (
  value1   NUMBER,
  value2   NUMBER,
  value3   NUMBER
 );
 TYPE TblType IS TABLE OF RecType INDEX BY PLS_INTEGER;
 TYPE TblOfTblType IS TABLE OF TblType INDEX BY PLS_INTEGER;
 matrix   TblOfTblType;

Now when i tried to initialize the matrix like this :

FOR i IN matrix.FIRST .. matrix.LAST LOOP
  FOR j IN matrix (i).FIRST .. matrix (i).LAST LOOP
       matrix(i)(j) := NULL;
  END LOOP;
END LOOP;

It doesn't work !I also tried

matrix := TblOfTblType()();

it shows the following error :

解决方案

You do not need to use an associative array - a collection will work.

DECLARE
  TYPE RecType IS RECORD
  (
    value1   NUMBER,
    value2   NUMBER,
    value3   NUMBER
  );
  TYPE TblType IS TABLE OF RecType;
  TYPE TblOfTblType IS TABLE OF TblType;
  matrix   TblOfTblType := TblOfTblType();
BEGIN
  matrix.EXTEND(3);
  FOR i IN 1 .. matrix.COUNT LOOP
    matrix(i) := TblType();
    matrix(i).EXTEND(4);
    FOR j IN 1 .. matrix(i).COUNT LOOP
      matrix(i)(j).value1 := i;
      matrix(i)(j).value2 := j;
      matrix(i)(j).value3 := DBMS_RANDOM.VALUE;
    END LOOP;
  END LOOP;

  FOR i IN 1 .. matrix.COUNT LOOP
    FOR j IN 1 .. matrix(i).COUNT LOOP
      DBMS_OUTPUT.PUT( '[' || matrix(i)(j).value1
                    || ',' || matrix(i)(j).value2
                    || ',' || matrix(i)(j).value3 || ']' || CHR(11) );
    END LOOP;
    DBMS_OUTPUT.NEW_LINE;
  END LOOP;
END;
/

这篇关于如何在plsql中初始化一个矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 22:03