Bed-dimensional array in PL / SQL

Dúvidas, dicas e truques de PL/SQL. Aqui também vão assuntos relacionados a pacotes, triggers, funções, Java-Stored Procedures, etc
Post Reply
rcoelho_6
Rank: Programador Júnior
Rank: Programador Júnior
Posts: 18
Joined: Tue, 04 Nov 2008 1:56 pm
Location: SP - são Paulo

Guys,

I have a silly doubt, but I will do it.

I need to create a two-dimensional array in Oracle any of the type:

Select all

int[][] field = new int[10][10]; <-- O mais parecido possivel jeito 
 
for (int i = 0; i < n*n; i++){ 
        for (int j = 0; j < n*n; j++){ 
                field[i][j] = (i*n + i/n + j) % (n*n) + 1; <-- Apenas um calculo 
        } 
}
in the truth querial something simple to manipulate like this int [] [].

could help me with opinions and examples?
PS: I'vê tried to look for something like it, but I did not find it.
ricards
Rank: Programador Sênior
Rank: Programador Sênior
Posts: 52
Joined: Sat, 29 Sep 2007 12:59 am
Location: Araraquara-SP
Contact:
Ricardo Neves
Analista e Instrutor Oracle Developer
Java Developer (JPA/JSF/Hibernate/WebServices/EJB)

Speak friend beleza !!!

follows an example of how to work with Arrays in PLSQL:

Select all

 
SET SERVEROUTPUT ON; 
 
DECLARE 
  TYPE T_ARRAY_REC IS RECORD ( 
                                COL1 NUMBER, 
 			                          COL2 VARCHAR2(50) 
                             ); 
  -- 
  TYPE T_ARRAY_TAB IS TABLE OF T_ARRAY_REC INDEX BY BINARY_INTEGER; 
  V_ARRAY T_ARRAY_TAB; 
BEGIN 
  -- POPULANDO O ARRAY 
  FOR X IN 1..3 LOOP 
    V_ARRAY(X).COL1 := X; 
    V_ARRAY(X).COL2 := 'COLUNA DA LINHA: ' || X || ' DO ARRAY'; 
  END LOOP; 
  -- LENDO O ARRAY 
  FOR I IN 1..V_ARRAY.COUNT LOOP 
     DBMS_OUTPUT.PUT_LINE('LINHA: '   ||I||  
			                    ' *COL1*: ' ||V_ARRAY(I).COL1|| 
                          ' *COL2*: ' ||V_ARRAY(I).COL2);  
  END LOOP; 
END; 
qualquer doubt there.
rcoelho_6
Rank: Programador Júnior
Rank: Programador Júnior
Posts: 18
Joined: Tue, 04 Nov 2008 1:56 pm
Location: SP - são Paulo

Then ricards,

The Record would not serve what I want, because the matrix would have to be extensible for both sides (both on and on X-axis).

As an example has the code below, which is the solution I gave to this problem, it is an array of arrays.

Only I did not like this solution that I gave, I would like something more elegant and effective.
My code:

Select all

 
declare 
  TYPE t_testtype  IS TABLE OF NUMBER INDEX BY BINARY_INTEGER; 
  TYPE t_testtype2 IS TABLE OF t_testtype INDEX BY BINARY_INTEGER; 
  v_array1 t_testtype; 
  v_array2 t_testtype2; 
begin 
  -- 
  for i in 0..9 loop 
    -- 
    for j in 0..9 loop 
      v_array1(j) := i||j ; 
    end loop; 
    -- 
    v_array2(i) := v_array1; 
    v_array1.delete; 
  end loop; 
  -- 
end; 
]
Post Reply
  • Information
  • Who is online

    Users browsing this forum: No registered users and 1 guest