當前位置:首頁 » 存儲配置 » c怎麼調用存儲過程

c怎麼調用存儲過程

發布時間: 2022-05-06 00:43:06

① 如何在C 中調用oracle存儲過程

http://blog.csdn.net/langeldep/article/details/6779286 C/C++封裝庫ocicpplib調用Oracle存儲過程的方法 看看這個,也許有收獲

② 如何通過c或c++調用存儲過程

給個例子給你看下:
...

_CommandPtr m_cmdptr;
m_cmdptr.CreateInstance(__uuidof( Command ) );

_ParameterPtr inParam2=NULL;
_ParameterPtr inParam3=NULL;
_ParameterPtr inParam4=NULL;
_ParameterPtr outParam1=NULL;
_ParameterPtr outParam2=NULL;
_ParameterPtr outParam3=NULL;

inParam2.CreateInstance(__uuidof(Parameter));
inParam3.CreateInstance(__uuidof(Parameter));
inParam4.CreateInstance(__uuidof(Parameter));
outParam1.CreateInstance(__uuidof(Parameter));
outParam2.CreateInstance(__uuidof(Parameter));
outParam3.CreateInstance(__uuidof(Parameter));

m_cmdptr->ActiveConnection=m_pConnection;
m_cmdptr->CommandType=adCmdStoredProc;
m_cmdptr->CommandText=_bstr_t("proc_XXX");//存儲過程的名稱

//輸入參數
inParam2=m_cmdptr->CreateParameter(_bstr_t("@P1"),adVarChar,adParamInput,32,_bstr_t(P1));
m_cmdptr->Parameters->Append(inParam2);

inParam3=m_cmdptr->CreateParameter(_bstr_t("@P2"),adVarChar,adParamInput,20,_bstr_t(P2));
m_cmdptr->Parameters->Append(inParam3);

//輸出參數
outParam1=m_cmdptr->CreateParameter("@P4",adInteger,adParamOutput,sizeof(int));
m_cmdptr->Parameters->Append(outParam1);
outParam2=m_cmdptr->CreateParameter("@P5",adInteger,adParamOutput,sizeof(int));
m_cmdptr->Parameters->Append(outParam2);
outParam3=m_cmdptr->CreateParameter(_bstr_t("@P6"),adVarChar,adParamOutput,20,_bstr_t(P6));
m_cmdptr->Parameters->Append(outParam3);

//執行

m_cmdptr->Execute(NULL,NULL,adCmdStoredProc);

//取返回值

long p1=m_cmdptr->Parameters->GetItem("@P4")->Value;
long p2=m_cmdptr->Parameters->GetItem("@P5")->Value;

VARIANT vtP6 =m_cmdptr->Parameters->GetItem("@P6")->Value;
if (vtP6.vt != VT_NULL)
strcpy(tp,(_bstr_t)vtP6);

m_cmdptr.Detach;

③ c程序該怎麼樣調用oracle存儲過程並獲取存

如果已經存在一個存儲過程A(參數);
那麼在存儲過程B中可以直接通過:
values := A(參數);即可實現調用。
備註:values必須在初始化過程中進行定義如: values VARCHAR(30);並且此類型必須與A存儲過程返回參數類型一致。

④ 如何調用存儲過程,有返回值的,有參數的,存儲過程中調用存儲過程

create procere proc_a as declare b int; c varchar2(10); begin proc_b(b, c); dbms_output.put_line (c); end procere a; 你照我這個寫吧 proc_b(b, c); proc_b是你調用的帶返回參數的存儲過程 b是輸入變數,c是輸出變數

⑤ 如何在VC中調用存儲過程

