We apply density functional theory (DFT) to the calculation of the (17)O NMR parameters in Ca and Mg oxides and aluminosilicates. We study the accuracy of the Perdew, Burke, and Ernzerhof (PBE) generalized-gradient approximation to DFT in the description of these systems and the origin of the experimentally observed large dependence of the (17)O chemical shift on the alkaline earth ion. We find that (i) the partially covalent nature of the Ca-O bond has a huge impact on the O chemical shifts. The Ca-O covalence alone explains why in Ca oxides and aluminosilicates the (17)O chemical shifts are much more deshielded than those of the corresponding Mg compounds. (ii) The Ca-O covalence is overestimated by the PBE functional. Thus PBE-DFT is not able to reproduce the measured (17)O NMR parameters in Ca oxide and Ca aluminosilicates. (iii) It is possible to correct for the PBE-DFT deficiency in a simple and transferable way and to predict very accurate (17)O NMR parameters. Such accuracy allows us to assign the (17)O NMR spectra of two important model systems: the grossite aluminate (CaAl(4)O(7)) and the wollastonite (CaSiO(3)) silicate.