Вы можете использовать следующее:
declare
stud_Id student_backup.student_id%type;
begin
select nvl(max(student_id),0) into stud_Id
from student_backup
where is_active_flg ='Y';
if stud_Id >0 then
for i in 1 ..stud_Id
loop
insert into users(student_id,password,status)
select b.student_id,'password','status'
from student_backup b
left join users u on b.student_id = u.student_id
where is_active_flg ='Y'
and b.student_id = i;
end loop;
end if;
commit;
end;
/
Демо
PS Если я понял, что вы хотите выступить, вы ненужно использовать цикл for (, включая оператор if ) и оператор select в начале, но непосредственно применить оператор вставки, удалив часть and b.student_id = i
.Итак, конвертируйте ваш блок в следующий:
declare
stud_Id student_backup.student_id%type;
begin
insert into users(student_id,password,status)
select b.student_id,'password','status'
from student_backup b
left join users u on b.student_id = u.student_id
where is_active_flg ='Y' ;
commit;
end;
/