Germany's SAP AG said it plans to buy smaller business software maker Sybase Inc for $5.8 billion, gaining technology that allows it to deliver accounting software and other programs to smartphones.

The acquisition would be the second largest in SAP's nearly 40-year history, and comes after the departure in February of Chief Executive Leo Apotheker, who was replaced by co-CEOs Bill McDermott and Jim Hagemann Snabe.

SAP's main rival, Oracle Corp , was the first major software maker to aggressively pursue acquisitions and has spent more than $42 billion to buy about 60 companies.

SAP finally learned that they should take some clues from Oracle's playbook. They finally woke up, said Trip Chowdhry, an analyst with Global Equities Research. They are late, but late is better than never.

California-based Sybase sells programs that make it easy for workers to access business software via smartphones and other mobile devices. SAP already uses the technology to let customers access its applications when they are on the road.

We want to make sure SAP solutions can be accessed from all leading mobile devices. The acquisition of Sybase will allow us and our partners to do just that, SAP's Snabe said on a conference call.

SAP has agreed to pay $65 per share in cash for Sybase, which is the world's No. 4 provider of database software, the companies said. That represents a 56 percent premium to Sybase's Tuesday closing price on the New York Stock Exchange.

Sybase shares rose to $64.50 in extended trade, after having climbed 35 percent to $56.14 on the NYSE after Bloomberg's report that SAP was planning to buy Sybase.

Sybase also sells a powerful database that large companies, such as banks, use to store sensitive information. It is the fourth-largest maker of database software after Oracle, IBM and Microsoft Corp .

Oracle declined comment, while Microsoft and IBM could not immediately be reached.

MOBILE SOFTWARE

Jefferies & Co analyst Ross MacMillan said Sybase's most valuable asset is its mobile software because it will give SAP an edge over Oracle when it comes to allowing customers to use business management programs on the go.

Those products only accounted for about 27 percent of Sybase's $403 million in software sales last year. The bulk of revenue came from Sybase's database, which is rarely used in conjunction with SAP's software products.

MacMillan said it was not clear how the Sybase database would fit into the rest of SAP's business of selling software for managing business tasks, such as accounting, human resources and manufacturing.

The question I have is: what's the plan with the database business? Reading between the lines, it's not really growing, but it's highly profitable, MacMillan said.

SAP said that it would fund the deal with cash on hand and a 2.75 billion euro loan facility.

The companies said they expect the transaction to close during the third quarter, immediately adding to SAP's earnings.

SAP's U.S. shares edged lower in extended trade to $44.50 from their close of $44.90.

Deutsche Bank and Barclays advised SAP, while Bank of America Merrill Lynch advised Sybase.

SAP's biggest acquisition to date is its $6.8 billion purchase of Business Objects in 2008.

(Reporting by Jim Finkle. Editing by Robert MacMillan, Leslie Gevirtz and Carol Bishopric)