The nation's foreign trade deficit shrank visibly last month, falling to $1.1 billion from $1.9 billion in June despite record oil imports, the government reported yesterday.

Meanwhile, several of the nation's leading banks boosted their prime interest rates to a record 12.25 percent, from 12 percent -- the second time in less than two weeks the rate has gone up.

The increase reflected further pressure by the Federal Reserve Board to push interest rates higher to combat inflation and bolster the dollar. The prime is the rate charged big corporate borrowers. [Story, Page D8.]

The combination of developments constituted bittersweet news for the Carter administration. Although the decline in the trade deficit was welcome, each increase in interest rates adds to the danger of a deep recession.

The improvement in the trade balance stemmed primarily from a 4.2 percent increase in U.S. exports, which more than offset the hefty boost in oil imports. Oil imports in July cost the country $4.8 billion.

Imports of all goods declined by 0.9 percent.

The July surge in exports marked the second straight month they have increased sharply. In June, exports jumped 8.5 percent, while imports rose 3.6 percent.

Yesterday's statistics bolstered predictions by some economists that the trade balance will improve significantly this year despite the rise in crude-oil prices. Last year's deficit was a record $28.5 billion.

The improvement in the trade balance reflected two developments:

The continuing deterioration in the value of the dollar finally has begun to make U.S. goods more attractive aboard, strengthening the competitiveness of American exports.

The downturn here apparently has begun to dull the American appetite for imports, which had been growing fairly rapidly until last month's surprise decline.

The July rise in exports pushed U.S. sales abroad up $631.3 million over the month to a new seasonally adjusted level of $15.67 billion. Increases were posted in seven of 10 categories.

Imports fell $160.8 million to a seasonally adjusted level of $16.78 billion. U.S. purchases of foreign goods declined in eight of 10 major categories.

The increase in petroleum imports last month amounted to 12.7 percent, outstripping an 11.5 percent rise in June. However, the figures reflected only part of the June rise in crude oil prices announced by the Organization of Petroleum Exporting Countries. More will show up in August's report.

The red ink total for July brought the trade deficit for the first seven months of this year to $12.86 billion, compared to $20.08 billion for the same period in 1978. The July deficit was the 38th month in a row.

The Carter administration last month predicted the trade deficit for the year would total around $24 billion.

The increase in the prime lending rate is expected to have repercussions throughout the economy. As interest rates push higher, the cost of doing business rises and heightens the danger of a worse recession.

Yesterday's rise in the prime rate was the second major push in interest rates engineered by Carter's new appointee as Fed chief, Paul A. Volcker. Volcker replaced G. William Miller, who has become Treasury secretary.

It has been the Fed's contention that increases in interest rates are necessary to dampen loan demand at home and to protect the dollar by persuading foreign exchange markets that the United States is serious about fighting inflation.

The White House has not protested the Fed's actions, but Carter may be in a bind soon if the central bank goes much further. Some liberal economists have warned that more increases could bring on a crunch.

Along with the other trade statistics, the Commerce Department also reported that the U.S. trade surplus with Western Europe increased to $1.2 billion in July, from $801.3 million in June.