Cursor for loop in Oracle

后端 未结 4 1202
时光取名叫无心
时光取名叫无心 2021-01-04 22:18

Please, explain me how to use cursor for loop in oracle.

If I use next code, all is fine.

for rec in (select id, name from students) loop
    -- do a         


        
4条回答
  •  醉话见心
    2021-01-04 22:25

    You're not executing that sql string anywhere. Simply do this

    v_sql := 'select id, name from students';
    open cur for v_sql;
    for rec in cur loop
        -- do anything
    end loop;
    

    Or you can do this

    cursor cur is select id, name from students;
    open cur;
    for rec in cur loop
            -- do anything
    end loop;
    

    Or you can do this

    for rec in (select id, name from students) loop
        -- do anything
    end loop
    

提交回复
热议问题