How to avoid querying the same table two times.
921556Mar 27 2012 — edited Mar 28 2012Hi all,
I am wondering if any one can tell me a better way to do what I am trying to do.
I am querying a table twice to get some values before I insert into the same table.
I am pretty sure there is a better way to do this.
select nvl(max(pd.line_no), 0) + 1
into p_new_line_no
from po_details pd
where pd.event_id = p_event_id;
select pd.cause, pd.cause_code
into l_cause, l_cause_code
from po_details pd
where pd.po_number = p_po_number
and pd.comp_code = p_comp_code
group by pd.comp_code;
insert into po_details
(qty, cost, cause, cause_code, line_no)
select p_qty, p_cost, l_cause, l_cause_code, p_new_line_no);
Thanks.