How to Create TYPE Object in Oracle PLSQL

Here is a way to create %TYPE object in Oracle. The purpose of TYPE statement is to create a variable of the same as table column data type.

Let us say you have created a Table called X. It has three columns such as emp_id, emp_name, and emp_slaray. Table X columns data-types: emp_id number(6), emp_name varchar2 (20), and emp_salary number(6)

IN THIS PAGE

  1. Creating variable using TYPE
  2. Creating array using TYPE

Creating variable using TYPE

Here V_SALARY data type and emp_salaqry data type are the same since %TYPE added for x.emp_salary.

DECLARE
 V_SALARY X.emp_salary%TYPE
BEGIN
 NULL;
END;

Creating array using TYPE

Here is the logic to create an internal array. Define array using the TYPE array_name. TYPE array_name.

DECLARE 
    TYPE EmpSSNarray 
      IS TABLE OF X.emp_id%TYPE 
      INDEX BY SIMPLE_INTEGER;

Related posts

Author: Srini

Experienced Data Engineer, having skills in PySpark, Databricks, Python SQL, AWS, Linux, and Mainframe