~~~~~~~~~~~~~~~~~~~~~faint~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~faint~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~faint~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~faint~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~faint~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~faint~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~faint~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~faint~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~faint~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~faint~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~faint~~~~~~~~~~~~~~~~~~~~~~~
键集游标 — 其行为类似动态游标,不同的只是禁止查看其他用户添加的记录,并禁止访问其他用户删除的记录,其他用户所作的数据更改将依然可见。它始终支持书签,因此允许 Recordset 中各种类型的移动。
静态游标 — 提供记录集合的静态副本以查找数据或生成报告。它始终支持书签,因此允许 Recordset 中各种类型的移动。其他用户所作的添加、更改或删除将不可见。这是打开客户端 (ADOR) Recordset 对象时唯一允许使用的游标类型。
仅向前游标 — 除仅允许在记录中向前滚动之外,其行为类似动态游标。这样,当需要在 Recordset 中单程移动时就可提高性能。
简要语法:/*sybase T_SQL语法*/
create proc p1 输入参数......,输出参数 output......
as
begin
declare 变量......
select 字段...... into #temp from table where ....../*创建临时表*/
declare cursor c1 /* */
for /*定义游标*/
select 字段...... from #temp /* */
open c1/*打开游标*/
fetch into 变量....../*取游标中的数据给变量赋植*/
select 变量...... /*输出结果集*/
while @@sqlstatus <> 2/*如果不是最后一行,在往下取*/
fetch into 变量....../*取游标中的数据给变量赋植*/
select 变量...... /*输出结果集*/
end如果你要把游标返回的数据存到临时表里的话,就把select 变量...... /*输出结果集*/
改为insert into #temp1 values(变量...... ),#temp1在存储过程开头先建好。再说一句,存储过程里面并不是只能建一个临时表,其实把游标说成是临时表有点不恰当,游标里的数据要fetch到变量里面才能输出,我想sql server也是这样的吧!
够了吧,记得要给我加分呀!
~~~~~~~~~~~~~~~~~~~~~very faint~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~very faint~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~very faint~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~very faint~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~very faint~~~~~~~~~~~~~~~~~~~~~~~
if exists (select name from sysobjects where name='mypro' and type='p')
drop procedure my
if exists(select table_name from information_schema.table
where table_name='#pro' )
drop table #pro
go
create procedure mypro
@proname varchar(14),---表名 @mycursor cursor varying output--返回游标
as
declare @tj1 varchar(250)
set @tj1='where id=001 and code=21 group by id,code,date,name
order by id,code'
exec('select id,code,date,name into #pro from'+' '+@proname+' '+@tj1)
set @mycursor=cursor static for
select * from #pro
open @mycursor
go--以下是对返回的游标进行调用的批处理
declare @usecursor cursor
exec mypro 'tablename',@mycursor=@usecursor output
while @@fetch_status=0
begin
fetch next from @usecursor
end
close @usecursor
deallocate @usecursor
以上是我写的一个返回游标的存储过程和对它的测试。原来的要求是用ASP调用返回的游标@mycursor,以便把查询出来的记录(可能有好几万条)进行分屏显示。可我在用一个批处理进行的调试中发现错误:临时表已存在。游标和临时表#pro都 要用到系统的临时表tempdb,所以会产生冲突,可文档又要用游标返回查询到的记录,请问那有什么方法可解决啊?听说可以用数组,那又应如何做呢(我没做过)?