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