I am new to ColdFusion, I have written a block of Postgres code in CFQuery :
<cffunction name="insertToReport" access="private" returntype="struct" output="false" >
<cfset var xyz = structNew() >
<cfset xyz.code = "">
<cfquery name="querysampleresult" datasource="abc">
DO
$BODY$
DECLARE resultValue int;
BEGIN
resultValue = 1;
SELECT resultValue INTO resultValue ;
END;
$BODY$
</cfquery>
<cfset xyz.code = querysampleresult.resultValue >
<cfreturn xyz >
</cffunction>
My problem is that I am unable to access the variable resultValue outside of the CFQuery tag, i.e it is throwing the exception:
Element RESULTVALUE is undefined in querysampleresult
This is occurring at the CFSet statement at the end of function here:
<cfset xyz.code = querysampleresult.resultValue >
I don’t know how I can set the variable resultValue in the structure and I am bound to return a structure from here to the calling environment.
Please help me in this, Thanks In Advance.
An anonymous code block (
DO) always returnsvoid. You need to use a function to return anything else:After the function is created you can use it in your query: