15.10 - Example: Invoking an SQL UDF From an SQL Procedure - Teradata Database

Teradata Database SQL Data Definition Language Syntax and Examples

prodname
Teradata Database
vrm_release
15.10
created_date
December 2015
category
Programming Reference
featnum
B035-1144-151K

The following example invokes the SQL UDF common_value_expression several times.

     CREATE PROCEDURE spAccount (
       IN  p2 INTEGER, 
       OUT p1 CHARACTER(30))
     L1: BEGIN
       DECLARE i INTEGER;
       DECLARE i1 INTEGER;
       DECLARE DeptCursor CURSOR FOR
       SELECT DeptName from Department 
       WHERE test.common_value_expression(DeptNo, 0) = 25;
       DECLARE CONTINUE HANDLER FOR SQLSTATE VALUE '23505'
     L2: BEGIN
       SET i1 = p2;
       SET p1='Failed To Insert Row';
     END L2;
     L3: BEGIN
       INSERT INTO table_1
       VALUES(1, test.common_value_expression(1,2));
       IF SQLCODE <> 0 THEN LEAVE L1;
     END L3;
       INSERT INTO table_2
       VALUES(2, test.common_value_expression(2,3));
     END L1;