当前位置:首页 » 存储配置 » 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;

热点内容
电脑网络服务器机主名 发布:2024-11-17 13:22:13 浏览:149
手机存储设备没了怎么办 发布:2024-11-17 13:20:33 浏览:426
保护生态最新脚本 发布:2024-11-17 13:17:34 浏览:1
解脚本工具 发布:2024-11-17 13:12:02 浏览:822
编译器优化有几种 发布:2024-11-17 13:11:58 浏览:387
vbnet判断文件夹是否存在 发布:2024-11-17 13:09:00 浏览:773
objectjava源码 发布:2024-11-17 13:00:37 浏览:352
linux中文字符集 发布:2024-11-17 12:42:28 浏览:305
在哪编译linux 发布:2024-11-17 12:39:27 浏览:903
华为代理服务器ip 发布:2024-11-17 12:38:42 浏览:595