The oxidation number of an element in a compound is the charge left on the central atom, when all the bonding pairs of electrons are removed, with the charge (the electrons) assigned to the most electronegative atom.
And thus if have an ionic compound, say #CaCl_2#, we can break this up into ions, i.e. #Ca^(2+)# and #2xxCl^-#. And thus we assign oxidation numbers #Ca^(+II)# and #Cl^(-I)#. As always, the sum of the oxidation numbers equals the charge on the original species, here #0#. Generally, calcium, a Group 2 metal, form #Ca^(2+)# ions, and thus it assumes a #+II# oxidation state.
For compound ions, say #ClO_4^-#, again the charge of the ion equals the sum of the oxidation numbers. Oxygen generally assumes an oxidation number of #-II#, and it does here, and thus:
#Cl_"oxidation number"+4xx(-II)=-I#
So #Cl_"oxidation number"=+VII#.
AS the elements, neither oxygen NOR calcium are assumed to have accepted or donated electrons, and here they are zerovalent, i.e. a #0# oxidation number.