MEXICO CITY -- Mexico, nearly broke a few years ago and burdened with the developing world's second-largest foreign debt, now faces an unusual problem: It has unexpectedly large reserves of cash and does not know how to spend it.

During a state-of-the-nation speech Tuesday, President Miguel de la Madrid confirmed that Mexico has piled up a record $14.6 billion in foreign-exchange reserves, compared to $4.5 billion a year ago and about $100 million when he took office in December 1982.

But de la Madrid gave no clue as to what the government would do with this windfall, fueling speculation about various options.

"A year ago everyone was wondering how Mexico was going to get out of the hole," said an American banker. "Now we're sitting here asking how Mexico is going to manage the excess."

Among the options is to "buy back" a portion of Mexico's $100 billion foreign debt, which is second only to Brazil's $110 billion in the developing world.

With Mexican loan paper available for about 50 cents on the dollar, the government in theory could cancel $10 billion worth of debt with an outlay of $5 billion, saving substantial interest payments.

But it is unclear how much debt is available at that price -- estimates are between $6 billion and $7 billion -- and such a buy-back would be fraught with political and financial problems, economists and bankers say.

The major dilemma facing the government is how to use the reserves without further fueling inflation, now running at an annual rate of about 130 percent.

There is a pressing need to stimulate growth in the currently stagnant economy, and labor leaders are stepping up pressure for sharp wage increases. But economic planners fear that prices could spiral out of control.

"Inflation is the biggest problem Mexico has right now," said a senior aide to de la Madrid. "We have to be careful and study what we are going to do with the reserves and when."

The windfall, which has taken government planners by surprise, was caused by a series of propitious factors. Oil price increases this year have brought in higher revenue than expected for Mexico's exports of 1.3 million barrels per day.

Whereas the average price of Mexican crude in 1986 was less than $12 a barrel, de la Madrid said Tuesday, the price during the first half of this year averaged $16, and it is now close to $20.

In addition, Mexico's nonpetroleum exports jumped 26 percent during the first half of 1987, compared to the same period last year, with exports of manufactured goods alone increasing by 46 percent to a rate of $800 million a month, de la Madrid said.

The non-oil exports, which totaled $9.7 billion during all of last year compared to $6 billion in the first six months of this year, have been helped by a decreasing exchange value for the Mexican peso.

Also boosting the reserves has been the repatriation this year of an estimated $4 billion to $5 billion held abroad -- out of total Mexican capital flight that is estimated by bankers to have reached $50 billion to $60 billion.

Much of that money undoubtedly represents the fruits of official corruption that has plagued Mexico over the years, economists say, but it also reflects the propensity of many Mexicans to salt away dollars abroad, mainly in the United States, as a hedge against inflation and economic uncertainty here.

The return of some of this money represents the increased attractiveness of peso investments in Mexico, particularly in the country's booming stock market, bankers say.

Another factor behind the high reserves has been Mexico's decision to draw on $3.5 billion of a new commercial credit facility -- money that some Mexican officials are now acknowledging was not really needed.

While the reserves can be seen as a measure of Mexico's improved economic health, bankers and economists note that they have not translated into a better standard of living for hard-pressed Mexican workers, who have seen their purchasing power decline 50 percent in the last five years.

"One of the big criticisms is that the reserves don't filter down," said a foreign banker. Thus, continuing to hold what amounts to almost an embarrassment of riches represents something of a political risk, he said.

One possible solution, recently floated by Finance Secretary Gustavo Petricioli, would be to use some of the reserves to repay foreign debt and remove at least a part of the country's debt-service burden. Currently, Mexico pays up to $700 million a month, 35 to 40 percent of the value of its exports, on its foreign debt.

"The Mexican economy could very well benefit from a token buy-back" of several billion dollars' worth of debt, a U.S. banker said. "The debt problem would not have gone away, but it would be a very encouraging token gesture that could very well attract more foreign investment to the country than it would cost in foreign reserves."

A potentially major problem is that such buy-backs currently are not allowed under the terms of Mexico's loans, and trying to buy large amounts of Mexican paper secretly through third parties would be "too transparent," as one banker put it. "I don't think Mexico would do something underhanded like that," he said.

Another option, advanced by Mexican economist Jorge Castaneda and other intellectuals here, is for the de la Madrid government to leave the reserves for his successor, who is to take office in December 1988. Such a move would free Mexico's next president from the trauma de la Madrid faced and strengthen his hand in bargaining with the country's creditors, he said. It would also "show statesmanship" and convey the "subliminal message that he didn't steal it all," Castaneda said.

According to Mexican historian Lorenzo Meyer, leaving a large amount of the reserves to the next president "could be the only way that de la Madrid can hope to redeem what has been a very gray term," marked by inflation, loss of purchasing power and years of "economic depression."

However, a senior aide to de la Madrid ruled out making such a commitment. "We cannot say we will keep this money in reserve," he said. "We don't know what might happen tomorrow."

Some observers see another possibility for Mexican officials' disposal of their reserves. "They can squander them," one banker said.