If SHA-2 is so secure then why have National Institute of Standards and Technology (NIST) announced an open competition for a new SHA-3 function to replace the older SHA-1 and SHA-2 after 2012?
For a variety of reasons, none of which in any way bear on SHA-2's suitability for use in bitcoin. For example, one issue is to provide improved hashing performance.
Is SHA-2 algorithm hard coded in the bitcoin protocol or not? Is it possible to upgraded it to SHA-3 after 2012?
It is, but the protocol could be changed if needed. However, SHA-2 will be suitable for use in bitcoin *way* past 2012. I would be surprised if SHA-2 wasn't still ironclad for its use in bitcoin until at least 2030.