There are many different types of race available for the enthusiast - not including the secret challenge we all have of winning the last sprint in a local 'friendly' group ride!
The most common events are short, high speed time-trials and criterium races (typically 10km-40km); shortish circuits that involve a significant challenge or two (hills!); longer cyclosport events, sometimes with several routes available between about 50 miles long and 100 miles long; longer all day or particularly challenging events; races and courses that attract many enthusiasts and will be a sigificant difficulty for most cyclists (eg the Etape du Tour which follows the route of one of the mountain days from the Tour de France); and then longer events covering several days - Tour of Britain, Tour de France, Gire d'italia, Race Across America etc.
Most of us are never going to compete in any of these except the local races and events - but to stand a good chance in these still needs careful preparation and planning. Of course, the goal isn't always (or usually) to win - completing the event with the main group, or in the top 50%, or with a good time for a given age group are just as likely to be your goal - and for plenty of the longer events simply completing the route in the permitted time is challenge enough.
Any degree of success will require a mix of certain abilities, and a knowledge of these - along with a training programme that incorporates these elements - will be of geat benefit in your preparations.
1) a good level of basic endurance, the ability to cycle consistently over the distance over the event
2) being able to meet extra challenges as they arise, such as a long hill climb or a ride into a strong headwind
3) the ability to produce a significant increase in power when required, such as for catching up with a breakaway group, ending a race with a sprint, or climbing a short steep hill
4) skills at pushing yourself to the limit, in case you want to lead an attack or sustain a high speed throughout a time-trial
5) tolerance of pain! it is often necessary to push yourself hard (anaerobic effort), at least for a short while, and this can be painful. Getting used to it is a good idea!
Time trials require a slightly different approach, essentially focussing on becoming familiar with the maximum effort you can sustain over the given time, and then riding consistently at that level of effort.
Charity events are also a special case, because they often have no time pressure - the goal in training is usually simply to ensure you can pace yourself and cycle the distance involved. Cycling a long way but at low intensity is quite different from cycling at high intensity
From the above, a training programme suitable to meet your goals will naturally emerge. Decide which skills you already have, and which could do with the most improvement, then plan your training rides around improving those weaknesses.
And remember - when doing our cycling training most of us have a natural tendency to focus on the things we enjoy or are already good at. This is unfortunately less successful at producing best results. For example if when cycling you are already pretty good at short power bursts and sprints, but weaker on long hill climbs, then it's the hills you need to improve for greatest benefit!