|
Answer» In PL/SQL, it is possible to create your own RECORDS i.e. user-defined. With that, you can set the different record structures. Let us take an example of a Laptop’s record. Here is how you can declare: DECLARE
TYPE laptop IS RECORD
(brand varchar(50),
RAM number,
SNO number,
);
l1 laptop;
l1 laptop;You can now access the fields using the dot(.) operator. The following is the example wherein we have created user-define records and accesses the fields: DECLARE
TYPE laptop IS RECORD
(brand varchar(50),
RAM number,
SNO number
);
lp1 laptop;
lp2 laptop;
lp3 laptop;
BEGIN
-- Laptop 1 specification
lp1.brand:= 'Dell';
lp1.RAM:= 4;
lp1.SNO:= 87667;
-- Laptop 2 specification
lp2.brand:= 'Lenevo';
lp2.RAM:= 4;
lp2.SNO:= 47656;
-- Laptop 3 specification
lp3.brand:= 'HP';
lp3.RAM:= 8;
lp3.SNO:= 98989;
-- Laptop 1 record
dbms_output.put_line('Laptop 1 Brand = '|| lp1.brand);
dbms_output.put_line('Laptop 1 RAM = '|| lp1.RAM);
dbms_output.put_line('Laptop 1 SNO = ' || lp1.SNO);
-- Laptop 2 record
dbms_output.put_line('Laptop 2 Brand = '|| lp2.brand);
dbms_output.put_line('Laptop 2 RAM = '|| lp2.RAM);
dbms_output.put_line('Laptop 2 SNO = ' || lp2.SNO);
-- Laptop 3 record
dbms_output.put_line('Laptop 3 Brand = '|| lp3.brand);
dbms_output.put_line('Laptop 3 RAM = '|| lp3.RAM);
dbms_output.put_line('Laptop 2 SNO = ' || lp3.SNO);
END;The OUTPUT: Laptop 1 Brand = Dell
Laptop 1 RAM = 4
Laptop 1 SNO = 87667
Laptop 2 Brand = Lenevo
Laptop 2 RAM = 4
Laptop 2 SNO = 47656
Laptop 3 Brand = HP
Laptop 3 RAM = 8
Laptop 2 SNO = 98989
|