Home » Oracle » Oracle Sql » What is oracle cursor for loop

What is oracle cursor for loop

We have already read about the Oracle cursor in the below post

What is the cursor in oracle

Let’s check about the oracle cursor for loop. How it is beneficial and How to use it in PLSQL

Oracle Cursor FOR Loops in oracle

oracle cursor for loop

1)The cursor FOR loop is a shortcut to process Explicit cursors

2) Implicit Open, fetch, exit, and close occurs

3) The record is implicitly declared

Example

DECLARE 
 CURSOR dept_cursor is Select deptno,dept_name  FROM   dept;
 BEGIN
 FOR dept_record IN dept_cursor
 LOOP
 Insert into dept_temp (deptno, deptname) values (dept_record.deptno, dept_record.dept_name);
 END LOOP;
 Commit;
 END;
 /

Oracle Cursor For Loops Using Subqueries

We can also cursor for loops using subqueries. No need to declare the cursor

Example

BEGIN 
 FOR dept_record IN (Select deptno,dept_name  FROM   dept)
 LOOP
 Insert into dept_temp (deptno, deptname) values (dept_record.deptno, dept_record.dept_name);     
 END LOOP;
 Commit;
 END;
 /

I hope you like this article on oracle cursor for loop. Please do provide the feedback

Related Articles

date functions in Oracle sql
Oracle PLSQL Tables: Check out this post for a detailed description of PLSQL Tables.How to manipulate it and work on it in Oracle PLSQL block and benefits
Oracle PLSQL records: Check out this article on the working of oracle plsql records.Also, find out the various ways to define it and assign value to it
oracle plsql interview questions : Check out this post for 25 Oracle PlSQL interview questions with detailed explanation and answer for the success in an interview
Oracle PLSQL Block: This page contains a good description on Oracle PLSQL Block Structure and types with examples and explanation
Cursor attributes

See also  Active Dataguard in Oracle

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top