March 26th, 2004, 09:24 AM
Can you exprot database records with ColdFusion?
I'm a beginner with using ColdFusion. I interact with some Oracle tables within my ColdFusion templates and. I need to export the entire contents of AN Oracle table into a text or excel file (or any other format).
Is there a way to achieve this in ColdFusion?
March 26th, 2004, 11:11 AM
You could do this by using a select * from myTable in a cfquery block to get a query containing all the records from that table. Then you could manually loop over the query and write each line to a text file. Or you could use cfwddx to translate the entire result set to XML and write that to a file...there are many options. But the bottom line is yes, this can be done easily.
March 26th, 2004, 02:11 PM
Thanks for replying, kiteless.
I don't know XML yet, as far as your second solution.
I've thought of doing this by using your first solution. I thought there might be a built-in feature in CF that does this in an easier way.
Can you show me the syntax as to how I can write retrieved records into .txt file pelase?
March 26th, 2004, 02:45 PM
Something like this, depending on your needs:
<cfquery name="myQuery" datasource="myDSN">
select firstName, lastName from myTable
<cffile action="WRITE" file="#getDirectoryFromPath( getTemplatePath() )#/myexportfile.txt" output="">
<cffile action="APPEND" file="#getDirectoryFromPath( getTemplatePath() )#/myexportfile.txt" output="#myQuery.firstName# #myQuery.lastName#" addnewline="Yes">