Modifying Data in External Databases

Use the Database statement to send instructions to modify external relational databases directly from Sybase CEP. The Database statement can execute any valid SQL Update, Insert, or Delete statement in the associated external database.

Assume that a Sybase CEP query is creating ongoing average price data from incoming stock trades. This query sends its information to a stream called StockAvgPrice. Here is an example of how the Database statement can read the StockAvgPrice stream and update the external database:

EXECUTE STATEMENT DATABASE 'StockDatabase'
[[UPDATE StockHistory
 SET StockHistory.avgprice = ?avgpr
 WHERE StockHistory.symbol = ?symb]] 
SELECT symbol AS symb, avgprice AS avgpr 
FROM StockAvgPrice

The syntax of the Database statement is very similar to the database subquery, except that it is a complete statement of its own which is not embedded in an INSERT/SELECT statement. Note the following differences and important points:


For every row that is published by the SELECT clause, a call is made to the external database, passing the entire SQL statement contained in the square brackets after all ? references are converted to their actual Sybase CEP data values. The external database is responsible for executing the SQL statement. Errors are reflected back to the Sybase CEP server and can be found in the Sybase CEP log files.


Created March 8, 2010. Send feedback on this help topic to Sybase Technical Publications: pubs@sybase.com