存档

文章标签 ‘for read only’,文章数:1

在定义游标时不指定for update 或 for read only,ASE会检查以了解游标是否可更新;

如果游标查询语句中包含order by子句,则ASE会将游标定义为只读;其它情况下定义为可更新游标;

如果不涉及更新或删除表数据的话,建议在游标定义中加上for read only选项,这样ASE将游标定义为只读;

 

表customer在c_custkey列上建有唯一索引,查询表的前10行内容(所有字段拼接成一个字符串),

如果定义游标为for read only:

    declare cur_hash cursor for select top 10 convert(varchar,c_custkey)+coalesce( nullif(isnull(c_name,''), '') , ' ')+coalesce( nullif(isnull(c_address,''),'') , ' ')+convert(varchar,c_nationkey)+coalesce( nullif(isnull(c_phone,''),'') , ' ')+convert(varchar,c_acctbal)+coalesce( nullif(isnull(c_mktsegment,''),'') , ' ')+coalesce( nullif(isnull(c_comment,''),'' ) , ' ') from customer for read only

则使用表扫描返回表的前10行数据;