O'Reilly logo

Oracle and PL/SQL Recipes: A Problem-Solution Approach by Matt Arena, Josh Juneau

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required