Its stem rot. Basically dead tissue. If its a branch stem, best to just remove the branch and dispose of properly. If its a main stem, or something with a lot of growth further on, use a knife to scrape away as much of the rotted tissue as you can get at, then use a garden hose with a jet nozzle or pressure washer to blast away the decayed soft tissue. As long as the main stem remains intact, the branch itself will continue to survive. Think of it like a tree, with the hard woody core being the trunk and the green flesh being the bark. I've got a few plants that have sections of bare core feet long that not only survive just fine, but the exposed core continues to grow and expand just like it would if it were still wet and green.
As for the cause, could be bacterial, fungal or environmental. Usually these things are caused by branches banging together, poking holes in one another with their thorns, and allowing impurities to get into the soft tissue, and fester once the holes scar up. There's not a whole lot you can do about that, unless you have fungal issues, in which case you can do the occasional wash down with a light anti-fungal, but that's a bit of a crap shoot and you have no guarantee its going to totally prevent this. Best thing you can do is make sure you're giving your plants the proper nutrients when you feed them, to help them stay healthy and less susceptible to disease and damage.