Oracle 循环 for loop
创建临时表
CREATE TABLE TMP(
ID NUMBER,
A VARCHAR(256)
)
循环N次 写入测试数据
BEGIN
FOR N IN 1..10 LOOP
INSERT INTO TMP VALUES(N,'');
COMMIT;
END LOOP;
END;
通过查询结果循环
通过循环修改
BEGIN
FOR DATAROW IN (SELECT ID FROM TMP) LOOP
UPDATE TMP SET A = TO_CHAR(SYSDATE,'YYYYMMDD')
WHERE ID = DATAROW.ID;
COMMIT;
END LOOP;
END;