12-4. Writing and Executing PL/SQL

Problem

You want to use Oracle SQL Developer to execute an anonymous block of code.

Solution

Establish a connection to the database of your choice, and the SQL worksheet will automatically open. Once the worksheet has opened, you can type the code directly into it. For the purposes of this recipe, type or copy/paste the following anonymous block into a SQL worksheet:

DECLARE   CURSOR emp_cur IS   SELECT * FROM employees;   emp_rec emp_cur%ROWTYPE; BEGIN   FOR emp_rec IN emp_cur LOOP     DBMS_OUTPUT.PUT_LINE(emp_rec.first_name || ' ' || emp_rec.last_name);   END LOOP; END;

Figure 12-8 shows the Oracle SQL Developer worksheet after this anonymous block has been written into it.

Figure 12-8. Oracle SQL ...

Get Oracle and PL/SQL Recipes: A Problem-Solution Approach now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.