Skip Headers
Oracle® Objects for OLE C++ Class Library Developer's Guide
10g Release 2 (10.2)

Part Number B14308-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

ExecuteSQL Method

Applies To

ODatabase

Description

This method sends a SQL statement to the Oracle database to be executed.

Usage

oresult ExecuteSQL(const char *sqlstmt) const

Arguments

sqlstmt
The SQL statement to execute.
Remarks

This method executes an arbitrary SQL statement specified in the sqlstmt argument. The sqlstmt should not be a query, but can use select clauses in some other kind of statement. If the SQL statement modifies the data accessed by an open dynaset, the dynaset is not guaranteed to see the change until it is Refreshed.

Note: Some kinds of SQL statements result in an implicit commit. Consult your Oracle documentation.

You can also use the ExecuteSQL method to call stored PL/SQL procedures and functions. Any parameters to the procedure or function should be provided with parameter objects.

Return Value

An oresult indicating whether the operation succeeded (OSUCCESS) or not (OFAILURE).

Example

Several examples follow. They all assume the existence of an open ODatabase named odb.

This example executes a very simple statement. It drops a table.

odb.ExecuteSQL("drop table dontwantit");

This example gives everybody in Department 20 a 10% raise in their salary by using a SQL statement that updates multiple records. Note that you can obtain the number of rows actually processed with the GetRowsProcessed attribute.

odb.ExecuteSQL("update emp set sal = sal * 1.1 where deptno = 20");
long numrows = odb.GetRowsProcessed();

This example calls a stored procedure.

// Create a database object
ODatabase odb("ExampleDB", "scott", "tiger");

// Add EMPNO as an Input parameter and set it's initial value
odb.GetParameters().Add("EMPNO", 7369,
                         OPARAMETER_INVAR, OTYPE_NUMBER);

// Add ENAME as an Output parameter and set it's initial value
odb.GetParameters().Add("ENAME", 0, 
                     OPARAMETER_OUTVAR, OTYPE_VARCHAR2);

/*
Execute the Stored Procedure Employee.GetEmpName to retrieve ENAME. This
Stored Procedure can be found in the file ORAEXAMP.SQL
*/

odb.ExecuteSQL("Begin Employee.GetEmpName (:EMPNO, :ENAME); end;")