Inserts and updates using record variables : RECORD « PL SQL Data Types « Oracle PL/SQL Tutorial






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> -- display data in the table
SQL> select * from Employee
  2  /

no rows selected

SQL>
SQL>
SQL>
SQL> create or replace procedure p_insertNewEmp(i_deptno VARCHAR)
  2  is
  3      v_emp_rec employee%ROWTYPE;
  4  begin
  5      select max(id)+1 into v_emp_rec.id from employee;
  6
  7      v_emp_rec.first_Name:='Emp#'||v_emp_rec.id;
  8      v_emp_rec.id :=i_deptno;
  9      v_emp_rec.salary := v_emp_rec.salary+1;
 10      insert into employee values v_emp_rec;
 11  end;
 12  /

Procedure created.

SQL>
SQL> call p_insertNewEmp('01');

Call completed.

SQL>
SQL> select * from employee;

ID   FIRST_NAME               SALARY
---- -------------------- ----------
01   Emp#

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

Table dropped.








21.30.RECORD
21.30.1.Records
21.30.2.Accessing Individual Record elements
21.30.3.Accessing an entire record
21.30.4.Testing for equality of records
21.30.5.Record Variables Based on Tables
21.30.6.Record Variables
21.30.7.Create Record based on table column type
21.30.8.Implicit Declaration
21.30.9.Assigning Record Variables
21.30.10.Using the Record Datatype and its limitation
21.30.11.Records based on tables can also be used in a SELECT statement
21.30.12.Inserts and updates using record variables
21.30.13.Using Records with 'select into'
21.30.14.Retrieving Cursor Variables with a Record Variable
21.30.15.Looping through Records in a Cursor
21.30.16.Looping through multiple records
21.30.17.Perform a field-by-field comparison
21.30.18.Passing Variables without Copying