The book Daniel purports to describe events which took place in Babylon after the fall of Jerusalem. The stories it contains have all one purpose - to show that God cares for and protects those who are faithful and put their trust in him in times of difficulty and danger.
Although the history of religions amply prove that those who are persecuted for their beliefs are spiritually protected and "saved" by their constancy and faith, yet it is also clear that God does not always bring their physical sufferings to a happy issue.
Most scholars believe that this book is a kind of "tract for hard times", i.e. a treatise produced at a time of religious persecution to encourage and strengthen those who are (figuratively) cast into a "burning, fiery furnace" or being "cast among lions". The stories have captured the imagination of many artists, readers and writers down through the ages and such stories as "Belshazzar's Feast" and the "Writing on the Wall" are very popular.
The chronology of the book is obscure, but towards the end we
come across a passage which links the book closely with the other
prophecies of the Exile period.
The purpose of the book, however, is clearly to nerve and strengthen those who (probably at the time of the tyrant Antiochus Epiphanes, the Greek) were facing persecution for the faith; and the (deliberate) obscurities for the uninitiated were intended to safeguard those who produced or read this "underground newspaper".