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

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.