Oracle批量处理SQL

批量更新且更新字段数字需要递增

示例:

DECLARE
n int; -- 定义变量
BEGIN
n:=1000010; --为n 赋值
FOR i IN (SELECT AGENCY.ID FROM AGENCY LEFT JOIN RELATIONSHIP ON RELATIONSHIP.CHILDREN_AGENCY_ID = AGENCY.ID WHERE RELATIONSHIP.PARENT_AGENCY_ID = 51633735479297  AND AGENCY.STATUS = 'N' AND AGENCY.LEVEL_ = 2) LOOP
    UPDATE AGENCY a SET a.STORE_NO = n
    WHERE a.ID = i.ID;
n:=n+1; -- n 以此+1
END loop;
END;

批量插入

示例:

-- 最后的select也算是插入,不加的话会报错
insert all into Student(id, name, sex, age, tel)
    into Student(id, name, sex, age, tel) values ('12', 'jack1', '男', 12, '13345674567' )
    into Student(id, name, sex, age, tel) values ('13', 'jack2', '男', 13, '13345674567')
    select '14', 'jack', '男', 13, '13345674567' from dual;
posted @ 2021-12-16 18:33  阿尔法哲  阅读(242)  评论(0编辑  收藏  举报