10.12.2012 Views

Oracle C++ Call Interface Programmer's Guide

Oracle C++ Call Interface Programmer's Guide

Oracle C++ Call Interface Programmer's Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Types of SQL Statements in the OCCI Environment<br />

<strong>Call</strong>able Statements<br />

stmt->executeUpdate(); // execute statement<br />

To insert another row:<br />

stmt->setString(1, “Apples”); // value for first parameter<br />

stmt->setInt(2, 9); // value for second parameter<br />

Having specified the parameters, you again insert values into the row:<br />

stmt->executeUpdate(); // execute statement<br />

If your application is executing the same statement repeatedly, then avoid changing<br />

the input parameter types because a rebind is performed each time the input type<br />

changes.<br />

PL/SQL stored procedures, as their name suggests, are procedures that are stored<br />

on the database server for reuse by an application. By using OCCI, a call to a<br />

procedure which contains other SQL statements is referred to as a callable<br />

statement.<br />

For example, suppose you wish to call a procedure (countFruit) that returns the<br />

quantity of a specified kind of fruit. To specify the input parameters of a PL/SQL<br />

stored procedure, call the setxxx methods of the Statement class as you would<br />

for parameterized statements.<br />

stmt->setSQL("BEGIN countFruit(:1, :2); END:");<br />

int quantity;<br />

stmt->setString(1, "Apples");<br />

// specify the first (IN) parameter of procedure<br />

However, before calling a stored procedure, you need to specify the type and size of<br />

any OUT and IN/OUT parameters by calling the registerOutParam method.<br />

stmt->registerOutParam(2, Type::OCCIINT, sizeof(quantity));<br />

// specify the type and size of the second (OUT) parameter<br />

You now execute the statement by calling the procedure:<br />

stmt->executeUpdate(); // call the procedure<br />

2-10 <strong>Oracle</strong> <strong>C++</strong> <strong>Call</strong> <strong>Interface</strong> Programmer’s <strong>Guide</strong>

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

Saved successfully!

Ooh no, something went wrong!