定義好一個Connection連接,然後再產生一個Command對象,利用Command 對象進行存儲過程調用
_ConnectionPtr m_Conn;
_CommandPtr m_Command
_variant_t vNULL;//定義為無參數
vNULL.vt = VT_ERROR;
vNULL.scode = DISP_E_PARAMNOTFOUND
m_Conn.CreateInstance( __uuidof( ADODB::Connection ));//初始化一個連接
m_Command.CreateInstance(__uuidof( ADODB::Command));;//初始化一個Command
m_Conn->Open("Provider=sqloledb;Data Source=yjf;Initial Catalog=pubs;User ID=sa;Password=sa","","",adModeUnknown);//在這里用你直接的Connection連接語句
_bstr_t sp_execstr;
sp_execstr="Exec sp_name";//sp_name為存儲過程名,這句話應該可以在SQL Server中直接執行的
m_Command->ActiveConnection=m_Conn;
m_Command->m_CommandTxt=sp_execstr;
m_pRecordset = m_pCommand->Execute(&vNULL,&vNULL,adCmdText);
**********************************************************************************
_ConnectionPtr m_pConnection;
_CommandPtr m_pCommand;
//.cpp中在函數中執行
//建立ado連接
HRESULT hr;
hr=m_pConnection.CreateInstance(__uuidof(Connection));
try
{
if(SUCCEEDED(hr))
{
hr=m_pConnection->Open(_bstr_t(L"Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=Viper;Data Source=Viper"),_bstr_t (L"sa"),_bstr_t (L""),adModeUnknown);
}
}
catch(_com_error & err)
{
AfxMessageBox(err.Description(),MB_OK,0);
AfxMessageBox(err.ErrorMessage(),MB_OK,0);
AfxMessageBox("無法連接SQL SERVER 伺服器,程序將退出。請檢查網路設備",MB_OK,0);
exit(0);
}
//執行儲存過程
CString cvar1,cvar2;
int cvar3;
cvar1=」ddd」;
cvar2=」";
cvar3=0;
try
{
m_pCommand.CreateInstance(__uuidof(Command));
m_pCommand->ActiveConnection=app->m_pConnection;
m_pCommand->CommandType=adCmdStoredProc;
m_pCommand->CommandText=_bstr_t(」pr_zs_dzdy」);
_variant_t vvar1,vvar2,vvar3;
vvar1=_variant_t(_bstr_t(cvar1));
vvar2=_variant_t(_bstr_t(cvar2));
vvar3=_variant_t(cvar3);
_ParameterPtr mp_var1,mp_var2,mp_var3;
mp_var1.CreateInstance(__uuidof(Parameter));
mp_var2.CreateInstance(__uuidof(Parameter));
mp_var3.CreateInstance(__uuidof(Parameter));
mp_var1=m_pCommand->CreateParameter
(
_bstr_t(」var1″),
adVarChar,
adParamInput,
3,
vvar1
);
m_pCommand->Parameters->Append(mp_var1);
mp_var2=m_pCommand->CreateParameter
(
_bstr_t(」var2″),
adVarChar,
adParamOutput,
3,
vvar2
);
m_pCommand->Parameters->Append(mp_var2);
mp_var3=m_pCommand->CreateParameter
(
_bstr_t(」var3″),
adIntger,
adParamOutput,
9,
vvar3
);
m_pCommand->Parameters->Append(mp_var3);
_variant_t vNull;
vNull.vt=VT_ERROR;
vNull.scode=DISP_E_PARAMNOTFOUND;
m_pCommand->Execute(&vNull,&vNull,adCmdStoredProc);
cvar2=mp_var2->Value.bstrVal;
cvar3=mp_var3->Value;
}
catch(_com_error &error)
{
MessageBox(error.ErrorMessage(),」ADO錯誤!」);
MessageBox(error.Description(),」ADO錯誤!」);
}
********************************************************************************
如果用ODBC訪問資料庫的話,可參考下列代碼:
CDatabase * pDatabase = new CDatabase;
TRY
{
pDatabase->OpenEx( _T("DSN=ODBCName;UID=***;PWD=***"), CDatabase::noOdbcDialog);
}
CATCH (CDBException, e)
{
delete pDatabase;
return;
}END_CATCH
SQL.Format("exec sp_Name");//有參數的話直接寫再後面
pDatabase->ExecuteSQL(SQL);
pDatabase->Close();
delete pDatabase;
****************************
below is from MSDN,you can find a lot of technical article in MSDN if you search"stored procere and VC"
good luck
Steps To Reproce Behavior
In the SQL Server 7.0 Query Analyzer select the test database Pubs.
Create the following stored procere. This stored procere returns a recordset and an out parameter count.
if exists (select * from sysobjects where id = object_id(N'[dbo].[GetJobs]') and OBJECTPROPERTY(id, N'IsProcere') = 1)
drop proc GetJobs
go
create proc GetJobs @id as int, @count as int [out] as
begin
Select @count = Count(*) from jobs where job_id >@id
Select * from jobs where job_id >@id
end
go
Use VC App Wizard to create a new console application and modify the code as follows:
#include "stdafx.h"
#include "stdio.h"
#import "C:\PROGRA~1\COMMON~1\System\ado\msado15.dll" no_namespace rename ("EOF", "EOF2")
struct InitOle {
InitOle() { ::CoInitialize(NULL); }
~InitOle() { ::CoUninitialize(); }
} _init_InitOle_;
int main(int argc, char* argv[])
{
_variant_t varErr((long)0, VT_ERROR);
_CommandPtr comm(__uuidof(Command));
_ConnectionPtr conn(__uuidof(Connection));
_bstr_t connstr="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=pubs;Data Source=(local)";
conn->Open(connstr, "", "", adConnectUnspecified);
comm->ActiveConnection=conn;
comm->CommandText="GetJobs";
comm->CommandType = adCmdStoredProc ;
comm->Parameters->Refresh();
_variant_t recs;
comm->Parameters->Item[_variant_t((short)1)]->Value= _variant_t((long)5);
_RecordsetPtr rs = comm->Execute(&recs, &vtMissing,adCmdStoredProc);
_variant_t recordcount= comm->Parameters->Item[_variant_t((short)2)]->Value;
printf("recordcount = %li\n", (long)recordcount);
return 0;
}
Change the Datasource, User ID and password in the connection string above.
The recordcount variant that the above code returns is of type VT_NULL rather than the number of records that the stored procere returns.

