The moral lesson of "The Happy Prince" by Oscar Wilde is that the worst aspects of modern society can be overcome by love and charity, which have the unique ability to unite men and make them whole. Wilde wrote the fairy tale during the Victorian era, when the East End of London was awash with the suffering and forced labor of children, many of whom were forced into prostitution and almost all of whom lived in abject poverty. This social context is generally accepted as the inspiration for the story.
The Prince is a multifaceted character symbolizing both the positive and negative aspects of society, sometimes referred to as the "senex" and the "puer," respectively. During his life, the Prince is sheltered in a life of luxury and is unaware of the suffering of the lower classes. When he is dead he becomes aware of their suffering, looking down from his elevated position as a statue above the city.
Seeing these social ills around him, the Prince sets out to assist various people in need of help, including a sick boy. For him, the Prince has a swallow fetch a ruby from the King's sword. Despite the inclement weather, the swallow does not feel cold while doing so and the Prince explains that this warmth is the result of doing a good deed.