S&P 500 advances on boost from oil stocks, Nasdaq retreats