各位大侠,小弟碰到一个问题,狂做没有做出来,请各位大侠帮帮忙:
   用ODBC连接的Oracle数据库,怎么在VC里面执行Oracle存储过程!
   小弟是这么写的,可是不行!
   CDatabase *m_pdb;
   m_pdb.Open(.....);
   m_pdb.ExcuteSQL("Call Procedure_Name");
谢谢!有分

解决方案 »

  1.   

    http://search.csdn.net/Expert/topic/1194/1194790.xml?temp=.2194178
      

  2.   

    // oracleprocedure.cpp : Defines the entry point for the console application.
    //#include "stdafx.h"
    #import "c:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF", "EndOfFile")
    VOID PrintProviderError(_ConnectionPtr pConnection)
    {
    // Print Provider Errors from Connection object.
    // pErr is a record object in the Connection's Error collection.
    ErrorPtr  pErr = NULL;
    long      nCount = 0;
    long      i = 0; if( (pConnection->Errors->Count) > 0)
    {
    nCount = pConnection->Errors->Count;
    // Collection ranges from 0 to nCount -1.
    for(i = 0; i < nCount; i++)
    {
    pErr = pConnection->Errors->GetItem(i);
    printf("\n\t Error number: %x\t%s", pErr->Number, (LPCSTR)pErr->Description);
    }
    }
    }
    /*
    CREATE PROCEDURE "ONEGA"."TestProc1" 
    (
    p_out OUT numeric,
    p_id IN numeric DEFAULT 1
    )
    IS
    BEGIN
    p_out:= p_id + 1234;return;
    END ;
     */
    int main(int argc, char* argv[])
    {
    printf("Use ADO to open Oracle!\n");
    CoInitialize(NULL);
    _ConnectionPtr pConn("ADODB.Connection");
    try
    {
    _CommandPtr    Cmd1;
    Cmd1.CreateInstance( __uuidof( Command ) );
    _ParameterPtr outParam=NULL;
    _RecordsetPtr  pRst("ADODB.Recordset");
    pConn->Open("Provider=OraOLEDB.Oracle;Data Source=workdb;User Id=Onega;Password=sa;"
    ,"","",adConnectUnspecified);
    Cmd1->ActiveConnection = pConn;
    Cmd1->CommandText      = "{call ONEGA.TestProc1( ?)}";
    Cmd1->CommandType      = adCmdText;
    outParam = Cmd1->CreateParameter("p_out",adInteger,adParamOutput,sizeof(int));
    Cmd1->Parameters->Append(outParam);
    Cmd1->Execute(NULL,NULL,adExecuteNoRecords);
    long p2=Cmd1->Parameters->Item["p_out"]->Value;
    printf("p2= %d,\n",p2);
    pConn->Close();
    }
    catch(_com_error &e)
    {
    _bstr_t bstrSource(e.Source());
    _bstr_t bstrDescription(e.Description());
    printf("\nCOM error occurred, Source : %s \n Description : %s \n",(LPCSTR)bstrSource,(LPCSTR)bstrDescription);
    PrintProviderError(pConn);
    }
    ::CoUninitialize();
    printf("program end.\n");
    return 0;
    }
      

  3.   

    to taianmonkey() :
    路过,如果还有一个输入参数呢?上面代码怎么改?
    Cmd1->CommandText      = "{call ONEGA.TestProc1( ?)}"; 这是什么?
      

  4.   

    "Call Procedure_Name" 语句应该应该是这样执行的吧
    CrecordSet oSet(m_pdb);
    oSet.open("{Call Procedure_Name}");
    但是我不知道执行有输出参数的过程怎么写?
    还有"{call ONEGA.TestProc1( ?)}"中的?什么意思?怎么把输出参数得到呢?
    还请高手指点。
    ps:ODBC方法哦!
      

  5.   

    要这样
    m_pdb.ExcuteSQL("{Call Procedure_Name}");