How to read a record from a table in a TIBCO Data Virtualization procedure, modify the record, and then write it to a pipe?

How to read a record from a table in a TIBCO Data Virtualization procedure, modify the record, and then write it to a pipe?

book

Article ID: KB0074998

calendar_today

Updated On:

Products Versions
TIBCO Data Virtualization 7.0 and higher

Description

How to read a record from a table in TIBCO Data Virtualization, modify the record, and then write it to a pipe ?

Issue/Introduction

How to read a record from a table in TIBCO Data Virtualization, modify the record, and then write it to a pipe?

Resolution

A cursor may be used to read a record from a table, as a cursor is able to execute a SELECT statement. The cursor fields are fetched into local variables and the content of the local variables modified as needed. One or more local variables can then be written out to a pipe. 

Below is an example that shows how to read a record from a table and store the record fields in local variables named acity and acompany. After changing the content of acity from 'Union City' to 'I am travelling to Union City' and changing the content of acompany from 'Able Computing' to  'I work for a company whose name is Able Computing', the record is written to a pipe.

PROCEDURE pGetRecord(OUT c2 PIPE(mydestination VARCHAR, mycompany VARCHAR))
BEGIN

DECLARE c1    CURSOR;
DECLARE acity      VARCHAR;
DECLARE acompany   VARCHAR;

open c1 for SELECT City, CompanyName from /shared/examples/ds_orders/tutorial/customers;
FETCH c1 INTO acity, acompany;    

set acity = 'I am travelling to ' || acity;
set acompany= 'I work for a company whose name is ' || acompany;
INSERT INTO c2 (mydestination, mycompany) VALUES (acity, acompany); 

END

The output of the procedure is:     
   
  mydestination  :  I am travelling to Union City
  mycompany     :  I work for a company whose name is Able Computing
          
   User-added image