中国站长下载-为中国站长提供最好最全的建站资源! 首 页发布资源有事留言繁體中文
设为首页
加入收藏
联系我们
 
您当前的位置:中国站长下载 -> 文章中心 -> 数据库区 -> MSSQL -> 文章内容  虚拟主机 域名注册 退出登录 用户管理
栏目导航
· ACCESS · MSSQL
· Mysql · DB2
· ORACLE · SYBASE
· 其他相关
热门文章
· sndvol32 - sndvol3...
· [组图] FLASH:《大话李白》...
· 个人网站到底能赚多...
· [图文] Rundll.exe是病毒吗...
· [组图] Flash:制作MV
· 价值12万元的网站SE...
· 网站创业者,你需要...
· 一个成功的网站设计...
· [图文] FLASH:韩国导航条解...
· 中国网站的赚钱模式...
相关文章
· 一个oracle+PHP的查...
· BS结构中使用PHP访问...
· 用PHP操纵Oracle的L...
· PHP网站后门的隐藏技...
· PHP 5 数据对象 (PD...
· PHP 5 数据对象 (PD...
· PHP 5 数据对象 (PD...
· PHP 5 数据对象 (PD...
· ASP.NET应用中缓存O...
· ASP.NET应用中缓存O...
Oracle Pro*C/C++游标和存储过程性能测试报告
作者:佚名  来源:不详  发布时间:2006-5-9 16:47:49  发布人:chinazhan

 减小字体 增大字体

1.1 目的说明进行Oracle数据库Pro*C/C++编程往往要对数据库中的记录进行读取,Pro*C/C++开发工具提供了二种对数据库读写的方法:一种我称之为游标(Cursor)的方式;另一种是C语言调用Oracle PL/SQL编程的储存过程方式;这二种方式在编程选择方面一般都没有太多数值比较说明,本文将实际编写测试代码,对这二种编码方式进行实际速度测试为各位读者在以后工作中进行编码选择提供经验。测试环境 二台PC机其中一台是数据库服务器,另一台是客户端即本文测试代码运行机器硬件 CPU P4 2.6 内存 1G硬盘 80G软件 windows2000 Oracle 8.1.7 VC61.2 测试记录
直接使用游标(cursor)和采用存储过程进行整表同步的测试结果 表1 120000条记录测试结果测试次数
使用cursor方式(TD)
使用PL/SQL方式(WCDMA)


5'22"
7"


1'23"
8"


1'15"
7"


1'22"
7"


2'20"
6"


1'19"
8"


2'32"
8"

平均
2’13.3”
7.3”
表2 3000条记录测试结果测试次数
使用cursor方式(TD)
使用PL/SQL方式(WCDMA)


3"
0"


2"
0"


2"
0"


2"
0"


2"
0"

平均
2.2”
0”
表3 9000条记录测试结果测试次数
使用cursor方式(TD)
使用PL/SQL方式(WCDMA)


0"
0"


14"
1"


9"
0"


13"
1"


10"
0"

平均
9.2”
0.4”
根据测试结果可以看出的确用存储过程在大数据量时是极其有优势的,特别是在大数据量的情况下,并且存储过程的性能极其稳定,cursor方式由于时间长,感觉受网络状况影响较大,时间长短不定。可以得出结论使用储存过程将18倍的提高数据查询读取速度。1.3 部分测试代码
1.3.1 测试表脚本:
创建用于查询的表drop table tb_boardt;create table tb_boardt( BYBOARDTYPE NUMBER(3), ABYBOARDNAME VARCHAR2(15)) tablespace cm_space; 用储存过程向表中插入需要查询的120000记录:)declarei integer :=0;begin for i in 1..20000 loop insert into tb_boardt values(1,'Allen_BOARD'); insert into tb_boardt values(2,'LILY_BOARD'); insert into tb_boardt values(4,'LIL_BOARD'); insert into tb_boardt values(5,'ALLEN_BOARD'); insert into tb_boardt values(6,'BEMC_BOARD'); insert into tb_boardt values(7,'TWIM_BOARD'); commit; end loop;end;/ 用于读取记录的存储过程包头create or replace package testEptTbl as type charArrayType is table of varchar2(2048) index by binary_integer; type lcharArrayType is table of varchar2(2048) index by binary_integer; type numArrayType is table of int index by binary_integer; num INTEGER; m_RncID INTEGER; procedure get_R0BrdLib( batch_size in integer, found in out integer, done_fetch out integer, BoardType1 out numArrayType,/*单板类型Board Type*/ BoardName1 out charArrayType/*各子单元类型包含的子单元个数Sunit Number Per Type*/); end testEptTbl;/show err 用于记录的存储过程包体create or replace package body testEptTbl as /* 3 */ cursor CUR_R0BrdLib is SELECT BYBOARDTYPE,ABYBOARDNAME FROM tb_boardt; procedure get_R0BrdLib( batch_size in integer, found in out integer, done_fetch out integer, BoardType1 out numArrayType,/*单板类型Board Type*/ BoardName1 out charArrayType/*各子单元类型包含的子单元个数Sunit Number Per Type*/) is begin if not CUR_R0BrdLib%isopen then open CUR_R0BrdLib; end if; done_fetch := 0; found := 0; for i in 1..batch_size loop fetch CUR_R0BrdLib into BoardType1(i),BoardName1(i); if CUR_R0BrdLib%notfound then close CUR_R0BrdLib; done_fetch := 1; exit; else found := found + 1; end if; end loop; end get_R0BrdLib;end testEptTbl;/show err 1.3.2 游标方式:
//倒出数据到zdb void CBOARDT::WriteZdb(int SubNetID,int NodeBID) { EXEC SQL BEGIN DECLARE SECTION; int iSubNetID = SubNetID; int iNodeBID = NodeBID; EXEC SQL END DECLARE SECTION; char tmpbuf[128],StartTime[256],EndTime[256]; /* Set time zone from TZ environment variable. If TZ is not set, * the operating system is queried to obtain the default value * for the variable. */ _tzset(); /* Display operating system-style date and time. */ _strtime( tmpbuf ); sprintf( StartTime,"OS time:\t\t\t%s\n", tmpbuf ); /* Declare a cursor for the FETCH. */ EXEC SQL DECLARE CUR_R_BOARDT CURSOR FOR SELECT byBoardType, abyBoardName FROM TB_BOARDT; EXEC SQL OPEN CUR_R_BOARDT; /* Initialize the number of rows. */ num_ret = 0; int rows_ret=BATCHSIZE; while (BATCHSIZE == rows_ret) { // Fetch from the Cursor, catching all ORA ERROR condition EXEC SQL WHENEVER SQLERROR DO sqlerror(m_dbheader); EXEC SQL FETCH CUR_R_BOARDT INTO :bHostVar1,:chHostVar1; /* Write however many rows were returned. */ rows_ret=sqlca.sqlerrd[2] - num_ret; WriteBatchToZdb(rows_ret,"b01c01"); num_ret = sqlca.sqlerrd[2]; /* Reset the number. */ } /* Write remaining rows from last fetch, if any. */ if ((sqlca.sqlerrd[2] - num_ret) > 0) WriteBatchToZdb(sqlca.sqlerrd[2] - num_ret,"b01c01"); m_dbheader.dbTupleNum=sqlca.sqlerrd[2]; EXEC SQL CLOSE CUR_R_BOARDT; _strtime(tmpbuf); sprintf(EndTime,"OS time:\t\t\t\t%s\n", tmpbuf ); printf("begin time: %s\n",StartTime); printf("end time: %s\n",EndTime); WriteZdbHeader();}1.3.3 存储过程方式:
//倒出数据到zdb void CBRDLIB::WriteZdb(int SubNetID,int NodeBID) { DWORD TupleNum=0; char tmpbuf[128],StartTime[256],EndTime[256]; /* Set time zone from TZ environment variable. If TZ is not set, * the operating system is queried to obtain the default value * for the variable. */ _tzset(); /* Display operating system-style date and time. */ _strtime( tmpbuf ); sprintf( StartTime,"OS time:\t\t\t%s\n", tmpbuf ); do { EXEC SQL EXECUTE BEGIN testEptTbl.get_R0BrdLib (:array_size, :num_ret, :done_flag,:bHostVar1,:chHostVar1); END; END-EXEC; TupleNum=TupleNum+num_ret;// print_rows(num_ret); WriteBatchToZdb(num_ret,"b01c01"); }while(!done_flag); m_dbheader.dbTupleNum=TupleNum; _strtime(tmpbuf); sprintf(EndTime,"OS time:\t\t\t\t%s\n", tmpbuf ); printf("brdlib begin time: %s\n",StartTime); printf("end time: %s\n",EndTime); WriteZdbHeader();} /*-------------CTable Factory-----------------*/CTable* CTable::Factory(int type){ switch( type ) { //R0 case 2 : return new CBOARDT; break; case 1 : return new CBRDLIB; break; } return NULL; }    asp">oracleasp">存储过程
 
[] [返回上一页] [打 印] [收 藏]
∷相关文章评论∷    (评论内容只代表网友观点,与本站立场无关!) [更多评论...]
中国站长下载
中国站长下载

本页只接受PR>=4 IT类站点连接,申请连接,谢谢您们的支持!希望我们的下载站能够真正帮到中国的站长们!
关于本站 - 网站帮助 - 广告合作 - 下载声明 - 友情连接 - 网站地图
Copyright © 2005-2006 ChinaZhan.Net. All Rights Reserved .