Quantcast
Channel: dBforums – Everything on Databases, Design, Developers and Administrators
Viewing all articles
Browse latest Browse all 13329

DB2 - Array /Cursor Fetch

$
0
0
Having trouble in fetching the data to an array and then inserting to the table. Can any one tell what the issue in this?


DECLARE
CURSOR c1
IS
SELECT *
FROM CUST A
FOR UPDATE;

my_record CUST.%ROWTYPE; ---this has to be an array

BEGIN
OPEN c1;

LOOP
FETCH c1
BULK COLLECT INTO my_record
LIMIT 1000; --bulk fetch is used..

DBMS_OUTPUT.PUT_LINE ('Name = ' || my_record.CODE);

FOR i IN 1 .. my_record.COUNT
LOOP
INSERT INTO CUSTOMER (XV,
CODE,
BXCODE,
FIRST_NAME,
MIDDLE_NAME,
LAST_NAME,
DATE_OF_BIRTH,
GENDER,
MOTHER_MAIDEN_NAME,
ADDRESS1,
ADDRESS2,
CITY,
COUNTRY,
HOME_PHONE)
VALUES (my_record (i).XV,
my_record (i).CODE,
my_record (i).BXCODE,
my_record (i).FIRST_NAME,
my_record (i).MIDDLE_NAME,
my_record (i).LAST_NAME,
my_record (i).DATE_OF_BIRTH,
my_record (i).GENDER,
my_record (i).MOTHER_MAIDEN_NAME,
my_record (i).ADDRESS1,
my_record (i).ADDRESS2,
my_record (i).CITY,
my_record (i).COUNTRY,
my_record (i).HOME_PHONE);
END LOOP;

EXIT WHEN c1%NOTFOUND;
END LOOP;

CLOSE c1;
END;

Viewing all articles
Browse latest Browse all 13329

Trending Articles