在做了前面的插入数据的实验以后,感觉更新也应该差不多的,所以就动手做执行存储过程的例子了,下面介绍一下:
首先是存储过程的代码:
create or replace procedure QUERYSTRUCT(TableName in nvarchar2,Res out nvarchar2) is
cname all_tab_columns.COLUMN_NAME%type;
dtype all_tab_columns.DATA_TYPE%type;
clen all_tab_columns.CHAR_LENGTH%type;
dpri all_tab_columns.DATA_PRECISION%type;
temp nvarchar2(10);
cursor c(tname nvarchar2) is
select column_name,data_type,char_length,data_precision
from all_tab_columns
where owner='LIUGANG'
and table_name = upper(tname);
begin
open c(TableName);
loop
fetch c into cname,dtype,clen,dpri;
exit when c%notfound;
if dtype != 'NUMBER' then
temp:=TO_CHAR(clen);
else
temp:=TO_CHAR(dpri);
end if;
Res:= Res || rpad(cname,7,' ') || dtype || '(' || temp || ')'|| CHR(10);
end loop;
close c;
end QUERYSTRUCT;
这个存储过程是实现查询表的结构的功能的
下面是OCI的代码:
sprintf( szSqlStr,"%s", "begin querystruct(:tname,:res); end;");
OCIStmtPrepare(m_stmthp, m_errhp, (text*)szSqlStr, (ub4)strlen(szSqlStr),(ub4) OCI_NTV_SYNTAX, (ub4)OCI_DEFAULT);
OCIBindByPos(m_stmthp, &bndp, m_errhp, 1, (dvoid *)tname, (sb4)sizeof(tname), SQLT_STR, NULL, NULL, NULL, 0, NULL, (ub4)OCI_DEFAULT);
OCIBindByPos(m_stmthp, &bndp, m_errhp, 2, (dvoid *)res, (sb4)sizeof(res), SQLT_STR, NULL, NULL, NULL, 0, NULL, (ub4)OCI_DEFAULT);
OCIStmtExecute( m_svchp, m_stmthp, m_errhp, (ub4)1, (ub4) 0,(OCISnapshot *) NULL,(OCISnapshot *) NULL, (ub4)OCI_DEFAULT);
cout << res << endl;
下面是运行的结果:
posted on 2007-05-28 20:44
LG 阅读(3963)
评论(0) 编辑 收藏 引用 所属分类:
CPlusPlus