Look at bahn.de for possible connections. They give a 31 hour journey connecting up through Germany then the overnight train from Hamburg to Stockho!m for train to Oslo, as the most sensible connection. 5 trains in all.
But overnights in Hamburg and Copenhagen seem better. Or maybe a night in Hamburg, then to Kiel or Copenhagen for the overnight Cruise ferry to Oslo may be alternative options.
It will never be as cheap as flying. The bahn will give you an idea of the point to point fares. You wouldn't do this for cheapness, more for the experience.