Tuesday, May 12, 2009

Oracle Package - Basics

Here is a sample of oracle package in which I will send startIndex as integer and endIndex as integer. In returns it will return me customer list

create or replace PACKAGE BODY PKG_GET_THANKYOU_customer_LIST AS

procedure getThankyouNames(startIndex IN number, endIndex in number,myMethodCode in varchar2, out_cursor OUT Thank_Cur) AS

localThank_Cursor Thank_cur;
BEGIN
/* TODO implementation required */
/* delete from temp_ty; */
insert into temp_thankyou_cust_list
select t3.customer_sid, ws1.order_sid, t2.order_code,max(ws1.order_date) order_date, rnum,t3.cust_company_name,
t3.cust_name,t3.cust_title, t3.cust_Phone, t3.cust_phone_ext, t3.cust_fax, t3.cust_STREET_ADDR_LINE1,
t3.cust_STREET_ADDR_LINE2,t3.cust_CITY,t3.cust_ZIP_CODE,t3.cust_ZIP_PLUS4,t3.cust_STATE_CODE,
t3.MY_METHOD_CODE
from work_table_order t2, work_spec_table ws1,
(select * from
(select t1.*, rownum rnum from
(select distinct c1.customer_sid, c1.cust_company_name, c1.cust_name,
c1.cust_title, c1.cust_Phone, c1.cust_phone_ext, c1.cust_fax,
c1.cust_STREET_ADDR_LINE1, c1.cust_STREET_ADDR_LINE2, c1.cust_CITY,
c1.cust_ZIP_CODE,c1.cust_ZIP_PLUS4,c1.cust_STATE_CODE,c1.RPC_METHOD_CODE
from customer c1, work_productive_order wp1
where c1.MY_METHOD_CODE = myMethodCode and c1.customer_sid = wp1.customer_sid
and wp1.customer_sid not in (select customer_sid from thankyou_customers)
order by c1.customer_sid
) t1
where rownum <= endIndex
)
where rnum >= startIndex
) t3
where t2.customer_sid = t3.customer_sid and ws1.order_sid = t2.order_sid
group by ws1.order_sid,t2.order_code, t3.customer_sid, rnum, t3.cust_company_name, t3.cust_name,
t3.cust_title, t3.cust_Phone, t3.cust_phone_ext, t3.cust_fax, t3.cust_STREET_ADDR_LINE1,
t3.cust_STREET_ADDR_LINE2,t3.cust_CITY,t3.cust_ZIP_CODE,t3.cust_ZIP_PLUS4,t3.cust_STATE_CODE,t3.MY_METHOD_CODE;
open localThank_Cursor for
select ty1.*, substr(ws1.text_description,1,50)
from temp_thankyou_cust_list ty1, work_spec_table ws1
where ty1.order_sid = ws1.order_sid and ty1.order_date = ws1.order_date
order by ty1.customer_sid, ty1.order_code;
out_cursor := localThank_Cursor;

END getThankyouNames;

END PKG_GET_THANKYOU_cust_LIST;

No comments:

Post a Comment