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

2-1. Retrieving a Single Row from the Database

Problem

You are interested in returning one row from a database table via a query that searches for an exact match.

Solution #1

Use the SELECT…INTO syntax in order to retrieve the row from the database. You can choose to retrieve one or more columns of data from the matching row. The following example depicts a scenario in which a table is queried to return multiple columns from a single row:

DECLARE   first   VARCHAR2(20);   last    VARCHAR2(25);   email   VARCHAR2(25); BEGIN   SELECT first_name, last_name, email   INTO first, last, email   FROM employees   WHERE employee_id = 100;   DBMS_OUTPUT.PUT_LINE(      'Employee Information for ID: ' || first || ' ' || last || ' - ' || email); EXCEPTION ...

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