PLSQL Ex
PLSQL Ex
PLSQL Ex
1) Create an Associative array of character datatype and index it by number and perform
the below operations.
Insert 10 values into this array
Delete 3rd element from the array
Delete 7th element from the array
Display the data from the array
2) Create a Nested Table array of character datatype and perform the below operations.
Insert 10 values into this array
Delete 3rd element from the array
Delete 7th element from the array
Display the data from the array
3) Create a VARRAY array of character datatype which holds 10 values and perform the
below operations.
Insert 10 values into this array
Display the data from the array
Answers
1)
DECLARE
TYPE CUSTOMER_TYPE IS TABLE OF VARCHAR2(100) INDEX BY BINARY_INTEGER;
CUSTOMER_TABLE CUSTOMER_TYPE;
V_IDX NUMBER;
BEGIN
CUSTOMER_TABLE(1) := 'AB';
CUSTOMER_TABLE(2) := 'CD';
CUSTOMER_TABLE(3) := 'DE';
CUSTOMER_TABLE(4) := 'FE';
CUSTOMER_TABLE(5) := 'GH';
CUSTOMER_TABLE(6) := 'IG';
CUSTOMER_TABLE(7) := 'KE';
CUSTOMER_TABLE(8) := 'LM';
CUSTOMER_TABLE(9) := 'NO';
CUSTOMER_TABLE(10) := 'PQ';
CUSTOMER_TABLE.DELETE(3);
CUSTOMER_TABLE.DELETE(7);
V_IDX := CUSTOMER_TABLE.FIRST;
END;
2)
DECLARE
TYPE CUSTOMER_TYPE IS TABLE OF VARCHAR2(100) ;
CUSTOMER_TABLE CUSTOMER_TYPE := CUSTOMER_TYPE();
V_IDX NUMBER;
BEGIN
CUSTOMER_TABLE.EXTEND (10);
CUSTOMER_TABLE(1) := 'AB';
CUSTOMER_TABLE(2) := 'CD';
CUSTOMER_TABLE(3) := 'DE';
CUSTOMER_TABLE(4) := 'FE';
CUSTOMER_TABLE(5) := 'GH';
CUSTOMER_TABLE(6) := 'IG';
CUSTOMER_TABLE(7) := 'KE';
CUSTOMER_TABLE(8) := 'LM';
CUSTOMER_TABLE(9) := 'NO';
CUSTOMER_TABLE(10) := 'PQ';
CUSTOMER_TABLE.DELETE(3);
CUSTOMER_TABLE.DELETE(7);
V_IDX := CUSTOMER_TABLE.FIRST;
END;
3)
DECLARE
TYPE CUSTOMER_TYPE IS VARRAY(10) OF VARCHAR2(100) ;
CUSTOMER_TABLE CUSTOMER_TYPE := CUSTOMER_TYPE();
V_IDX NUMBER;
BEGIN
CUSTOMER_TABLE.EXTEND (10);
CUSTOMER_TABLE(1) := 'AB';
CUSTOMER_TABLE(2) := 'CD';
CUSTOMER_TABLE(3) := 'DE';
CUSTOMER_TABLE(4) := 'FE';
CUSTOMER_TABLE(5) := 'GH';
CUSTOMER_TABLE(6) := 'IG';
CUSTOMER_TABLE(7) := 'KE';
CUSTOMER_TABLE(8) := 'LM';
CUSTOMER_TABLE(9) := 'NO';
CUSTOMER_TABLE(10) := 'PQ';
V_IDX := CUSTOMER_TABLE.FIRST;
END;