0% found this document useful (0 votes)
12 views

PLSQL Ex

Uploaded by

Mostafa Elnahass
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

PLSQL Ex

Uploaded by

Mostafa Elnahass
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Exercise # 8

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;

WHILE V_IDX IS NOT NULL LOOP


DBMS_OUTPUT.PUT_LINE('Name ' || CUSTOMER_TABLE(V_IDX));
V_IDX := CUSTOMER_TABLE.NEXT(V_IDX);
END LOOP;

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;

WHILE V_IDX IS NOT NULL LOOP


DBMS_OUTPUT.PUT_LINE('Name ' || CUSTOMER_TABLE(V_IDX));
V_IDX := CUSTOMER_TABLE.NEXT(V_IDX);
END LOOP ;

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;

WHILE V_IDX IS NOT NULL LOOP


DBMS_OUTPUT.PUT_LINE('Name ' || CUSTOMER_TABLE(V_IDX));
V_IDX := CUSTOMER_TABLE.NEXT(V_IDX);
END LOOP ;

END;

You might also like