sql - Creating one line of output for my result using a CURSOR -
i'm successful acquire data need wish put results continuous string separated pipes here sample code
connect mgs/mgs; set serveroutput on; declare cursor product_summary_cursor select product_name ,list_price products order list_price desc; product_summary_row products%rowtype; begin product_summary_row in product_summary_cursor loop if (product_summary_row.list_price > 700) dbms_output.put_line ('"' || product_summary_row.product_name || '",' || '"' || product_summary_row.list_price || '"' || '|'); end if; end loop; end; /
depending on how many products going processing below should work. if string gets long might need @ using clob rather varchar2.
connect mgs/mgs; set serveroutput on; declare v_output_string varchar2(4000) default null; cursor product_summary_cursor select product_name ,list_price products order list_price desc; product_summary_row products%rowtype; begin product_summary_row in product_summary_cursor loop if (product_summary_row.list_price > 700) v_output_string := v_output_string || '"' || product_summary_row.product_name || '",' || '"' || product_summary_row.list_price || '"' || '|'; end if; end loop; dbms_output.put_line(v_output_string); end; /