The cartridges have batteries that can last from 5 to 7 years on average. It all depends on the battery though on how long it lasts. It also depends on how much you save during a game aswell. If you have a save the battery keeps going day and night to keep the save. Every time you hit save a bit of extra energy is taken from the battery to save your progress. Eventually the battery dies. It depends on how much you use it. Pokemon games are used a lot as we know in most cases alot more than any other game. Therefore the battery dies quicker than the other games. I've got a Mario game for my Gameboy that is 10 ears old which can still save but I hardly ever use it. Though people who have claimed that they've used it alot have had their batteries die already. though as I said it does also depend on the battery. You can replace the battery, they are gotten from watch shops and online sites. Though it does mean opening the cartridge. Though if you bought a second hand one to replace it and still have the broken one then there's nothing to lose. I've been studying this so I'm prepared.
I heard from another forum the battery for Gameboy and Gameboy Colour cartridges are DL1616 or CR1616 lithium battery. To find out exactly what battery is needed, it does require pulling it out. Also if you choose to open it try to touch as little of the circuit board as possible.
I've been pretty lucky. I own all the old versions "silver, Gold, Crystal, Red, Blue and Yellow" and they all still save. Though I'm studying all this to be prepared.
The Advance versions on the other hand don't use a battery to save. Leaf green and Fire Red don't have a battery within them and the battery that is in Ruby, Sapphire and Emerald only controls the clock not the save. (This is what Nintendo stated). That is why when a Ruby, sapphire and Emerald version says the "internal battery has run dry", the game is still able to be played. The DS cartridges don't use an internal battery either. The advance Pokemon games and future games tha will come out on the DS use a type of flash memory. There are to types of Flash memory used for the Advance Pokemon games. Though the disadvantage with this is that they can lose their save if they are exposed to static electricity but at least you can start a new game.