In simple ions, the oxidation number is the charge on the ion (so an Mg2+ ion will have an oxidation state of +2) - so you're right.
But you have to remember that group 1 metals, group 2 metals and aluminium from group 3 have fixed oxidation states in all of their compounds - +1 for group 1, +2 for group 2 and +3 for aluminium (although that does mean that the charge on their ions is equal to their oxidation state).
The ions want to reach the same electron configuration as the nearest noble gas as this is the most stable. They all want 8 electrons in their outer shell.
Group 1 have to lose an electon to become 1+ and Group 2 have to lose 2 electrons to become 2+. Group 7 have to gain an electron to become 1- and Group 6 have to gain 2 electrons to become 2-. Now they all have 8 in the outer shell.
As for things like NO3- and OH-, you just have to learn them.