Stocks rose slightly on Thursday as better-than-expected earnings by Wal-Mart Stores Inc helped offset gloomy government numbers on retail sales and jobs.

Shares of Wal-Mart, the world's largest retailer, were up 2.6 percent to $51.82 following its second-quarter earnings and its outlook for the full year.

The retail sector, however, was mostly lower after the U.S. Commerce Department reported retail sales fell 0.1 percent in July, defying the market's expectation of a 0.7 percent gain. Analysts had expected a boost to retail sales from the government's cash for clunkers program.

Government data also showed the number of workers filing first-time applications for unemployment benefits rose by 4,000 to a seasonally adjusted 558,000. Economists had anticipated a drop in first-time jobless claims.

Stocks appeared set for a solid advance before the release of the government data.

First you had the initial claims number - everybody is talking about 'it's over,' but this was worse than expected and actually worse than last month, said Doug Roberts, chief investment strategist at Channel Capital in Shrewsbury, New Jersey.

More important was retail sales, and if you take out cars for clunkers, was much more negative than people expected. So it's throwing a little bit of doubt, Roberts added.

The Dow Jones industrial average <.DJI> gained 2.64 points, or 0.03 percent, to 9,364.25. The Standard & Poor's 500 Index <.SPX> rose 2.43 points, or 0.24 percent, to 1,008.24. The Nasdaq Composite Index <.IXIC> added 3.82 points, or 0.19 percent, to 2,002.54.

Financial stocks were among the bright spots, a day after hedge fund manager John Paulson -- who had made a fortune betting against financial companies after foreseeing the credit crisis -- disclosed that he had bought large stakes in several banks.

Bank of America shares gained 5.2 percent to $16.76 and the KBW Bank index <.BKX> gained 2.4 percent.

Stocks briefly extended gains at midday after a 30-year U.S. Treasury bond auction was well received, providing a boost to confidence in U.S. assets including stocks.

Homebuilder shares fell on a string of downgrades, with D.R. Horton Inc down 4.7 percent to $12.82 after Citigroup cut its rating. KB Home fell 2.8 percent to $17.77 after a downgrade by Raymond James.

The Dow Jones U.S. Home Construction index <.DJUSHB> shed 1.8 percent.

(Reporting by Chuck Mikolajczak; Editing by Kenneth Barry)