string类的replace方法略显奇怪,要实现字符串替换,还需自己写代码,如下:

string& string_replace(string& strSrc, string strOld, string strNew)
{
	while (true)
	{
		// 在strSrc中查找strOld
		size_t index = strSrc.find(strOld);
		if (index == string::npos)
		{
			break;
		}

		// 从index开始,把strSrc中的strOld.length()个字符替换为strNew
		strSrc = strSrc.replace(index, strOld.length(), strNew);
	}

	return strSrc;
}

本文链接地址: 使用STL的string类进行字符串替换
https://blog.qingfengju.com/index.asp?id=385

分类:Win32/C++ 查看次数:3637 发布时间:2013/3/12 16:46:14

declare @startTime datetime 
set @startTime = getdate()
if object_id('tempdb..#tmpTable') is not null
drop table #tmpTable;

declare @RowCount int = 0;
select ROW_NUMBER() over(ORDER BY ID ASC) as RowNumber,名称 into #tmpTable from 客户;
set @RowCount = @@ROWCOUNT;

create clustered index index_tmp On #tmpTable(RowNumber ASC) with FILLFACTOR = 100;

declare @CustName varchar(50);
declare @iRow int = 0;
while(@iRow < @RowCount)
begin
  set @iRow = @iRow + 1; 
  select top 1 @CustName=名称 from #tmpTable where RowNumber = @iRow ;
end;

drop table #tmpTable;

select datediff(ms,@startTime,getdate()) as '耗时','毫秒' as '单位'
不过,测试发现此方法和加了 FAST_FORWARD 的游标性能基本一致。
10000条记录,在T3400,SSD 830 Series,SQL2008上需要的时间都是200ms。

参考文章中提到的其他方法则远不如游标的性能,可能需要进一步验证。

参考:
http://support.microsoft.com/kb/111401
http://www.searchdatabase.com.cn/showcontent_24030.htm
http://wenku.baidu.com/view/94656feb172ded630b1cb6a6.html

本文链接地址: 不使用游标遍历记录集
https://blog.qingfengju.com/index.asp?id=321

分类:数据库 查看次数:4765 发布时间:2013/3/1 11:35:11