We analyze the resonant inelastic x-ray scattering (RIXS) spectra at the Cu and Ni K edges in La2CuO4 and La2NiO4, respectively. We make use of the Keldysh-Green-function formalism, in which the RIXS intensity is described by a product of incident-photon-dependent factor and density-density correlation function in the 3d states. The former factor is calculated using the $4p$ density of states given by an ab initio band structure calculation and the latter using the wavefunctions given by a Hartree-Fock calculation of a multi-orbital tight-binding model. The initial state is described within the Hartree-Fock approximation and the electron correlations on charge excitations are treated within the random phase approximation. The calculated RIXS spectra well reproduce several characteristic features in the experiments. Although several groups have interpreted the RIXS peaks as bound excitons, our calculation indicates that they should be interpreted as band-to-band excitations augmented by electron correlations. The difference in RIXS spectra between La2CuO4 and La2NiO4 is explained from this point of view.