开发者

How to populate a single-dimension array with result of a query?

开发者 https://www.devze.com 2022-12-08 17:56 出处:网络
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 NUMBERINDEX BY BINARY_INTEGER;) and i want to populate this

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 :

    sele开发者_如何学JAVAct empId where dept = 'accounts'. 

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

Thx Cshah


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;
/
0

精彩评论

暂无评论...
验证码 换一张
取 消