⑥ 有一存儲過程,裡面實現了增刪改查,我如何在C/S界面中,事件中調用此存儲過程,舉例說明,求高手解答!

不知道你前台語言,給你個pb中調用的例子,其他的你參考語言的幫助說明
DECLARE MySP PROCEDURE FOR bb//這個是存儲過程名
@ld_date1=:ld_date1,//輸入參數
@ld_date2=:ld_date2,//輸入參數
@li_shitime=:li_shitime OUTPUT;//輸出參數
EXECUTE MySP; //調用名字,隨便定義一個

Fetch Mysp Into :li_shitime;

close mysp;

⑦ 求大神:C語言如何執行SQL sever的存儲過程

執行帶參數的存儲過程的方法如下:
Exec sp_configure 'allow updates',1 --允許更新系統表。
exec dbo.User_ChangeObjectOwnerBatch 'OldOwner','dbo'
以上是兩個例子。
SQL Server中執行帶參數的存儲過程的方法是:
EXEC 存儲過程名字 '參數1','參數2',數值參數
EXEC 是一個關鍵字。
字元串參數使用單引號括起來,數值參數不需要使用單引號

⑧ 關於存儲過程創建和C#調用

declare
@insertId
intBEGIN
TRY
BEGIN
TRAN
--准備事務
intsert
into
a(f1,f2)values
('111','2222')
set
@InsertId=(select
@@IDENTITY)
insert
into
b(f1,f2)values(@InsertId,'3333') COMMIT
TRAN
end
TRY
BEGIN
catch
ROLLBACK--
回滾事務
END
CATCH -----我用的是mssql2008的,估計05的也能運行以上代碼,2000的估計就不行了

⑨ c程序該怎麼樣調用oracle存儲過程並獲取存儲過程中的輸出參數的值

我以前這樣用pro*c 這樣玩的,僅供參考
EXEC SQL EXECUTE
DECLARE
lsid varchar2(60);
lss_this_error_code number;
BEGIN
proctest(:ls_name,lsid); --ls_name 輸入參數 lss_id 輸出
:chId := lsid;-- lsid 輸出返回給C變數chId
END;
END-EXEC;

熱點內容
演算法sum 發布:2024-04-18 10:58:49 瀏覽:20
linux是javaweb 發布:2024-04-18 10:49:30 瀏覽:318
倩女幽魂寶藏演算法 發布:2024-04-18 10:44:20 瀏覽:347
知道伺服器的ip地址怎麼連接 發布:2024-04-18 10:37:53 瀏覽:705
安卓手機的鍵盤如何改成日語 發布:2024-04-18 10:36:07 瀏覽:625
pw壓縮機 發布:2024-04-18 10:35:53 瀏覽:19
qnap搭建java伺服器 發布:2024-04-18 10:35:44 瀏覽:313
王者榮耀qq安卓區最難打的是哪個 發布:2024-04-18 10:34:51 瀏覽:491
如何取消觸手伺服器 發布:2024-04-18 10:34:41 瀏覽:908
壓縮空氣緩沖罐 發布:2024-04-18 10:21:54 瀏覽:93