基础数据准备:
create table STUDENT
(
username CHAR(8),
score NUMBER
);
insert into student
select 'zhangsan' username, 80 score from dual;
insert into student
select 'lis' username, 90 score from dual;
insert into student
select 'wangwu' username, 95 score from dual;
commit;
1.小示例:
create or replace procedure test as
cursor cur is
select username from student;
begin
for Temp in cur loop
dbms_output.put_line(Temp.username);
end loop;
end test;
输出:
zhangsan
lis
wangwu
2.在原示例的基础上添加变量
create or replace procedure test1 is
v_score number;
v_username varchar(30);
cursor cur is
select username from student;
begin
for Temp in cur loop
select username into v_username from student where username=Temp.username;
dbms_output.put_line(v_username);
select score into v_score from student where username=Temp.username;
dbms_output.put_line(v_score);
end loop;
end test1;
输出:
zhangsan
80
lis
90
wangwu
95