1.
-- 定義游標
cursor c_student is
select id, first_name, last_name, major from t_test_students;
-- 遍歷游標
open c_student;
loop
fetch c_student
into v_newid, v_newfirstname, v_newlastname, v_newmajor;
exit when c_student%notfound;
insert into t_test_students
(id, first_name, last_name, major)
values
(v_newid, v_newfirstname, v_newlastname, v_newmajor);
end loop;
close c_student;
commit; 2.
-- 定義游標
cursor c_student is
select id, first_name, last_name, major from t_test_students;
-- 遍歷游標
fetch c_student into v_newid, v_newfirstname, v_newlastname, v_newmajor;
while c_student%found loop
insert into t_test_students
(id, first_name, last_name, major)
values
(v_newid, v_newfirstname, v_newlastname, v_newmajor);
fetch c_student into v_newid, v_newfirstname, v_newlastname, v_newmajor;
end loop;
close c_student;
commit; 3.
cursor c_student is
select id, first_name, last_name, major from t_test_students;
for v_student in c_student loop
insert into t_test_students
(id, first_name, last_name, major)
values
(v_student.id, v_student.first_name, v_student.last_name, v_student.major);
end loop;
commit; 4.
/* 不需要定義游標
cursor c_student is
select id, first_name, last_name, major from t_test_students; */
for v_student in (select id, first_name, last_name, major from t_test_students) loop
insert into t_test_students
(id, first_name, last_name, major)
values
(v_student.id, v_student.first_name, v_student.last_name, v_student.major);
end loop;
commit;
遍歷的幾種方式
es5的話也可以使用foreach,es5具有遍歷陣列功能的還有map filter some every reduce reduceright等,只不過他們的返回結果不一樣。但是使用 foreach 遍歷陣列的話,使用 break 不能中斷迴圈,使用 return 也不能返回到外層函式。使用for...
集合的幾種遍歷方式
listlist new arraylist list.add aaa list.add bbb list.add ccc 普通for迴圈 for int i 0 i list.size i 增強for迴圈 for string string list 使用迭代器 iteratorite list....
C Vector遍歷的幾種方式()
include include using namespace std struct point int main 第一種遍歷方式,下標 cout 第一種遍歷方式,下標訪問 endl for int i 0 i iterator iter m testpoint.begin iter m testp...