1. Custom composite variable query and output case:
Declare
TYPE myrecord is record (
Aa varchar2 (10 ),
Bb varchar2 (10); -- defines compound Variables
Record1 myrecord;
Begin
Select a1, a2 into record1 from a where a2 = 'mmm'; -- assign a value to the variable
Dbms_output.put_line (record1.aa | record1.bb); -- Query Output Method
End;
/
2. In the case of the % type application, the difference from the previous case is that changing the basic type to the % type of the corresponding table will automatically match, as shown in the following case:
Declare
TYPE recorde is record (
Id emp. eid % type, -- Use % type to define compound data [Table name]. [column name] % type
Name emp. ename % type,
Age emp. eage % type
);
Record1 recorde;
Begin
Select eid, ename, eage into record1 from emp where eid = '08'; -- assign a value
Dbms_output.put_line ('Id: '| record1.id); -- output
Dbms_output.put_line ('name: '| record1.name );
Dbms_output.put_line ('Age: '| record1.age );
End;
/
3. In the application case of % rowtype, unlike the previous one, each sub-variable record of the composite variable is not declared. We can directly declare it with [Table name % rowtype. As follows:
Declare
Myrec emp % rowtype; -- Use % rowtype to declare a composite variable
Begin
Select * into myrec from emp where eid = '010 ';
Dbms_output.put_line ('myrec. eid' | myrec. eid );
Dbms_output.put_line ('myrec. ename' | myrec. ename );
Dbms_output.put_line ('myrec. eage' | myrec. eage );
End;
/