如何将这段代码从Oracle移动到Postgres



有人能让我知道如何转换下面的代码从Oracle到Postgres数据库:

DECLARE
TYPE parametro IS RECORD
(
b1  NUMBER,
b2  NUMBER,
b3  NUMBER,
bf1  NUMBER,
bf2  NUMBER,
bf3  NUMBER
);
TYPE t_parametros IS TABLE OF parametro INDEX BY PLS_INTEGER;
matriz t_parametros;

在Postgres中,您需要声明一个Type,然后声明该类型的数组。然而,类型声明必须在模式级别,它不能在DO块(Postgres相当于Oracle匿名块)中。所以:(见demo)

create type parametro as
( b1   numeric
, b2   numeric
, b3   numeric
, bf1  numeric
, bf2  numeric
, bf3  numeric
);
-- test 
do $$
declare 
matriz parametro[];
begin
matriz[1] = ( (1),(2),(3),(4),(5),(6))::parametro ;
matriz[2] = ( (10),(20),(30),(40),(50),(60))::parametro ;   
raise notice 'Length of matriz[]: %', array_length(matriz,1); 
raise notice 'matriz[1].b1,matriz[2].b1==>: %,%', matriz[1].b1, matriz[2].b1;     
end ; 
$$;