This set of PL/SQL Multiple Choice Questions & Answers (MCQs) focuses on “PL/SQL Records”.
1. A record is a data-structure that can contain data items of same type.
a) True
b) False
View Answer
Explanation: In PL/SQL, a record is a data structure that can contain data items of different types. Records consists of a combination of different fields, same as a table which is a collection of different rows.
2. How many types of records are supported by PL/SQL?
a) 2
b) 3
c) 4
d) 5
View Answer
Explanation: PL/SQL supports 3 different kinds of records. They are – Table-based records, Cursor-based records and User-defined records.
3. Which of the following attribute enables us to create the table-based and cursor-based records?
a) %ROWTYPE
b) %COLUMNTYPE
c) %RECORDTYPE
d) %TABLETYPE
View Answer
Explanation: The %ROWTYPE attribute is used to create the table-based and cursor-based records. The syntax for table-based record is – record_name table_name%ROWTYPE. The syntax for cursor-based record is –
record_name cursor_name%ROWTYPE
In the later, a cursor should already be created on the needed table before making a record.
4. Which of the following is the correct syntax for defining a record type in a programmer-defined record?
a)
TYPE RECORD IS record_type ( field_name1 data_type1 [[NOT NULL] := | DEFAULT default_value], field_name2 data_type2 [[NOT NULL] := | DEFAULT default_value], ... );
b)
TYPE record_type IS RECORD ( data_type1 field_name1 [[NOT NULL] := | DEFAULT default_value], data_type2 field_name2 [[NOT NULL] := | DEFAULT default_value], ... );
c)
TYPE record_type IS RECORD ( field_name1 data_type1 [[NOT NULL] := | DEFAULT default_value], field_name2 data_type2 [[NOT NULL] := | DEFAULT default_value], ... );
d)
TYPE record_type RECORD ( field_name1 data_type1 [[NOT NULL] := | DEFAULT default_value], field_name2 data_type2 [[NOT NULL] := | DEFAULT default_value], ... );
Explanation: The correct syntax for defining a record type in programmer-defined record is –
TYPE record_type IS RECORD ( field_name1 data_type1 [[NOT NULL] := | DEFAULT default_value], field_name2 data_type2 [[NOT NULL] := | DEFAULT default_value], ... );
The fields inside the square brackets [] is not compulsory to write and depends upon the programmer’s need.
5. Which of the following is the correct syntax to declare a record based upon a pre-defined record-type?
a) record_name record_type;
b) record_type record_name;
c) record_name IS record_type;
d) record_type IS record_name;
View Answer
Explanation: The correct syntax to declare a record based upon a pre-defined record-type is –
record_name record_type;
Here, record_name is the name of the record that the user wants to give.
record_type is the name of the pre-defined record type.
6. Which of the following symbol can be used to refer a record’s field in PL/SQL?
a) :
b) ->
c) .
d) =
View Answer
Explanation: The dot (.) symbol can be used to refer a record’s field in PL/SQL. Its syntax is –
record_name.field_name
The field name should be of the field contained inside the record.
7. You cannot compare two records of the same type via comparison operator.
a) True
b) False
View Answer
Explanation: It is true. You cannot compare two records of the same type via comparison operator (=). We need to first compare the individual fields of the records instead to check whether the records are similar or not.
8. Which of the following symbol is used to assign a record to another record?
a) =
b) =>
c) ==
d) :=
View Answer
Explanation: The := symbol is used to assign a record to another record. For example –
record_name1 := record_name2
This will transfer all the data in record 2 to record 1. This symbol can also be used to assign a value to an individual field in a record.
9. To update a row from a %ROWTYPE record, which of the following keyword can be used?
a) INSERT ROW
b) UPDATE ROW
c) SET ROW
d) CREATE ROW
View Answer
Explanation: The SET ROW keyword is used to update a row from a %ROWTYPE record. Its syntax is –
UPDATE cursor_name SET ROW = record_name WHERE condition;
10. We can use a nested record in PL/SQL.
a) True
b) False
View Answer
Explanation: A nested record is a record that contains a field which is another record. Nesting records is a powerful way to structure your program data and hide complexity in your code.
Sanfoundry Global Education & Learning Series – PL/SQL.
To practice all areas of PL/SQL, here is complete set of 1000+ Multiple Choice Questions and Answers.
If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]