15.00 - Passing Parameters to an SQL UDF - Teradata Database

Teradata Database SQL Data Definition Language Detailed Topics

Product
Teradata Database
Release Number
15.00
Content Type
Programming Reference
Publication ID
B035-1184-015K
Language
English (United States)

Passing Parameters to an SQL UDF

When you pass parameters directly to a UDF, Teradata Database returns parameter metadata in a Statement Info parcel (see Teradata Call-Level Interface Version 2 Reference for Mainframe-Attached Systems or Teradata Call-Level Interface Version 2 Reference for Workstation-Attached Systems for details). The rules for passing parameters to an external UDF or method also apply to SQL UDFs (see “Rules for Using SQL UDFs” on page 299 and “Function Calling Argument” on page 254).

In this example, the SQL UDF is not overloaded, so Teradata Database can resolve the UDF with just a ? parameter passed directly to the UDF. Teradata Database returns the parameter metadata regarding the UDF parameter in the target position.

     SELECT myudf(1, ?) 
     FROM t1;

In this example, the SQL UDF is overloaded, so you must explicitly cast the ? parameter to an acceptable value to enable the UDF to be resolved in Prepare mode. If you do not specify such a cast, Teradata Database cannot resolve the UDF, so the request aborts and the system returns an error to the requestor. For the purposes of parameter metadata, the data type field of the returned metadata is the result type of the cast.

     SELECT myudf(1, CAST(? AS INTEGER), col3) 
     FROM t1;