create or replace function get_quote_items(p_quote_id in number) return varchar2 is
  ret_items varchar2(250);
  first_item BOOLEAN := TRUE;
BEGIN
  --blank string
  ret_items := '';
   
  FOR cur_item IN (SELECT * FROM quote_items quit 
                    WHERE quit.qute_id = p_quote_id
                      AND quit.adit_code IS NOT NULL) LOOP
  
    IF first_item THEN
      ret_items := cur_item.adit_code;
      first_item := FALSE;
    ELSE --add a seperator
      ret_items := ret_items ||', '|| cur_item.adit_code;
    END IF;
  END LOOP;

  return(ret_items);
EXCEPTION
  WHEN OTHERS THEN
    --return an empty string just in case
    RETURN(NULL);
end get_quote_items;
/
