17.10 - Example: Using the java.sql.Struct Interface for a Structured UDT Parameter - Advanced SQL Engine - Teradata Database

Teradata Vantageā„¢ - SQL External Routine Programming

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1147-171K
Language
English (United States)
CREATE TYPE EMPLOYEE AS (empid int,
                         first_name varchar(20),
                         last_name varchar(20),
                         salary decimal(10,2))

REPLACE PROCEDURE getEmployeeDetails(IN E1 Employee)
LANGUAGE JAVA
NO SQL
PARAMETER STYLE JAVA 
EXTERNAL NAME 'UDF_JAR:UserDefinedFunctions.getEmployeeDetails';

public static void getEmployeeDetails(java.sql.Struct E1) throws SQLException
{
  String objname;
  Object[] elements;

  objname = E1.getSQLTypeName();
  System.out.println("Object Name:"+ objname);

  elements = E1.getAttributes();
  System.out.println("Employee Id: " + (Integer)elements[0]);
  System.out.println ("Employee name:  " + (String) elements[1] + 
                                       " " + (String)elements[2] );
  System.out.println("Salary: "+ (BigDecimal)elements[3]);
}