Select data into record type data : Select into « PL SQL Statements « Oracle PL/SQL Tutorial






SQL>
SQL> set serveroutput on
SQL> set echo on
SQL> -- create demo table
SQL> create table Employee(
  2    ID                 VARCHAR2(4 BYTE)         NOT NULL,
  3    First_Name         VARCHAR2(10 BYTE),
  4    Salary             Number(8,2)
  5  )
  6  /

Table created.

SQL>
SQL> -- prepare data
SQL> insert into Employee(ID,  First_Name, Salary)
  2               values ('01','Jason', 1234.56)
  3  /

1 row created.

SQL> insert into Employee(ID,  First_Name, Salary)
  2                values('02','Alison', 6661.78)
  3  /

1 row created.

SQL>
SQL>
SQL> -- display data in the table
SQL> select * from Employee
  2  /


ID   FIRST_NAME     SALARY
---- ---------- ----------
01   Jason         1234.56
02   Alison        6661.78

SQL>
SQL>
SQL> SET ECHO ON
SQL>
SQL> DECLARE
  2      TYPE EmployeeTypee IS RECORD (
  3          id employee.id%type,
  4          name employee.first_name%type,
  5          salary employee.salary%type
  6      );
  7
  8      emp EmployeeTypee;
  9  BEGIN
 10      SELECT id, first_name, salary INTO emp
 11      FROM employee
 12      WHERE id = 2;
 13
 14      DBMS_OUTPUT.PUT_LINE('emp_record.id: ' || emp.id);
 15      DBMS_OUTPUT.PUT_LINE('emp_record.id: ' || emp.name);
 16      DBMS_OUTPUT.PUT_LINE('emp_record.id: ' || emp.salary);
 17  END;
 18  /
emp_record.id: 02
emp_record.id: Alison
emp_record.id: 6661.78

PL/SQL procedure successfully completed.

SQL>
SQL>
SQL> -- clean the table
SQL> drop table Employee
  2  /

Table dropped.

SQL>








22.10.Select into
22.10.1.Use Select into statement to assign value to a variable
22.10.2.Multiple-Row SELECT Command with Several Exception-Handling Routines: set value in exception handler
22.10.3.Select data into record type data
22.10.4.Select data into PL/SQL table of cursor
22.10.5.Select count value into a variable
22.10.6.Use if statement to check the selected into value
22.10.7.Use more than one entrances in if statement to handle the value returned from a select into
22.10.8.Retrieving a single row: The basic syntax
22.10.9.Use IF-THEN-ELSE to check the return value from the select into statement
22.10.10.SELECT into ROWTYPE
22.10.11.SELECT into TYPE
22.10.12.Multiple-row SELECT command.
22.10.13.Multiple-row SELECT command with several exception-handling routines
22.10.14.Create a loop that prints a list of all employees and their managers
22.10.15.You must have the same datatypes in both the SELECT and INTO clauses.
22.10.16.select pair value into two variables
22.10.17.Build an anonymous block that will trigger an error.
22.10.18.Demo a SELECT INTO with exception handling
22.10.19.Select into and subquery