10.07.2015 Views

Programming Guide - Actian

Programming Guide - Actian

Programming Guide - Actian

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

How You Can Access a Database with Standard SQL StatementsThe following execute immediate statement runs the select statement and putsthe values returned in the vidtitle and vidno variables:execute immediate :statement into :vidtitle, :vidno;If you do not know the names and data types of the target variables untilruntime, create an SQLSelect or a query object to build the retrieval statementdynamically. For more information about dynamic query creation, see How YouCan Access a Database with DataStream Objects (see page 165) and How YouCan Use Query Objects (see page 177).How You Can Use Cursors to Access the DatabaseCursors are useful for:• Bringing only part of a result set across the network where lowcommunications bandwidth is an issue• Performing an unrelated operation in the midst of processing returnedrows (which can also be performed using a select loop)• Performing operations on returned values that span two or more eventblocks• Determining which of several select statements in a fetch loop to executeat runtime, for example:if frame_mode = MODE_SALES thenopen cursor1 for select salesname as name,salesquota as amountfrom sales where region = :region orderby amount;elseif frame_mode = MODE_MGRS thenopen cursor1 for select mgrname as name,budget as amount from managerswhere business_unit = :bus_unitorder by name;elseopen cursor1 for select staffname as name,salary as amountfrom staff where staff_code = :staff_codeORDER BY Amount;endif;i = 0;curs_state = CS_CURRENT;while (curs_state = CS_CURRENT) doi = i + 1;fetch cursor1 into :tf[i].name = name,:tf[i].amount = amount;curs_state = cursor1.state;endwhile;/* number of rows fetched = i-1 */close cursor1;Working with a Database 157

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!