Save as a file in a DB combined content from that same DB

Is it possible to take the content of several text categories from a database, to combine it in a structured manner and save the outcome as a .txt file to be saved in a file category of the same database ? Thanks.