0

I have to populate the result of a query into an array in my pl/sql proc.

For example, I have a employeeId empArr (TYPE empArr IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;) and i want to populate this array with the result of a sql statement :

    select empId where dept = 'accounts'. 

Is there a way to do this ? Or would you suggest using cursors to do the job ?

Thx Cshah

1 Answer 1

6
DECLARE
  TYPE empArr IS TABLE OF NUMBER INDEX BY BINARY_INTEGER;
  myEmpArr  empArr;

BEGIN

  SELECT empID
    BULK COLLECT INTO myEmpArr
    FROM empTable
    WHERE dept='accounts';

  -- Do your stuff

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

2 Comments

I don't see where you're setting which table to perform the select statement on in the above example.
@EddiePrislac you're quite right, I left it out (maybe because I copied the query form the question which also had no table name). Fixed now.

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.