Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to update or sort data in collection?

558902Nov 21 2007 — edited Jan 27 2008
Hi all.
Below is my way to create a struct and collection

Step 1: created an object type.
CREATE TYPE department_type AS OBJECT (
DNO NUMBER (10),
NAME VARCHAR2 (50),
LOCATION VARCHAR2 (50)
);
Step 2: created a varray of the above type.
CREATE TYPE dept_array AS TABLE OF department_type;
Step 3: map this collection to an array in JAVA, and pass a collection into stored procedure.
Step 4: Cycle the data in that array
PROCEDURE insert_object (d dept_array)
AS
BEGIN
FOR i IN d.FIRST..d.LAST
LOOP
INSERT INTO department_teststruct
VALUES (d(i).dno,d(i).name,d(i).location);
END LOOP;
END insert_object;

My question is how can I update the item in that array. Can I use this way?
PROCEDURE insert_object (d dept_array)
AS
BEGIN
FOR i IN d.FIRST..d.LAST
LOOP
d(i).dno := '123';
INSERT INTO department_teststruct
VALUES (d(i).dno,d(i).name,d(i).location);
END LOOP;
END insert_object;


Best regards,
Andreas

Message was edited by:
Andreas Zhang
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 24 2008
Added on Nov 21 2007
47 comments
13,374 views