Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 382 Vote(s) - 3.57 Average
  • 1
  • 2
  • 3
  • 4
  • 5
oracle pl/sql arrays

#1
i have some numbers which i want to store in an array. how will i declare array and assign value to it in oracle pl/sql??
Reply

#2
There are array type in PL/SQL but we can create those ourselves using the table

declare
type NumberArray is table of number index by binary_integer;
myArray NumberArray;
begin

myArray(0) := 1
myArray(1) := 2
--or use a for loop to fill
end;


[The explanation article][1]


**EDIT** :

or as *Adam Musch* said if we know the data size of data, that we are operating on, we can use `VARRAYs` that are length fixed, this is `oracle` environment, so subscripts start from `1`,

Alternative is using `VARRAY`, where array subscript starts from 1 and the length of VARRAYs is fixed.

Semantic:

declare type VarrayType is varray(size) of ElementType;

Example :

declare
type NumberVarray is varray(100) of NUMERIC(10);
myArray NumberVarray;
BEGIN
myArray := NumberVarray(1,10,100,1000,10000);

myArray(1) = 2;

for i in myArray.first..myArray.last
loop
dbms_output.put_line('myArray(' || i || '): ' || myArray(i));
end loop;
end;
END;

Output :

myArray(1) : 2
myArray(2) : 10
myArray(3) : 100
myArray(4) : 1000
myArray(5) : 10000




[1]:http://www.devshed.com/c/a/Oracle/Associative-Arrays-in-Oracle-PLSQL-Introduction/
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through