I’ve been working on improving the performance of a stored procedure and there is a big slow down due to having to run four very similar updates.
I’ve found information on similar troubles in MySql which was helpful but I could not implement what I had learned, perhaps Oracle operates differently.
Among the things I’ve tried are; a batch insert through merge, creating a secondary temp_table and working with no temp tables at all but there has been no improvement.
Being new to Oracle it’s entirely possible I’m just going about it the wrong way.
Any advice or answers or directions to answers would be greatly apreciated as I’ve run out of ideas and working now with nothing but brute force and ignorance.
UPDATE TEMP_TABLE TI SET T.ItemPrice_One =
(
SELECT ItemPrice
FROM Temp.View_Items V
WHERE V.Item_Name = 'Item_Name_One'
AND V.ID = T.ID
AND V.Date = T.Date
);
UPDATE TEMP_TABLE TI SET T.ItemPrice_Two =
(
SELECT ItemPrice
FROM Temp.View_Items V
WHERE V.Item_Name = 'Item_Name_Two'
AND V.ID = T.ID
AND V.Date = T.Date
);
UPDATE TEMP_TABLE TI SET T.ItemPrice_Three =
(
SELECT ItemPrice
FROM Temp.View_Items V
WHERE V.Item_Name = 'Item_Name_Three'
AND V.ID = T.ID
AND V.Date = T.Date
);
What you’re trying to do is essentially a pivot operation — turning multiple row values into multiple column values in a single row. Below is one method using a common technique in Oracle for doing pivot queries (untested but I think it should work as-is). As of version 11g there is a built-in PIVOT operation, but I have not really looked at it yet — it may be a more direct method of doing what you need.