Apply a callback to an array: Difference between revisions

Content added Content deleted
(reverted spamming and vandalism)
No edit summary
Line 458: Line 458:
set serveroutput on
set serveroutput on
declare
declare
type myarray is table of number index by binary_integer;
type myarray is table of number index by binary_integer;
x myarray;
x myarray;
i pls_integer;
i pls_integer;
begin
begin
-- populate array
-- populate array
for i in 1..5 loop
for i in 1..5 loop
x(i) := i;
x(i) := i;
end loop;
end loop;
i :=0;
i :=0;
-- square array
-- square array
loop
loop
i := i + 1;
i := i + 1;
begin
begin
x(i) := x(i)*x(i);
x(i) := x(i)*x(i);
dbms_output.put_line(x(i));
dbms_output.put_line(x(i));
exception
exception
when no_data_found then exit;
when no_data_found then exit;
end;
end;
end loop;
end loop;
end;
end;
/
/

==[[Pop11]]==
[[Category:Pop11]]

;;; Define a procedure
define proc(x);
printf(x*x, '%p,');
enddefine;

;;; Create array
lvars ar = { 1 2 3 4 5};

;;; Apply procedure to array
appdata(ar, proc);

If one wants to create a new array consisting of transformed values
then procedure mapdata may be more convenient.



== [[Python]] ==
== [[Python]] ==