Example 10-10: Improved procedure returning XML stock quotes

CREATE PROCEDURE XMLQuotesForStocksInPortfolio( id NUMBER ) IS
  -- Select all stocks for the user with id passed in
  CURSOR c_QuotesForUserid( cp_Userid NUMBER )
      IS SELECT q.symbol, q.price, q.change
           FROM quotes q, portfolio_stocks ps
          WHERE q.symbol = ps.symbol
            AND ps.owner = cp_Userid;
BEGIN
  xmlhelper.prolog;
  xmlhelper.startTag('Quotes');
  FOR curQuote IN c_QuotesForUserid( id )
  LOOP
    xmlhelper.startTag('Quote');
    xmlhelper.tag('Symbol', curQuote.symbol);
    xmlhelper.tag('Price',  curQuote.price);
    xmlhelper.tag('Change', curQuote.change);
    xmlhelper.endTag('Quote');
  END LOOP;
  xmlhelper.endTag('Quotes');
END XMLQuotesForStocksInPortfolio;