Oracle Corp., eager to boost its cloud-services strategy amid intensifying competition, agreed to buy NetSuite Inc. for about $9.3 billion.