Is Oracle (ORCL -6.63%) stock a buy now? That's a more complicated question than you might think.

At first blush, some investors might overlook this throwback tech stock, assuming that it wouldn't have performed well in the age of artificial intelligence (AI). That would be a mistake: Over the last three years, Oracle stock has been an excellent investment. Not only has it outperformed the S&P 500 and Nasdaq Composite handily, it has also outpaced some of the most prominent stocks within those indexes.

Take Microsoft, for example. As of this writing, its shares have generated a total return of 34% over the last three years -- more or less matching the total returns of both the S&P 500 and Nasdaq Composite. However, Oracle has generated a total return of 97%.

ORCL Total Return Level Chart

ORCL Total Return Level data by YCharts.

The reason behind the rally

Clearly, Oracle has been an outperformer. But why?

In short, the answer comes down to one thing: AI infrastructure demand. As the demand for AI services has taken off, so has the demand for the data centers used to run the latest AI applications. Oracle, as one of the world's leading providers of data center servers, has benefited as the need for high-powered, cutting-edge servers has increased. It also operates its own major network of cloud data centers.

In its fiscal 2025 third quarter, which ended on Feb. 28, Oracle's revenue increased 6% year over year to $14.1 billion. However, cloud services revenue jumped by 23% to $6.2 billion, nearly 44% of its total revenue.

In addition, the company noted it holds a significant sales backlog, as evidenced by signed sales contracts with Meta Platforms, Nvidia, AMD, OpenAI, and xAI, which should drive further revenue expansion in 2025.

Moreover, Stargate -- a private joint venture between OpenAI, SoftBank, and Oracle that they announced earlier this year -- could act as an additional catalyst as it is expected to further boost demand for AI training and inference. The three tech companies plan to invest up to $500 billion in building as many as 20 large AI data centers in the U.S. by 2029.

Is Oracle stock a buy now?

While skyrocketing AI demand may seem to make Oracle a screaming buy right now, there are risks to investing in it. First off, the company is spending heavily to expand its data center network. As a result, its free cash flow has dipped over the last year even as its revenue and net income have grown.

Second, any slowdown or pullback in AI spending by major players could result in a deceleration in Oracle's growth. Given that it's only growing revenue at a 6% annual clip, it doesn't have much wiggle room.

On the other hand, the stock's valuation paints a different picture. As of this writing, Oracle's trailing 12-month price-to-earnings (P/E) ratio stands at 36, which is down significantly from its recent three-year high of nearly 50. What's more, its current P/E is only slightly above its three-year average of 34.

To sum up, Oracle is an under-the-radar pick within the AI stock space. For investors who believe in the long-term growth story behind AI data center demand, Oracle could be a name worth considering.