Total Pageviews

March 11, 2016

3/11/2016 03:38:00 AM
Example 1:- simple program using index by table/associative array.

DECLARE
   TYPE ebiz_type
   IS
      TABLE OF employees%ROWTYPE
         INDEX BY BINARY_INTEGER;

   var_ebiz   ebiz_type;
   v_count       NUMBER (3) := 204;
BEGIN
   FOR i IN 100 .. v_count
   LOOP
      SELECT   *
        INTO   var_ebiz (i)
        FROM   employees
       WHERE   employee_id = i;
   END LOOP;

   FOR i IN var_ebiz.FIRST .. var_ebiz.LAST
   LOOP
      DBMS_OUTPUT.put_line(var_ebiz (i).employee_id
                           || '    '
                           || var_ebiz (i).last_name
                           || '   '
                           || var_ebiz (i).salary);
   END LOOP;
END;


Example 2:- example for creating varray 

Step 1:-

CREATE TYPE ebiz_type AS VARRAY (4) OF NUMBER (4);

Step 2:-

CREATE TABLE test_v
(
   roll_no   NUMBER (3),
   s_name    VARCHAR2 (20),
   marks     ebiz_type
);
Step 3:-
INSERT INTO test_v (roll_no, s_name, marks)
  VALUES   (143, 'ebiz', ebiz_type ('96',
                                    '97',
                                    '98',
                                    '99'));


Example 3:- example for creating nested table we can create it by two types
             
Type 1: - normal nested table

1)    Nested table using number data type.
Step 1:-

CREATE TYPE ebiz_nest_type AS TABLE OF NUMBER;

Step 2:-

CREATE TABLE nest_ebiz
(
   roll_no   NUMBER (3),
   s_name    VARCHAR2 (20),
   dep       NUMBER (3),
   marks     ebiz_nest_type
)

NESTED TABLE marks STORE AS ebiz_king;

Step 3:-

INSERT INTO nest_ebiz (roll_no,
                       s_name,
                       dep,
                       marks)
  VALUES   (143,
            'ebiz',
            420,
            ebiz_nest_type (91,
                            92,
                            93,
                            94,
                            95,
                            96,
                            97,
                            97,
                            98,
                            99))
2)    Nested table using varchar data type.
Step 1:-
CREATE TYPE ebiz_obj AS TABLE OF VARCHAR2 (64);
Step 2:-
CREATE TABLE ebiz_nest_table
(
   e_name      VARCHAR2 (20),
   job_type    VARCHAR2 (20),
   office      VARCHAR2 (20),
   education   nest_test
)

nested table education store as details;

INSERT INTO ebiz_nest_table
  VALUES   ('ebiz',
            'professional',
            'bangalore',
            nest_test ('saint francis high school',
                       'avv junior college',
                       'avv degree college',
                       'thanthai hans roever arts and science college'));
Type 2:-Nested table using object in it.

CREATE TYPE ravs_object
AS
   OBJECT (employee_id NUMBER (4),
           last_name VARCHAR2 (20),
           salary NUMBER (6));

CREATE TYPE ravs_nest AS TABLE OF ravs_object;

CREATE TABLE nest_obj_ebiz
(
   emp_id    NUMBER (3),
   l_name    VARCHAR2 (20),
   dep       NUMBER (3),
   manager   ravs_nest
)
NESTED TABLE manager STORE AS ravs_143;