A California judge on Tuesday approved an unusual legal settlement that will require Oracle Corp. CEO Larry Ellison to donate $100 million to charity and pay another $22 million to the attorneys who sued him for alleged stock trading abuses — forcing Ellison to dig deeper into his pockets than he originally wanted.

Barring an appeal, the $122 million settlement finalized by San Mateo Superior Court Judge John Schwartz closes the books on a shareholder lawsuit filed nearly four years ago on behalf of Oracle, one of the world’s largest software makers.