You are on page 1of 6

Topic : Oracle Complex Data Type

Author : Subhobrata Mukherjee(subhobrata.mukherjee@tcs.com)


Emp Id : 521486
Date : 30 August 2014





































Oracle Complex Data Type




Records



Records are used for related bits of information. Records are composite datatypes, it is a
combination of different scalar datatypes like char, varchar, number ,integer etc. Each scalar
data types in the record holds a value. A record can be visualized as a row of data. It can contain
all the contents of a row.

// First we have to declare the record,


DECLARE

TYPE emp_person IS RECORD (
first_name VARCHAR2(30),
last_name VARCHAR2(30),
age NUMBER,
salary NUMBER
);

-- we have to declare a variable (v_person ) of that type (emp_person)

v_person emp_person;

BEGIN

-- Then we can assign values to the variable.field name

v_person.first_name:= 'Subho';
v_person.last_name := 'Mukherjee';
v_person.age := 26;
v_person.salary := 30000;

end;







DECLARE

// We can also dynamically declare a record based on an entire row of a table

v_person Employees%ROWTYPE;

BEGIN

v_person.fname := 'Subho';
v_person.lname := 'Mukherjee';
v_person.age := 26;
v_person.salary := 30000;

END;
/





























Associative Arrays


DECLARE

// we can declare the index as BINARY_INTEGER,VARCHAR,INTEGER.

TYPE a_array IS TABLE OF VARCHAR2(100)

INDEX BY BINARY_INTEGER;

// we have to declare a variable (v_array) of that type (a_array)


v_array a_array;

BEGIN

// Variable name and in (),we have the index, like the position of 1 is Subho

v_array(1) := 'Subho';
v_array(2) := 'Mukherjee';

END;
/





















Nested Table


Nested table is like associative array, but we dont put the index
The index grows by the extend command.

We have to initiate its memory area
We have to call its constructor first.
Constructor name is same as type name


DECLARE
TYPE t_array IS TABLE OF VARCHAR2(30);

v_array t_array;

BEGIN

-- We have to iniliaze its memeory area
-- We have to call its constructor first.
-- Constructor name is same as type name

v_array := t_array();

v_array.extend;
v_array(1) := 'Subho';

v_array.extend;
v_array(2) := 'Mukherjee';


END;/


























Varray


Varray is alaways declared size.
It cannot grow after it reaches its limit


DECLARE

TYPE t_array IS VARRAY(10) OF VARCHAR2(30);

v_array t_array;

BEGIN
v_array := t_array();

v_array.extend;
v_array(1) := 'Subho';

v_array.extend;
v_array(2) := 'Mukherjee';


END;
/

You might also like