begin for i in (select catcode, catcname from goodscat where catcode like '___') loop-- for循环取数,条件是catcode是4位数,取类别代码与名称 update jxcgoodslist_dayj set lbm4 = i.catcname where lb4 = i.catcode;-- update语句修改jxcgoodslist_dayj表中的lbm4字段,条件是类别代码相等 commit...
for i in 1..10 loop …. end loop; Implicit cursor loop for c in (select ) loop …. end loop; While loop i:=5; while i >10 loop i:=i+1; ... end loop; Basic loop i:=5; loop i:=i+1; …. exit when i>10; end loop;...
declarev_inumber(3):=1;beginwhilev_i<=10loopdbms_output.put_line(v_i);-- 修改变量v_i:=v_i+1;endloop;end; 3.2.3 for循环 --for循环beginforiin1..10loopdbms_output.put_line(i);endloop;end;select*fromstudent;beginforcur_rowin(selectid,name,sex,departmentfromstudent)loopdbms_output....
(1)while循环(2)loop循环(3)for循环三、光标 1、光标的语法 游标(光标):就是一个结果集(在plsql语句中来使用光标来代表一个集合) 光标的语法:CURSOR 光标名[(参数名 数据类型[,参数名 数据类型]...)] IS SELECT 语句; 例如:cursor c1 is select ename from emp; 打开光标: open c1; (打开光标执行查...
plsql中常见的loop循环 --Integerforloopforiin1..10loop ….endloop; ---Implicitcursorloopforcin(select) loop ….endloop; ---Whileloopi:=5;whilei>10loop i:=i+1; ...endloop; ---Basic loopi:=5; loop i:=i+1; ….exitwheni>10;endloop;...
BEGIN SELECT MAX(location_id) INTO v_location_id FROM locations WHERE country_id = v_country_id; FOR i IN 1 .. 3 LOOP dbms_output.put_line(v_location_id); INSERT INTO locations (location_id, city, country_id) VALUES ((v_location_id + i), v_city, v_country_id); ...
游标通常与FOR循环一起使用。以下是一个示例,展示了如何在PL/SQL中使用游标和FOR循环: DECLARE CURSOR my_cursor IS SELECT column1, column2 FROM my_table; BEGIN FOR my_record IN my_cursor LOOP -- 在此处编写对每一行记录的操作 DBMS_OUTPUT.PUT_LINE('Value of column1: ' || my_record.column1)...
select name, dob from students where specialty = v_specialty; begin v_specialty := '%specialty'; dbms_output.put_line('序号 学生 出生日期'); for students_record in students_cur loop dbms_output.put_line(students_cur%rowcount||' '||students_record.name ...
当知道循环范围时可用,循环变量在loop范围内有效,为number类型,plsql隐式定义,会为其自动加1. 当要从游标或select语句取出全部的记录时,可用。循环变量类型为cursor_name%rowtype,plsql隐式定义。 用cursor for loop即简洁又清晰,如: DECLARE CURSOR occupancy_cur IS ...
FOR C IN C_CURSOR LOOP --打印输出结果 DBMS_OUTPUT.PUT_LINE(C_CURSOR%ROWCOUNT||' '||C.employee_id||' '||C.first_name); --循环结束 END LOOP; END; --游标参数传递,在指定数据类型时,不能使用长度约束。 DECLARE --定义游标:就是定义一个游标名,以及与其相对应的 SELECT 语句。 --游标...