MOCKSTACKS
EN
Questions And Answers

More Tutorials









Oracle Cursors

Parameterized "FOR loop" Cursor


DECLARE
 CURSOR c_emp_to_be_raised(p_sal emp.sal%TYPE) IS
 SELECT * FROM emp WHERE sal < p_sal;
BEGIN
 FOR cRowEmp IN c_emp_to_be_raised(1000) LOOP
 DBMS_OUTPUT.Put_Line(cRowEmp .eName ||' ' ||cRowEmp.sal||'... should be raised ;)');
 END LOOP;
END;
/

Implicit "FOR loop" cursor


BEGIN
 FOR x IN (SELECT * FROM emp WHERE sal < 100) LOOP
 DBMS_OUTPUT.Put_Line(x.eName ||' '||x.sal||'... should REALLY be raised :D');
 END LOOP;
END;
/

.First advantage is there is no tedious declaration to do (think of this horrible "CURSOR" thing you had in previous versions)

.second advantage is you first build your select query, then when you have what you want, you immediately can access the fields of your query (x.) in your PL/SQL loop

.The loop opens the cursor and fetches one record at a time for every loop. At the end of the loop the cursor is closed.

.Implicit cursors are faster because the interpreter's work grows as the code gets longer. The less code the less work the interpreter has to do.


Conclusion

In this page (written and validated by ) you learned about Oracle Cursors . What's Next? If you are interested in completing Oracle tutorial, your next topic will be learning about: Oracle Sequences.



Incorrect info or code snippet? We take very seriously the accuracy of the information provided on our website. We also make sure to test all snippets and examples provided for each section. If you find any incorrect information, please send us an email about the issue: mockstacks@gmail.com.


Share On:


Mockstacks was launched to help beginners learn programming languages; the site is optimized with no Ads as, Ads might slow down the performance. We also don't track any personal information; we also don't collect any kind of data unless the user provided us a corrected information. Almost all examples have been tested. Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness of all content. By using Mockstacks.com, you agree to have read and accepted our terms of use, cookies and privacy policy.