在函式中使用 cfquery
<cffunction name="getUserById" access="public" returntype="query">
<cfargument name="userId" type="numeric" required="yes" hint="The ID of the user">
<cfquery name="local.qryGetUser" datasource="DATABASE_NAME">
SELECT id,
name
FROM user
WHERE id = <cfqueryparam value="#arguments.userId#" cfsqltype="cf_sql_integer">
</cfquery>
<cfreturn local.qryGetUser>
</cffunction>