Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Oracle’s PL/SQL documentation and the Ask TOM example reviewed here do not establish a built-in PL/SQL IRR function. To calculate a return, implement or adopt a custom routine: use IRR for equally spaced cash flows and XIRR for cash flows paired with dates. Both calculations are numerical root-finding problems, so validate inputs and handle non-convergence explicitly.

IRR and XIRR solve different cash-flow timing problems

IRR is the rate that makes the net present value (NPV) of a periodic sequence of cash flows equal zero. The cash flows are assumed to occur at equal intervals. XIRR applies the same idea when cash flows are not necessarily periodic and each amount is associated with a date. These definitions are described in the OASIS OpenDocument Format 1.4 specification; that specification is not Oracle Database documentation.

Choice Use when Input structure
IRR Cash flows occur at regular, equal intervals An ordered sequence of amounts
XIRR Cash flows have irregular timing Amounts paired one-to-one with dates

Do not use IRR on irregularly spaced cash flows as if every step represented the same time interval. Use the dated calculation instead, preserving each amount’s association with its date.

Why PL/SQL needs a custom calculation

The Oracle sources cited here do not document a built-in PL/SQL IRR function. The practical pattern shown in a 2018 Ask TOM discussion is to pass cash-flow collections into a custom function. Its example uses collections of dates and amounts for XIRR and demonstrates populating collections from table rows with BULK COLLECT. It is a community example, not a version-certified Oracle implementation; review and adapt it for the target Oracle version and data model.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Oracle PL / SQL For Dummies
  • Used Book in Good Condition

Keep data retrieval separate from the numerical solver. That makes it easier to verify ordering and pairing, test the calculation independently, and decide how invalid input or failure to converge should be reported.

Prepare and validate the inputs

For periodic IRR

  • Supply the cash flows in chronological order as a sequence of amounts.
  • Confirm that the amounts represent equally spaced periods; the solver cannot correct a timing model that does not fit the data.
  • Ensure the sequence contains both an outflow and an inflow. If the cash flows do not change sign, a meaningful conventional return root may not exist.

For dated XIRR

  • Supply one date for each amount, and ensure the two collections have the same number of elements.
  • Keep every date attached to its corresponding amount when sorting or loading rows.
  • Include at least one positive and one negative cash flow, as required by the cited formula specification.
  • Check the date values and ordering according to the conventions chosen for your implementation.

Validate these conditions before starting iteration. Report malformed inputs distinctly from a valid calculation that cannot find a root; returning an ordinary-looking rate after a solver failure can mislead downstream users.

Use an iterative solver and treat its result carefully

The OASIS OpenDocument Format 1.4 specification states, “There is no closed form for XIRR.” It describes a numerical calculation that can depend on an initial guess and may fail to converge for a particular guess. This describes the formula standard, not a guarantee about any Oracle implementation.

That specification uses 0.1 (10%) when an IRR/XIRR guess is omitted. This is a starting estimate in that specification, not a documented default for Oracle PL/SQL. A custom routine should make its starting guess and stopping rules explicit, and should signal non-convergence rather than silently presenting an unverified value. Depending on the cash flows, a numerical routine may also need care in choosing or validating the root it returns.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Calling the calculation from SQL

A PL/SQL function called from a SQL statement is subject to Oracle’s rules for SQL-invoked functions. Oracle Database 18’s PL/SQL subprogram documentation describes restrictions on transaction control and database changes in SQL query contexts. Review the rules for the specific calling context before using a calculation function in a query; treat it as a calculation, not as a place for transaction control or database writes.

The Ask TOM collection-and-BULK COLLECT pattern can help bridge table data and a custom routine, but it does not remove SQL invocation restrictions or substitute for input validation and solver error handling.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.