Oracle使用临时表调整查询

时间:2019-04-23 05:41:53

标签: oracle sql-tuning query-tuning

我想在下面提到的存储过程中删除多余的计数请求,而是想使用一个临时表并使用该临时表返回游标

procedure status(p_order_id in varchar2, p_stat out sys_refcursor) is
  l_count pls_integer;
begin
  select count(*) into l_count
  from order o
  where o.order_id=p_order_id;
  if l_count > 0 then
    -- exists in main table so only query that
    open p_stat for select o.status_code,o.order_id
      from order o
      where o.order_id=p_order_id;
  else -- does not exist in main table so only query archive
    open p_stat for select a.status_code,a.order_id
      from order_archive a where a.order_id=p_order_id;
  end if;
end status;

0 个答案:

没有答案