Un tableau PL/SQL
-- table de multiplication
par 8 et par 9...
declare
type tablemul is record ( par8 number,
par9 number);
type tabledentiers is table of tablemul index by binary_integer;
ti tabledentiers;
i number;
begin
for i in 1..10 loop
ti(i).par9 := i*9 ;
ti(i).par8:= i*8;
dbms_output.put_line (i||'*8='||ti(i).par8||' '||i||'*9='||ti(i).par9
);
end loop;
end;
/
--
on va lire les salaires de emp...
declare
type tsal is table of emp.sal%type index by binary_integer;
tasal tsal;
i number;
cursor cur is select sal from emp;
begin
open cur;
i :=1;
loop
exit when cur%notfound;
fetch cur into tasal(i) ;
dbms_output.put_line ('salaire ...'||tasal(i));
i := i + 1;
end loop;
end;
/
nom_table_sql.COUNT | retourne le nombre d’élements de la table |
nom_table_sql.DELETE | supprime toute la table |
nom_table_sql.DELETE (n) | supprime l’élément n |
nom_table_sql.DELETE (n,m) | supprime les éléments de n à m |
nom_table_sql.EXISTS (n) | retourne TRUE si l’élément n existe |
nom_table_sql.FIRST | retourne le premier index |
nom_table_sql.LAST | retourne la valeur du dernier index |
nom_table_sql.NEXT(n) | élément suivant |
nom_table_sql.PRIOR(n) | élément précédent |
declare
type tsal is table of emp.sal%type index by binary_integer;
tasal tsal;
i number;
cursor cur is select sal from emp;
begin
open cur;
i :=1;
loop
exit when cur%notfound;
fetch cur into tasal(i) ;
i := i + 1;
end loop;
close cur;
dbms_output.put_line ('premier élément : '||tasal(tasal.FIRST)
);
dbms_output.put_line ('dernier élément : '||tasal(tasal.LAST)
);
dbms_output.put_line ('nombre d élément : '||tasal.COUNT);
dbms_output.put_line ('suppresion des éléments '||tasal.next(1)||'
à '||tasal.prior(tasal.COUNT));
tasal.delete(2,tasal.COUNT-1);
dbms_output.put_line ('nombre d élément : '||tasal.COUNT);
end;
/
|