How long you can, or should, hold onto a company depends on whether or not its future presents great value or not.
You can hold onto a dog for 30 years and it could die on you in 10, costing you loads of cash from the "rights" issues they needed every now and then to stay alive (or "grow"). Not to mention opportunity costs.
So think "long term" not in terms of time. As in, don't think that if you put money into a business and don't mind waiting for a long time that it's automatically a good investment idea and strategy.
There are businesses that, yes, are so good that even if you bought in at a high price, had the misfortune of its industry going into the headwind for a couple of years... you hanging on and in about 10 years or more, all the bad stuff just made it stronger and you more profitable.
So there's those good qualities, buy to hold until the kids inherit it.
Then there are terrible businesses burning money millions on billions... they can be bought and you can hang on for a few years or even a decade or more... and it still wouldn't make you much.
I guess what I'd do is try to figure out whether or not a business is one of outstanding quality that, as Buffett would say, any idiot could run. Try to buy into it at a reasonable, or very cheap, price (that depends on both luck and a lot of luck)... then keep an eye on them.
Great businesses rarely sell for reasonable, or cheap. They do tend to be overpriced too.
So if you hold one that was bought cheap and the market thinks too much of it... then if another opportunity exists that you could do with the cash from that sale. Obvious what you'd do right?
In the end, I think investment decision should be made based on the quality and value of the business; not on the time you hold it.
That's not to say you should jump in and out, or try to time the market or time the stock. That's something you should only do if you can predict market movement or have a time machine.