谢谢各位朋友,我现在写了一个存储过程 CREATE OR REPLACE PACKAGE testpre AS TYPE myrctype IS REF CURSOR; END testpre; /create procedure a(p_cur out testpre.myrctype) as str varchar2(200); begin str:='select deptno,dname from dept'; open p_cur for str; end; 现在我想在VC的程序中调用此存储过程,我应该怎么做,我VC中的环境是用OCI接口和数据库建立联系的,拜托!!
CREATE OR REPLACE PACKAGE testpre
AS
TYPE myrctype IS REF CURSOR;
END testpre;
/create procedure a(p_cur out testpre.myrctype)
as
str varchar2(200);
begin
str:='select deptno,dname from dept';
open p_cur for str;
end;
现在我想在VC的程序中调用此存储过程,我应该怎么做,我VC中的环境是用OCI接口和数据库建立联系的,拜托!!
m_pConnection.CreateInstance("ADODB.Connection");
/******************连接数据库********************/
try
{
m_pConnection->ConnectionTimeout = 8;
//连接SQL SERVER
//m_pConnection->Open("Driver=SQL Server;Database=test;Server=127.0.0.1;UID=sa;PWD=;","","",adModeUnknown);
//连接ACCESS2000
//m_pConnection->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=userinfo.mdb","","",adModeUnknown);
//连接到oracleMSDAORA oraoledb.oracle
m_pConnection->Open("Provider=oraoledb.oracle;Data Source=ep;User ID=zongdui;Password=zongdui;PLSQLRSet=1","","",adModeUnknown); }
catch(_com_error e)///捕捉异常
{
AfxMessageBox("数据库连接失败!");
return FALSE;
}
/**********************************************/上面是连接数据库,PLSQLRSet=1这个一定要有。 m_bNewUser = FALSE;
m_pRecordset.CreateInstance("ADODB.Recordset");
try
{
//m_pRecordset->Open("SELECT name as username,old,photo as photo1 FROM test",_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenStatic,adLockPessimistic,adCmdText);
_CommandPtr pCmdChange = NULL;
// _ParameterPtr pprmByRoyalty = NULL; pCmdChange.CreateInstance(__uuidof(Command));
pCmdChange->CommandType = adCmdStoredProc;
pCmdChange->CommandText = "pkg_test.get";
//Define Integer/variant.
// pprmByRoyalty.CreateInstance(__uuidof(Parameter));
// VARIANT vtRoyalty;
// vtRoyalty.vt = VT_I2;
// vtRoyalty.iVal = 20;
// pprmByRoyalty = pCmdChange->CreateParameter("param1",adInteger,adParamInput,sizeof(int),vtRoyalty);
// pCmdChange->Parameters->Append(pprmByRoyalty); // pprmByRoyalty->Value = vtRoyalty;
//Create Recordset by executing the command
pCmdChange->ActiveConnection = theApp.m_pConnection; //Create Recordset by executing the command
m_pRecordset->CursorType=adOpenStatic;
m_pRecordset->LockType=adLockPessimistic;
m_pRecordset = pCmdChange->Execute(NULL,NULL,adCmdStoredProc);
//m_pRecordset->Open("{CALL (?{20})}",_variant_t((IDispatch *)theApp.m_pConnection,true),adOpenStatic,adLockPessimistic,adCmdStoredProc);
/**/
}
catch (_com_error e)
{
AfxMessageBox(e.Description());
return FALSE;
}这样就可以得到pkgtest.get返回的记录集