Subject Re: Arrays in execute block
Author Fidel Viegas
On Fri, Feb 22, 2008 at 4:02 PM, Fidel Viegas <fidel.viegas@...> wrote:
> Hello all,
>
> I am playing with the execute block statement, and I am facing some
> problems executing my code. I am using Arrays and it does not seem to
> like that. Can someone tell me what is wrong with the following code:
>
> ------------------------ begin code ------------------------------
> execute block returns (objid bigint) as
> declare vals varchar (40) [5];
> declare i integer;
> begin
> vals[1] = 'value 1';
> vals[2] = 'Value 2';
> vals[3] = 'Value 3';
> vals[4] = 'Value 4';
> vals[5] = 'Value 5';
> i = 1;
>
> while (i <= 5) do
> begin
> execute insert into objs (objid, objval) values (next value for
> obj_seq, :vals[:i]) into :objid;
> suspend;
> i = i + 1;
> end
> end
> -------------------------------------------- end code
> ------------------------------------------------------
>
> Do I need to declare set term ! ; and set term ; ! ?
>
> What is wrong with my array? It seems to be complaining about the
> array. I get a Token Unknown for '['.
>
> Hope someone can explain to me how to use arrays and execute block the
> correct way.
>
> Thanks in advance,
>
> Fidel.
>

sorry, there is a typo. It should be:

------------------------- begin code ----------------------
execute block returns (objid bigint) as
declare vals varchar (40) [5];
declare i integer;
begin
vals[1] = 'value 1';
vals[2] = 'Value 2';
vals[3] = 'Value 3';
vals[4] = 'Value 4';
vals[5] = 'Value 5';
i = 1;

while (i <= 5) do
begin
execute insert into objs (objid, objval) values (next value for
obj_seq, :vals[:i]) returning objid into :objid;
suspend;
i = i + 1;
end
end
-------------------------- end code ----------------

Thanks