3- cursor Oracle Basic Operation

1. Cursor

# 将sql返回的结果集用游标进行标注,以后通过对游标的操作来获取结果集的数据
# 定义游标
cursor 游标名 is select语句;

#打开游标
open 游标名;

#提取游标
fetch 游标名 into 变量;

#关闭游标,释放占用的系统资源
close 游标名;
  1. example

Vernacular Commentary: Select a number of data, declare a cursor, save the data.
Open to open a cursor, because a number of records, so use loop cycle.
fetch value, take the cursor select data from memory and to c_empno c_ename (because it is circular, it is determined to exit the exit when. If the cursor which fail to value, exits the back (exit statement if it is determined in the print statement, is last record will be printed twice. because when fetch fail to get value, then the next statement is the print record, that there is no value, the current record is printed, it is equivalent to print more than once, and then determine the next statement no value, and exit) Here Insert Picture Description
Here Insert Picture Description
2. use the cursor to delete the same record the name of the department table, but want to keep the last addition of department (department number largest)
to view the data, lloop leaving only 50, wloop leaving only 60, floop leaving only 65 .
Here Insert Picture Description
View the maximum number for each departmentHere Insert Picture Description
Here Insert Picture Description
Here Insert Picture Description

Published 56 original articles · won praise 34 · views 3656

Guess you like

Origin blog.csdn.net/MicoOu/article/details/103566597