I am writing a complex Stored Procedure in ORacle that does several things, as part of a Java program with JDBC.
First, it needs to perform a very complex SELECT to read information into a cursor, with each row of the cursor denoting a lineitem for an invoice. There are about 10 columns in the output cursor. For each row of the cursor, some but not all of the fields need to be inserted into another table (called LineItem), and in addition to this I need to take the total of all those rows in the cursor and create a parent row in an Invoice table.
Would it be easier to read the cursor back into the Java app, then iterate over its contents performing INSERTS as necessary, or is it possible to do all of this within the same Stored Procedure? I am thinking multiple stored procedures should be used to avoid complexity, but am not sure if this can be done and for it all to remain as part of one transaction.
I am trying to avoid creating a super complex Stored Proc, but don’t want a dreadful solution either.
Thanks
We too have a similar situation (processing invoices and their line items) and we do the following:
We use JPA (With hibernate) and Spring for this and all the above steps are performed in a single transaction.