1

please, is it possible to access single values in varray?

Something like newVariable := myArray(value2) --> this will assign second value in array into new varible...

I also need something like this:

FOR CYCLE...
x++
newVariable(x) := myArray(value(x))
END FOR CYCLE 

Is it possible?

Thx, I'm student of information technologies and I'm trying to solve this. Don't know where to look...

1

1 Answer 1

5

According to the oracle online documentation, the varray type is the type among other collection types in PL/SQL used for creating array like objects(I mean array as we understand it in other classic programming languages such as C, Java, etc.). Except that the length can varry from 0 to a maximum size specified during its definition.

Here is an example:

DECLARE
    SUBTYPE country_ty IS VARCHAR2(50);
    TYPE countries_varr_ty IS VARRAY(10) OF country_ty;
    l_varr_countries countries_varr_ty :=
        countries_varr_ty
        (
            'Iran', 'France', 'United Kingdom', 'United States', 'Germany',
            'Spain', 'Canada', 'Australia', 'South Africa', 'Afganistan'
        );
    l_country country_ty;
BEGIN
    FOR counter IN l_varr_countries.FIRST .. l_varr_countries.LAST
    LOOP
        l_country := l_varr_countries(counter);
        DBMS_OUTPUT.PUT_LINE('The current value in the array is: ' 
            || l_country);
    END LOOP;
END;
/

For more information on varrays you can refer to the following link:

http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/composites.htm#CHDEIJHD

Regards,

Dariyoosh

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.