Avoiding frequent call to same view inside a Oracle procedure

僤鯓⒐⒋嵵緔 提交于 2021-01-29 18:11:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!