ORACLEPL/SQL语法应用:游标,存储过程,触发器-Oracle

Oracle 21NN 4个月前 (06-27) 52次浏览 已收录 0个评论 扫描二维码

ORACLEPL/SQL语法应用:游标,存储过程,触发器。

–游标

–do while

declare

cursor c is select * from t_t_student order by id;

v_record c%rowtype;

begin

open c;

loop

fetch c into v_record;

exit when(c%notfound);

dbms_output.put_line(‘编号:’||v_record.id||’, 姓名:’||v_record.name||’, 年龄’||v_record.age||’,电话:’

||v_record.phone||’,地址:’||v_record.address);

end loop;

close c;

end;

–while循环查找数据始终不对

declare

cursor c is select * from t_t_student order by id;

v_record c%rowtype;

begin

open c;

fetch c into v_record;

while(c%found) loop

fetch c into v_record;

dbms_output.put_line(‘编号:’||v_record.id||’, 姓名:’||v_record.name||’, 年龄’||v_record.age||’,电话:’

||v_record.phone||’,地址:’||v_record.address);

end loop;

close c;

end;

–for循环

declare

cursor c is select * from t_t_student order by id;

v_record c%rowtype;

begin

for v_record in c loop

dbms_output.put_line(‘编号:’||v_record.id||’, 姓名:’||v_record.name||’, 年龄’||v_record.age||’,电话:’

||v_record.phone||’,地址:’||v_record.address);

end loop;

end;

–带参游标

declare

cursor c(v_age t_t_student.age%type) is select * from t_t_student where age = v_age order by id;

v_record c%rowtype;

begin

for v_record in c(24) loop

dbms_output.put_line(‘编号:’||v_record.id||’, 姓名:’||v_record.name||’, 年龄’||v_record.age||’,电话:’

||v_record.phone||’,地址:’||v_record.address);

end loop;

end;

–可变游标,为了改变当前邮编所指数据而使用

declare

cursor c is select * from t_t_student order by id for update;

v_record c%rowtype;

begin

for v_record in c loop

if(v_record.name = ‘李信’) then

update t_t_student set age = 24 where current of c;

end if;

end loop;

commit;

end;

 


本文:ORACLEPL/SQL语法应用:游标,存储过程,触发器-Oracle 本文链接:https://www.21nn.cn/shujuku/oracle/49255.html 本站所以图片、文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如有侵权请邮件与我们联系处理。i@ki4.cn
喜欢 (0)
[1353713598@qq.com]
分享 (0)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址