这是一些更简化的伪代码,描述了我要执行的操作:
DECLARE
CURSOR CURSOR_A IS
SELECT FIELD_A1, FIELD_A2
FROM TABLE_A;
vNAME NVARCHAR2(100) := NULL;
BEGIN
FOR RECORD_A IN CURSOR_A LOOP
IF (RECORD_A.FIELD_A1 IS NOT NULL) THEN
vNAME := RECORD_A.FIELD_A1;
ELSE
vNAME := (SELECT FIELD_B
FROM TABLE_B
WHERE TABLE_B.B2 = RECORD_A.A2)
END LOOP;
END;
/
我不允许在PL / SQL块内使用SELECT语句吗?
最佳答案
您可以选择,但需要指定将存储所选数据的变量
DECLARE
CURSOR CURSOR_A IS
SELECT FIELD_A1, FIELD_A2
FROM TABLE_A;
vNAME NVARCHAR2(100) := NULL;
BEGIN
FOR RECORD_A IN CURSOR_A LOOP
IF (RECORD_A.FIELD_A1 IS NOT NULL) THEN
vNAME := RECORD_A.FIELD_A1;
ELSE
SELECT FIELD_B into vNAME
FROM TABLE_B
WHERE TABLE_B.B2 = RECORD_A.A2;
END LOOP;
END;
/