Records: PL/SQL Record is a combination of fields. Records are used to represent complete row in a table. ‘Record is a group of multiple piece of information, related to one another, called fields’.
PL/SQL supports three types of records:
Table Based Record represents each field in the table. Fields in the record have the same name and datatype as the columns in the table have. Table Based Record is declared with an anchored declaration-using %ROWTYPE.
Write the PL/SQL code to display the ename and sal of emp whose empno is input by user, using table-based record.
SELECT * INTO RS FROM EMP WHERE EMPNO=&ENO;
Programmer Defined Record is declared and defined explicitly by the programmer as per requirement. Firstly a RECORD type is defined and then variable of that RECORD type is declared.
Write the PL/SQL code to display the ename and sal of emp whose empno is input by user, using programmer-based record.
TYPE RS_EMP IS RECORD
SELECT ENAME, SAL INTO RS FROM EMP WHERE EMPNO=&ENO;