16.20 - Example: Creating a Procedure with Multistatement Request Using a Dynamic SQL Call Statement - Teradata Database - Teradata Vantage NewSQL Engine

Teradata Vantage™ SQL Data Definition Language Syntax and Examples

Product
Teradata Database
Teradata Vantage NewSQL Engine
Release Number
16.20
Published
March 2019
Language
English (United States)
Last Update
2019-05-24
dita:mapPath
wkf1512081455740.ditamap
dita:ditavalPath
TD_DBS_16_20_Update1.ditaval

Following is an example of a dynamic SQL call using DBC.SysExecSQL.

    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;