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

本文目录
关于存储过程里使用游标和循环的问题
、带参数游标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条应该是《=

更多文章:
false是精确匹配吗(vlookup 函数中的精确匹配和大致匹配的区别)
2026年10月12日 00:50
sumproduct多条件排名不重复(Excel 求助,如何多条件统计不重复个数)
2026年10月11日 23:10
gcc编译器参数(深度linux的arm-linux-gnueabihf-gcc编译参数如何配)
2026年10月11日 19:30
asp是什么检查项目(医院血液检验项目RPR、TPPA、HIV-Ab各是什么意思)
2026年10月11日 10:20
汇编输出指令(用汇编语言循环指令在屏幕中间输出红底白字的“hello I am 720“)
2026年10月11日 07:20
本地搭建springboot项目(使用eclipse构建springboot项目)
2026年10月11日 06:20





