top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is anonymous block using cursor?

+1 vote
258 views

Give any example for getting the product id, from one table that refer salesperson table, and this refer order table. totally there are 3 different tables

posted Jun 25, 2015 by Priyadharshini Kunjithapatham

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

An anonymous block is a PL/SQL program unit that has no name and it does not require the explicit presence of the BEGIN and END keywords to enclose the executable statements. An anonymous block consists of an optional declarative part, an executable part, and one or more optional exception handlers.

The following short example of a PL/SQL anonymous block prints the names of all employees in department 20 in the Emp_tab table, using the DBMS_OUTPUT package:

DECLARE
Emp_name VARCHAR2(10);
Cursor c1 IS SELECT Ename FROM Emp_tab
WHERE Deptno = 20;
BEGIN
OPEN c1;
LOOP
FETCH c1 INTO Emp_name;
EXIT WHEN c1%NOTFOUND;
DBMS_OUTPUT.PUT_LINE(Emp_name);
END LOOP;
END;

Source: http://oracle-plsql-programming-concept.blogspot.in/2012/10/anonymous-blocks.html

answer Jun 25, 2015 by Salil Agrawal
Similar Questions
+3 votes

In what order should a open/fetch/loop set of commands in a PL/SQL block be implemented if you use the %NOTFOUND cursor variable in the exit when statement? Why?

...