CFPROCPARAM  
Description

Defines stored procedure parameters. This tag is nested within a cfstoredproc tag.

 
Category

Database manipulation tags

 
Syntax
<cfprocparam 
   type = "in" or "out" or "inout"
   variable = "variable name"
   value = "parameter value"
   CFSQLType = "parameter datatype"
   maxLength = "length"
   scale = "decimal places" 
   null = "yes" or "no">
 
See also

cfinsert, cfprocresult, cfquery, cfqueryparam, cfstoredproc, cftransaction, cfupdate; "Optimizing ColdFusion applications" in Chapter 13, "Designing and Optimizing a ColdFusion Application," in ColdFusion MX Developer's Guide

 
History

ColdFusion MX:

  • The maxrows attribute is obsolete.
  • Changed the dbvarname attribute behavior: it is now ignored for all drivers. ColdFusion MX uses JDBC 2.2 and does not support named parameters.
  • Changed the maxLength attribute behavior: it now applies to IN and INOUT parameter values.

 
Usage

Use this tag to identify stored procedure parameters and their data types. Code one cfprocparam tag for each parameter. The parameters that you code vary based on parameter type and DBMS. ColdFusion MX supports positional parameters only and you must code cfprocparam tags in the same order as the associated parameters in the stored procedure definition.

Output variables are stored in the ColdFusion variable specified by the variable attribute.

You cannot use the cfprocparam tag for Oracle 8 and 9 reference cursors. Instead, use the cfprocresult tag.

 
Example

The following example shows how to invoke an Oracle 8 PL/SQL stored procedure. It makes use of Oracle 8 support of the Reference Cursor type.

The following package, Foo_Data, houses a procedure refcurproc that declares output parameters as Reference Cursor:

  • Parameter pParam1 returns the rows in the EMP table
  • Parameter pParam2 returns the rows in the DEPT table

The procedure declares one input parameter as an integer, and one output parameter as a two-byte char varying type. Before the cfstoredproc tag can call this procedure, it must be created, compiled, and bound in the RDBMS environment.

CREATE OR REPLACE PACKAGE Foo_Data AS
    TYPE EmpTyp IS REF CURSOR RETURN Emp%ROWTYPE;
    TYPE DeptTyp IS REF CURSOR RETURN Dept%ROWTYPE;
 PROCEDURE refcurproc(pParam1 in out EmpTyp, pParam2 in out DeptTyp, 
pParam3 in integer, pParam4 out varchar2);
END foo_data;

CREATE OR REPLACE PACKAGE BODY Foo_Data AS
   PROCEDURE RefCurProc(pParam1 in out EmpTyp,
         pParam2 in out DeptTyp,
         pParam3 in integer,
         pParam4 out varchar2) IS
   BEGIN
      OPEN pParam1 FOR select * from emp;
      OPEN pParam2 FOR select * from dept;
      IF pParam3 = 1
      THEN
         pParam4 : = 'hello';
      ELSE
         pParam4 : = 'goodbye';
      END IF;
   END RefCurProc;
END Foo_Data;

The following CFML example shows how to invoke the RefCurProc procedure using cfstoredproc, cfprocparam, and cfprocresult:

<cfstoredproc  procedure = "foo_data.refcurproc"
   dataSource = "oracle8i" 
   username = "scott"
   password = "tiger"
   returnCode = "No">

   <cfprocparam type = "Out" CFSQLType = "CF_SQL_REFCURSOR" 
      variable = "param1">
   <cfprocparam type = "Out" CFSQLType = "CF_SQL_REFCURSOR"
      variable = "param2">
   <cfprocparam type = "IN" CFSQLType = "CF_SQL_INTEGER" value = "1">

   <cfprocparam type = "OUT" CFSQLType = "CF_SQL_VARCHAR" 
      variable = "FOO">
   <cfprocresult name = "rs1">
   <cfprocresult name = "rs2" resultSet = "2">
</cfstoredproc>

<b>The first result set:</b><br>
<hr>
<cftable query = "rs1" colHeaders HTMLTable border = "1">
   <cfcol header = "EMPNO" text = "#EMPNO#">
   <cfcol header = "EMPLOYEE name" text = "#ENAME#">
   <cfcol header = "JOB" text = "#JOB#">
   <cfcol header = "SALARY" text = "#SAL#">
   <cfcol header = "DEPT NUMBER" text = "#DEPTNO#">
</cftable>

<hr>
<b>The second result set:</b><br>

<cftable query = "rs2" colHeaders HTMLTable border = "1">
   <cfcol header = "DEPT name" text = "#DNAME#">
   <cfcol header = "DEPT NUMBER" text = "#DEPTNO#">
</cftable>
<hr>
<cfoutput>
   <b>The output parameter is:</b>'#FOO#'
</cfoutput>
TYPE  
  Optional
 
Default value: "in"
  • in: the parameter is used to send data to the database system only. Passes the parameter by value.
  • out: the parameter is used to receive data from the database system only. Passes the parameter as a bound variable.
  • inout: the parameter is used to send and receive data. Passes the parameter as a bound variable.
VARIABLE  
  Required if type = "OUT" or "INOUT"
 

ColdFusion variable name; references the value that the output parameter has after the stored procedure is called. This is ignored for IN parameters.

VALUE  
  Required if type = "IN"
 

Value that ColdFusion passes to the stored procedure.This is optional for INOUT parameters.

CFSQLTYPE  
  Required
 

SQL type to which the parameter (any type) is bound. ColdFusion supports the following values, where the last element of the name corresponds to the SQL data type. Different database systems might support different subsets of this list. See your DBMS documentation for information on supported parameter types.

  • CF_SQL_BIGINT
  • CF_SQL_BIT
  • CF_SQL_BLOB
  • CF_SQL_CHAR
  • CF_SQL_CLOB
  • CF_SQL_DATE
  • CF_SQL_DECIMAL
  • CF_SQL_DOUBLE
  • CF_SQL_FLOAT
  • CF_SQL_IDSTAMP
  • CF_SQL_INTEGER
  • CF_SQL_LONGVARCHAR
  • CF_SQL_MONEY
  • CF_SQL_MONEY4
  • CF_SQL_NUMERIC
  • CF_SQL_REAL
  • CF_SQL_REFCURSOR
  • CF_SQL_SMALLINT
  • CF_SQL_TIME
  • CF_SQL_TIMESTAMP
  • CF_SQL_TINYINT
  • CF_SQL_VARCHAR

For a mapping of ColdFusion SQL data types to JDBC data types, See also cfqueryparam.

MAXLENGTH  
  Optional
 
Default value: "0"

Maximum length of a string or character IN or INOUT value attribute. A maxLength of 0 allows any length. The maxLength attribute is not required when specifying type=out.

SCALE  
  Optional
 
Default value: "0"

Number of decimal places in numeric parameter. A scale of 0 limits the value to an integer.

NULL  
  Optional
 
Default value: "No"

Whether the parameter is passed in as a null value. Not used with OUT type parameters.

  • Yes: tag ignores the value attribute.
  • No