存储过程写法循环(关于存储过程里使用游标和循环的问题)

本文目录
关于存储过程里使用游标和循环的问题
、带参数游标for循环 一 首先编写存储程整体结构,: create or replace procedure test_proc is v_date date; --变量定义 begin select sysdate into v_date from dual; end test_proc; 二 定义游标: create or replace procedure test_proc is v_date date; --定义变量 cursor cur is select * from ldcode; --定义游标 begin select sysdate into v_date from dual; end test_proc; 三 编写for循环: create or replace procedure test_proc is v_date date; --定义变量 cursor cur is select * from ldcode where rownum《一0; --定义游标 begin select sysdate into v_date from dual; --游标for循环始 for temp in cur loop --temp临变量名,自任意起 Dbms_Output.put_line(temp.Code); --输某字段,使用"变量名.列名"即 end loop; --游标for循环结束 end test_proc; 四 测试运行点击【DBMS Output】标签页查看结图: END 二、带参数游标for循环 一 定义带参数游标: cursor cur(v_codetype ldcode.Codetype%TYPE) is select * from ldcode where codetype = v_codetype; --定义游标 定义游标格式: cursor 游标名称(变量定义) is 查询语句; 注意: where条件变量名v_codetype要与游标定义cur(v_codetype ldcode.Codetype%TYPE)致 二 编写for循环部: --游标for循环始 for temp in cur(’llmedfeetype’) loop --temp临变量名,自任意起 --cur(’llmedfeetype’)"游标名称(传入变量)" Dbms_Output.put_line(temp.Code); --输某字段,使用"变量名.列名"即 end loop; --游标for循环结束 三 测试运行点击【DBMS Outpu
求循环删除数据的存储过程写法
create or replace procedure p_test as
v_c number;
begin
select count(*) into v_c from TB_RP_ODSBUSI_LIST;
v_c := ceil(v_c / 5000);
if v_c 》 10
then
v_c := 10;
end if;
for i in 1 .. v_c
loop
delete TB_RP_ODSBUSI_LIST
where sum_DATE 《= ’201504’
and rownum 《= 5000;
commit;
end loop;
end;
一次删5000条应该是《=

更多文章:
avantage怎么设置为中文(Avantage安装丢失GIT)
2026年10月15日 03:00
activex控件未注册怎么办(登陆视频监控网页时提示activex控件未注册,怎么解决)
2026年10月14日 20:30
excel连接sql数据库教程(excel怎么连接sql数据库)
2026年10月14日 19:40







