Thursday, March 8, 2018

PL/SQL - PROCEDURE Select multiple columns

create or replace procedure MUTL_GET_EMP_ADDRESS(p_segment1 in varchar2)
is
  p_address_line1 varchar2(300);
  p_city          varchar2(100);
  p_state         varchar2(300);
  p_zip           varchar2(300);
     
      CURSOR c_address IS
        SELECT   assa.address_line1,
                 assa.city,
                 assa.state,
                 assa.zip      
        FROM     ap_supplier_sites_all assa,
                ap_suppliers aps
      WHERE    assa.vendor_id = aps.vendor_id
      AND      aps.segment1 =p_segment1;
BEGIN
      OPEN c_address;
        FETCH c_address INTO p_address_line1,p_city,p_state,p_zip;
        DBMS_OUTPUT.put_line (  p_address_line1 || '-' || p_city || '-' || p_state || '-' || p_zip); 
     CLOSE c_address;
END;


--Package spec

 create or replace package  MUTL_GET_EMP_ADDRESS_PKG
Is
  procedure MUTL_GET_EMP_ADDRESS(p_segment1 in varchar2);
End MUTL_GET_EMP_ADDRESS_PKG;

--Package body

  create or replace package body MUTL_GET_EMP_ADDRESS_PKG
is
  procedure MUTL_GET_EMP_ADDRESS(p_segment1 in varchar2)
is
  p_address_line1 varchar2(300);
  p_city          varchar2(100);
  p_state         varchar2(300);
  p_zip           varchar2(300);
     
      CURSOR c_address IS
        SELECT   assa.address_line1,
                 assa.city,
                 assa.state,
                 assa.zip      
        FROM     ap_supplier_sites_all assa,
                ap_suppliers aps
      WHERE    assa.vendor_id = aps.vendor_id
      AND      aps.segment1 =p_segment1;
BEGIN
      OPEN c_address;
        FETCH c_address INTO p_address_line1,p_city,p_state,p_zip;
        DBMS_OUTPUT.put_line (  p_address_line1 || '-' || p_city || '-' || p_state || '-' || p_zip); 
     CLOSE c_address;
 END MUTL_GET_EMP_ADDRESS;
end MUTL_GET_EMP_ADDRESS_PKG;

No comments:

Post a Comment