1

I am trying to write a trigger in Oracle 9i that will create some dynamic insert statements based on the values from the NEWROW that fired the trigger.

I need to pass the value of two fields from the new row to an existing function that returns a table of values (this function already exists and works fine). Basically the function splits the string into table rows.For example, if the two values I pass are 'Shirt,Sweater' and 'Red,Blue' I get back two tables. The first table has the values:

Shirt
Sweater

and the second table has the values

Red
Blue

Pretty simple. Once these two tables are returned I need to create some dynamic insert statements based on the values from these two table like so:

insert into mytable values ('Shirt','Red')
insert into mytable values ('Shirt','Blue')
insert into mytable values ('Sweater','Red')
insert into mytable values ('Sweater','Blue')

It is not necessary that I use the existing function. If the string can be split into arrays withing this trigger and have the same end results that also works.

Any help in this would be great appreciated. Thanks.

1 Answer 1

3

You want all possible combinations of the array elements, in other words?

FOR i in 1 .. clothing.count LOOP
    FOR j in 1 .. colors.count LOOP
        INSERT INTO mytable VALUES ( clothing(i), colors(j) );
    END LOOP;
END LOOP;
Sign up to request clarification or add additional context in comments.

Comments

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.