I can imagine that your accuracy would have to be absolutely perfect if using a 9 against a bear. And even with perfect accuracy, that must be just about the biggest crap-shoot there is. Just flat-out LUCK would have to be a huge factor, I'd think.
I've always wondered what a person would (or should) do if caught in such a situation, and had nothing else on hand?
If the animal is close enough and you are steady enough, even a .22 will do. It has been done. I would not want to try it though.
https://www.liveoutdoors.com/news/240665-alaskan-fishing-guide-kills-grizzly-with-9mm/
https://backfire.tv/9mm-for-bear-protection-best-ammo-tips-and-if-its-enough/