spool wow.txt set serveroutput on begin for c in (select * from smstorelocations where accepted='1' order by name) Loop begin dbms_output.put_line(c.name); for s in (select g.article,g.quantity,c.name from smgoods g,smcard c where storeloc=c.id and quantity<0 and g.article=c.article) Loop begin dbms_output.put_line(s.article||' *** '||s.name||' : '||s.quantity); end; end loop; end; end loop; end; / spool off