After a decade of diversification, oil companies are headed back to the well.

Although some ventures remain, the oil industry clearly is retrenching and getting back to its oil and gas basics, according to industry analysts.

Take, for instance, the Sun Co., which announced that it would sell its data processing subsidiary, Sun Information Services Co. Inc. "Its business direction does not fit Sun's principal focus on energy investments," said senior vice president R. P. Hauptfuhrer.

Sun, which liked to refer to itself as "a diversified management company" during the 1970s, retains some non-energy ventures, including a couple of regional trucking firms, but earlier in the year Sun sold the assets of its Sun Ship Inc. subsidiary, a ship construction company. And in 1981 it sold Sperry-Sun, a wholly owned subsidiary in the business of manufacturing and marketing specialized oil field equipment.

In the 1970s, when oil prices were tripling and quadrupling and cash was flowing, major energy companies ventured into exotic areas in energy and outside of it. Outside of the energy field the new ventures included department stores, office systems, copper mining and biotechnology. Oil companies also felt some pressure to increase investments in the United States, and that added to the impetus for diversification.

At the same time came the realization that the oil and gas business might be as finite as oil and gas reserves. As a result, almost every major oil company began moving into solar energy, oil shale or other newfangled energy sources or started moving more actively into minerals and mining.

But that was then.

In recent years those same companies have delayed or scaled down alternate energy ventures, taken losses in mining and minerals, and have begun eliminating less profitable outside ventures.

Two major factors account for the change. One is the failure of oil prices to continue rising toward prices high enough to make alternate energy projects feasible. The other is the relative shortage of capital.

"They're sort of disowning the strategy where they would wander into alien fields," according to Alvin D. Silber, an oil industry analyst with Dean Witter Reynolds. "The oil companies are making a recommitment to traditional business. That's very much the trend."

"Cash flow was such in 1979 and 1980 that it made sense to look outside, because you couldn't invest it all in oil," said John Lichtblau of the Petroleum Industry Research Foundation. "Now the situation is completely turned around. The oil companies are even cutting expenditures on exploration and development. Now the problem is to find the cash to do the things you want to do in oil."

"Clearly there is a move to cut back on capital expenditures, and when you do that you cut back on marginal expenditures first," said Sanford Margoshes, an oil industry analyst with Bache Halsey Stuart Shields. "The areas in which you have diversified tend to be not nearly as attractive as bread-and-butter, cash flow operations," he said. As the industry pulls in its horns, "diversified projects tend to be the victims."

In addition, some of the major diversified ventures have proven major embarrassments.

"They've done very poorly. I think everyone would probably make that observation," said Silber. "Oil companies are like governments -- they're big bureaucracies. They're not very successful entrepreneurs."

"I don't think any of these have been nearly so good as oil earnings. In retrospect, it has not been such a good idea," said Lichtblau.

"I think the companies are learning that when they leave home they had better have a very good road map," said Margoshes. "Many have left home improperly prepared."

Some major diversified ventures that have not lived up to expectations are Mobil's acquisition of Montgomery Ward, Exxon's ventures with Reliance Electric Corp. and the office systems business, and some oil company mining ventures, analysts said.

In 1976, Mobil acquired Montgomery Ward and Container Corporation of America. While Container Corp. has proven a profitable venture, the department store chain distinctly has not. Retailing produced losses for Mobil of $162 million in 1980 and $160 million in 1981.

Mobil officials, who are not anxious to talk about diversification, are continually looking for a graceful way out, although that may mean hanging on long enough to produce a slight profit and turn it into a saleable commodity, according to analysts.

Exxon Corp. took aim at the office of the future with its office systems business and also acquired Reliance Electric Corp. for $1.17 billion. With Reliance, Exxon planned to produce a miracle motor that would save millions of barrels of oil.

Exxon retains Reliance, but the miracle motor regulator was a bust. Asked months ago whether Reliance was for sale, an Exxon official quipped, "Do you have a buyer?"

The office systems business initially consisted of three office products that made major inroads into the market in the 1970s. They were Qyx, an electronic typewriter; Qwip, low-cost facsimile transmission, and Vydec, word-processing equipment.

In the late 1970s, market analysts viewed the Exxon ventures as a potential $1 billion business that posed a threat to IBM and Xerox, but by 1981 the threat looked less ominous. In 1980, the loss on the company's information systems group was estimated at $150 million. In 1981, the year the three operations were pared down and consolidated into Exxon Office Systems, the loss was estimated at still over $100 million.

Next year Exxon officials say they expect the office systems operation to achieve profitability. The introduction of the Series 500 word processor, which has registered substantial gains since its introduction about six months ago, has helped boost the operation.

"Exxon Enterprises (where the diversified ventures are generally located) still very much exists," said Exxon Enterprises spokeswoman Darcie Bundy. "If there is any retrenchment, it certainly isn't going the full route."

The mining ventures, such as Standard Oil Co. of California's 20 percent share of Amax, Sohio's acquisition of the Kennecott Corp., Atlantic Richfield's acquisition of Anaconda Co. and other companies' uranium ventures, are suffering with the downturn in mining in general, but may prove profitable in the long run.

If the economy, oil prices and the oil industry's cash flow were to revive, would diversification? Alternate energy projects are likely to come back if oil prices rise high enough, and mining and coal appear sensible long-term investments, according to industry observers.

"If you're going to be a going concern, you've got to plan for well beyond the remaining lives of the board of directors. That's when you get into things like copper," said Margoshes.

"American business is often chided for being shortsighted, but people in the oil business tend to be rather forward-looking," he said. "That doesn't mean they always see clearly, but they're used to long lead-time projects."

As far as the more exotic ventures go, oil companies may continue for a long time to approach them more gingerly. That may be a good thing, according to some schools of thought.

"Unfortunately, the general American penchant for separating and simplifying has tended to encourage a diversification away from core technologies and markets to a much greater degree than is true in Europe or Japan," according to a 1980 Harvard Business Review article.

"U.S. managers appear to have an inordinate faith in the portfolio law of large numbers -- that is, by amassing enough product lines, technologies and businesses, one will be cushioned against the random setbacks that occur in life," the authors wrote. The bulk of merger activity "appears to have been absolutely wasted in terms of generating economic benefits for stockholders," they said.

The authors of the article were not focusing on oil companies in their comments, but some of what they said may be applicable.

"Most investors would prefer doing their own diversification to having oil company managers who might not be so skilled once they get out of their industry do it," said one analyst.