SQL学习笔记之游标
2007-04-14 19:09
441 查看
use bus
select * from citybus
--定义一个简单的游标
declare cursor1 cursor for
select bus_no,stop_name from citybus
where bus_no='221' order by stop_name
open cursor1
fetch next from cursor1
while @@fetch_status=0
begin
fetch next from cursor1
end
close cursor1
deallocate cursor1
go
--定义一个带参的游标
declare @first varchar(20),@second varchar(20)
declare cursor2 cursor for
select bus_no,stop_name from citybus where bus_no='305' order by bus_no
open cursor2
fetch next from cursor2 into @first,@second
while @@fetch_status=0
begin
print 'the bus name is :'+convert(varchar(20),@first)
print 'the stop name is:'+convert(varchar(20),@second)
print '----------------------'
fetch next from cursor2 into @first,@second
end
close cursor2
deallocate cursor2
go
--查找221的第一站:
declare dd cursor for
select stop_name from citybus where bus_no='221'
open dd
fetch next from dd
close dd
deallocate dd
go
--search the 221's last busstop
declare last1 scroll cursor for
select top 5 stop_name from citybus where bus_no='221'
open last1
fetch last from last1
close last1
deallocate last1--delete the cursor.
go
--游标修改数据
declare cur1 scroll cursor for select * from citybus
open cur1
fetch absolute 6 from cur1
update citybus set stop_name='营门口公交站' where id=4
close cur1
deallocate cur1
go
select * from citybus
--定义一个简单的游标
declare cursor1 cursor for
select bus_no,stop_name from citybus
where bus_no='221' order by stop_name
open cursor1
fetch next from cursor1
while @@fetch_status=0
begin
fetch next from cursor1
end
close cursor1
deallocate cursor1
go
--定义一个带参的游标
declare @first varchar(20),@second varchar(20)
declare cursor2 cursor for
select bus_no,stop_name from citybus where bus_no='305' order by bus_no
open cursor2
fetch next from cursor2 into @first,@second
while @@fetch_status=0
begin
print 'the bus name is :'+convert(varchar(20),@first)
print 'the stop name is:'+convert(varchar(20),@second)
print '----------------------'
fetch next from cursor2 into @first,@second
end
close cursor2
deallocate cursor2
go
--查找221的第一站:
declare dd cursor for
select stop_name from citybus where bus_no='221'
open dd
fetch next from dd
close dd
deallocate dd
go
--search the 221's last busstop
declare last1 scroll cursor for
select top 5 stop_name from citybus where bus_no='221'
open last1
fetch last from last1
close last1
deallocate last1--delete the cursor.
go
--游标修改数据
declare cur1 scroll cursor for select * from citybus
open cur1
fetch absolute 6 from cur1
update citybus set stop_name='营门口公交站' where id=4
close cur1
deallocate cur1
go
相关文章推荐
- PL/SQL学习笔记-游标
- SQL学习笔记之游标
- PL/SQL学习笔记之游标
- T-SQL 游标学习笔记
- PL/SQL学习笔记_02_游标
- Oracle 学习笔记 16 -- 游标(PL/SQL)
- 【SQL Server学习笔记】T-SQL中的流程控制、游标
- 【数据库学习笔记】Oracle_03_PL/SQL深入:游标编程,自定义异常
- SQL学习笔记7 游标 约束 索引 触发器
- 学习笔记_oracle——游标与动态SQL
- 【SQL Server学习笔记】T-SQL中的流程控制、游标
- 工作学习笔记——用SQL语句新建SQL SERVER数据库、数据库用户以及登录名
- 黑马程序员之SQL server基础学习笔记(五)
- Sql语句学习笔记(4)-查询1
- 【SQL SERVER学习笔记】Sqlserver游标的尝试
- sql语句学习笔记(6)-常用字符串操作函数
- oracle开发之<<SQL Cookbook>>学习笔记整理:第二章 查询结果排序
- Oracle SQL Plus Tutorial 学习笔记
- oracle开发之<<SQL Cookbook>>学习笔记整理:第三章 操作多个表
- SQL入门学习笔记1.0