17.05 - Example: Invoking an SQL UDF From an SQL Procedure - Advanced SQL Engine - Teradata Database

Teradata Vantage™ - SQL Data Definition Language Syntax and Examples

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
Release Date
January 2021
Content Type
Programming Reference
Publication ID
B035-1144-175K
Language
English (United States)

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;