3

PL/SQL の varray コレクションにテーブルの列の値を挿入したいと考えています。これについて教えてください

4

1 に答える 1

1

ここに私の試みがあります:

create table my_test ( id number,date_time date, person_id number);

Insert into my_test (ID,DATE_TIME,PERSON_ID) values (1,to_date('10-SEP-13','DD-MON-RR'),112);
Insert into my_test (ID,DATE_TIME,PERSON_ID) values (2,to_date('10-SEP-13','DD-MON-RR'),113);
Insert into my_test (ID,DATE_TIME,PERSON_ID) values (3,to_date('10-SEP-13','DD-MON-RR'),114);
Insert into my_test (ID,DATE_TIME,PERSON_ID) values (4,to_date('10-SEP-13','DD-MON-RR'),115);
Insert into my_test (ID,DATE_TIME,PERSON_ID) values (5,to_date('10-SEP-13','DD-MON-RR'),116);
Insert into my_test (ID,DATE_TIME,PERSON_ID) values (6,to_date('10-SEP-13','DD-MON-RR'),117);
Insert into my_test (ID,DATE_TIME,PERSON_ID) values (7,to_date('10-SEP-13','DD-MON-RR'),118);
Insert into my_test (ID,DATE_TIME,PERSON_ID) values (8,to_date('10-SEP-13','DD-MON-RR'),119);
Insert into my_test (ID,DATE_TIME,PERSON_ID) values (9,to_date('10-SEP-13','DD-MON-RR'),120);
Insert into my_test (ID,DATE_TIME,PERSON_ID) values (10,to_date('10-SEP-13','DD-MON-RR'),121);           

CREATE OR REPLACE TYPE integer_varray AS VARRAY(100) OF INTEGER NOT NULL;

SET SERVEROUTPUT ON
DECLARE
     varray_integer integer_varray := integer_varray();
     l_limit number;
BEGIN

select count(*) into l_limit from my_test;
     FOR i IN 1..l_limit LOOP
          varray_integer.EXTEND;

          SELECT person_id 
          INTO varray_integer(i) 
          FROM my_test WHERE ID = i;

     END LOOP;


     FOR i IN 1..l_limit loop
     dbms_output.put_line(varray_integer(i));
     END loop;
END;


anonymous block completed
112
113
114
115
116
117
118
119
120
121

またはタイプを作成せずに、次のことができます

`

DECLARE
     type integer_varray  IS VARRAY(100) OF INTEGER NOT NULL;
     varray_integer integer_varray := integer_varray();
     l_limit number;
BEGIN

... `

于 2013-09-11T07:39:17.433 に答える