Home > Database > Mysql Tutorial > 基于游标的定位DELETE/UPDATE语句

基于游标的定位DELETE/UPDATE语句

WBOY
Release: 2016-06-07 17:37:19
Original
1508 people have browsed it

如果游标是可更新的(也就是说,在定义游标语句中不包括Read Only 参数),就可以用游标从游标数据的源表中DELETE/UPDATE行,即DELETE/UPDATE基于游标指针的当前位置的操作; 举例: --删除当前行的记录 Declare cur_Depart Cursor For Select cDeptID,cDeptN

如果游标是可更新的(也就是说,在定义游标语句中不包括Read Only 参数),就可以用游标从游标数据的源表中DELETE/UPDATE行,,即DELETE/UPDATE基于游标指针的当前位置的操作;
举例:

--删除当前行的记录
Declare cur_Depart Cursor
For Select cDeptID,cDeptName From Department into @DeptID,@DeptName
Open cur_Depart
Fetch From cur_Depart into @DeptID,@DeptName
Delete From Department Where CURRENT OF cur_Depart
--更新当前行的内容
Declare cur_Depart Cursor
For Select cDeptID,cDeptName From Department into @DeptID,@DeptName
Open cur_Depart
Fetch From cur_Depart into @DeptID,@DeptName
Update Department Set cDeptID='2007' + @DeptID Where CURRENT OF cur_Depart

 

一个Update例子

create table t1 ( id int ) () t1 ,c_update_id id from t1 c_update_id c_update_id () c_update_id c_update_id c_update_id DEALLOCATE c_update_id t1 t1

 

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template