15.10 - Example: Creating a Procedure with Multistatement Request Using a Dynamic SQL Call Statement - 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 is a repeat of Example: Creating a Procedure with Multistatement Request Using a Dynamic SQL Call Statement, except it substitutes a dynamic SQL call using DBC.SysExecSQL in place of the two UPDATE statements.

    CREATE PROCEDURE salesadjust(IN item    INTEGER, 
                                 IN numsold INTEGER)
      BEGIN
        DECLARE  price DECIMAL(8,2);
        DECLARE  update1, update2 VARCHAR(128);
        SELECT item_price INTO price 
        FROM PriceTbl 
        WHERE item = pricetbl.item_no;
        SET Update1 = 'UPDATE sales_summary' ||
         'SET total_sales = total_sales + ' ||
         price ' || ' * ' || numsold || 
         'WHERE ' || item || ' = sales_summary.item_no;';
        SET update2 = 'UPDATE inventory' ||
         'SET item_no = item_no -' || numsold
         'WHERE ' || item || ' = inventory.item_no;';
       BEGIN REQUEST
        CALL dbc.SysExecSQL(update1 || update2);
       END REQUEST;
      END;