环境: AIX 5.3 (64bit)
Oracle 9.2.0.7
Visual Age C++ 7.0occiproc.cpp就是oracle自带的一个演示occi用法的例子,位于$ORACLE_HOME/rdbms/demo目录中.oracle@newdev:>xlC -I/oracle/product/9.2.0/rdbms/demo -I/oracle/product/9.2.0/rdbms/public -q64 -L/oracle/product/9.2.0/lib -locci occiproc.cpporacle@newdev:>./a.out
occiproc - invoking a PL/SQL function and procedure having parameters
callproc - invoking a PL/SQL procedure having IN, OUT and IN/OUT parameters
Executing the block :(:v1, :v2, :v3); END;
Update Count:1
Printing the INOUT & OUT parameters:
Col2:IN-OUT Col3:OUT
occiproc - done
callfun - invoking a PL/SQL function having IN, OUT and IN/OUT parameters
Executing the block :o_fun(:v1, :v2, :v3); END;
Segmentation fault(coredump)不知道为什么createStatement参数明明是("Begin demo_proc(:v1, :v2, :v3); END;", 但是用getSQL打印出来的SQL语句却少了前面几个字节,难道是Oracle的bug,百思不得其解,还望高手指点一二.
Oracle 9.2.0.7
Visual Age C++ 7.0occiproc.cpp就是oracle自带的一个演示occi用法的例子,位于$ORACLE_HOME/rdbms/demo目录中.oracle@newdev:>xlC -I/oracle/product/9.2.0/rdbms/demo -I/oracle/product/9.2.0/rdbms/public -q64 -L/oracle/product/9.2.0/lib -locci occiproc.cpporacle@newdev:>./a.out
occiproc - invoking a PL/SQL function and procedure having parameters
callproc - invoking a PL/SQL procedure having IN, OUT and IN/OUT parameters
Executing the block :(:v1, :v2, :v3); END;
Update Count:1
Printing the INOUT & OUT parameters:
Col2:IN-OUT Col3:OUT
occiproc - done
callfun - invoking a PL/SQL function having IN, OUT and IN/OUT parameters
Executing the block :o_fun(:v1, :v2, :v3); END;
Segmentation fault(coredump)不知道为什么createStatement参数明明是("Begin demo_proc(:v1, :v2, :v3); END;", 但是用getSQL打印出来的SQL语句却少了前面几个字节,难道是Oracle的bug,百思不得其解,还望高手指点一二.
* occiproc - Demonstrating the invoking of a PL/SQL function and procedure
* using .
*
* DESCRIPTION :
* This program demonstrates the invoking a PL/SQL function and procedure
* having IN, IN/OUT and OUT parameters.
*
*/#include <iostream>
#include <occi.h>
using namespace oracle::occi;
using namespace std;class occiproc
{
private: Environment *env;
Connection *con; public :
/**
* Constructor for the occiproc demo program.
*/
occiproc (string user, string passwd, string db) throw (SQLException)
{
env = Environment::createEnvironment (Environment::DEFAULT);
con = env->createConnection (user, passwd, db);
}// end of constructor occiproc (string, string, string )
/**
* Destructor for the occiproc demo program.
*/
~occiproc () throw (SQLException)
{
env->terminateConnection (con);
Environment::terminateEnvironment (env);
} // end of ~occiproc () // Function to call a PL/SQL procedure
void callproc ()
{
cout << "callproc - invoking a PL/SQL procedure having IN, OUT and IN/OUT ";
cout << "parameters" << endl;
Statement *stmt = con->createStatement
("BEGIN demo_proc(:v1, :v2, :v3); END;");
cout << "Executing the block :" << stmt->getSQL() << endl;
stmt->setInt (1, 10);
stmt->setString (2, "IN");
stmt->registerOutParam (2, OCCISTRING, 30, "");
stmt->registerOutParam (3, OCCISTRING, 30, "");
int updateCount = stmt->executeUpdate ();
cout << "Update Count:" << updateCount << endl; string c1 = stmt->getString (2);
string c2 = stmt->getString (3);
cout << "Printing the INOUT & OUT parameters:" << endl;
cout << "Col2:" << c1 << " Col3:" << c2 << endl; con->terminateStatement (stmt);
cout << "occiproc - done" << endl;
} // end of callproc () // Function to call a PL/SQL function
void callfun ()
{ cout << "callfun - invoking a PL/SQL function having IN, OUT and IN/OUT ";
cout << "parameters" << endl;
Statement *stmt = con->createStatement
("BEGIN :a := demo_fun(:v1, :v2, :v3); END;");
cout << "Executing the block :" << stmt->getSQL() << endl;
stmt->setInt (2, 10);
stmt->setString (3, "IN");
stmt->registerOutParam (1, OCCISTRING, 30, "");
stmt->registerOutParam (3, OCCISTRING, 30, "");
stmt->registerOutParam (4, OCCISTRING, 30, "");
int updateCount = stmt->executeUpdate ();
cout << "Update Count : " << updateCount << endl; string c1 = stmt->getString (1);
string c2 = stmt->getString (3);
string c3 = stmt->getString (4); cout << "Printing the INOUT & OUT parameters :" << endl;
cout << "Col2:" << c2 << " Col3:" << c3 << endl;
cout << "Printing the return value of the function :";
cout << c1 << endl; con->terminateStatement (stmt);
cout << "occifun - done" << endl;
} // end of callfun ()
}; // end of class occiprocint main (void)
{
string user = "SCOTT";
string passwd = "TIGER";
string db = ""; cout << "occiproc - invoking a PL/SQL function and procedure having ";
cout << "parameters" << endl;
occiproc *demo = new occiproc (user, passwd, db);
demo->callproc();
demo->callfun();
delete demo;
}// end of main ()
callproc - invoking a PL/SQL procedure having IN, OUT and IN/OUT parameters
Executing the block :(:v1, :v2, :v3); END;
Update Count:1
Printing the INOUT & OUT parameters:
Col2:IN-OUT Col3:OUT
occiproc - done
callfun - invoking a PL/SQL function having IN, OUT and IN/OUT parameters
Executing the block :o_fun(:v1, :v2, :v3); END;
Segmentation fault(coredump)
$>echo $?
139