12-4. Writing and Executing PL/SQL


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


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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.