问题
I have a oracle view it returns 5 million records from different tables and i use this view to insert into different tables using a single procedure, inside this procedure i use this several times and this is affecting the performance, is there any way we can query the view once and later i can use it multiple places?
回答1:
A view is a stored query; itself, it doesn't contain any data. If its code is complex and fetches data from several tables, using different conditions, aggregations, whatnot, it can take some time to access data.
In your situation, maybe a global (or private; depending on Oracle version you use) temporary table (GTT) would help.
- you create it once
- at the beginning of the procedure, insert data from the view into it
- the rest of the procedure would work with those prepared data
- once the session (or transaction; depending on how you set the GTT up) is over, data from the table is lost
- the table can be reused next time you run the procedure
来源:https://stackoverflow.com/questions/63572321/avoiding-frequent-call-to-same-view-inside-a-oracle-procedure