We have table RPT_TEMPLATES with some columns RT_CODE (varchar2), RT_TEXT (blob), ...
In RT_TEXT place RTF template (xxx.rtf) with tags for sql query field
Sample
#main#
Some text № #doc_num# #doc_dt#
#main#
-- pl/sql function
declare
l_sql varchar2(4000);
l_report blob;
begin
-- init query
l_sql :='select doc_num, doc_dt from document where doc_id = || p_doc_id;
-- init template by RT_CODE name
qqq.reportfl_engine.initreport('wwwww', <RT_CODE_name);
-- add dataset to template
qqq.reportfl_engine.adddataset('main', l_sql);
-- get blob
l_report := qqq.reportfl_engine.publishreportblob;
-- if need get file from blowser
htp.p('Content-Type: application/msword; name="test.rtf"');
htp.p('Content-Disposition: attachment; filename="test.rtf"');
htp.p('Content-Length: ' || dbms_lob.getlength(l_report));
htp.p('');
-- send blob to user
wpg_docload.download_file(l_report);
end;