This set of PL/SQL Multiple Choice Questions & Answers (MCQs) focuses on “PL/SQL DBMS Output”.
1. DBMS_OUTPUT is a built-in package.
a) True
b) False
View Answer
Explanation: DBMS_OUTPUT is a built-in package. It provides the capability to send messages to a message buffer, or get messages from the message buffer. It is also used to display outputs and debugging information.
2. Which of the following function is not supported by the DBMS_OUTPUT package?
a) Display Output
b) Display Debugging Information
c) Display Exception Information
d) Send Messages
View Answer
Explanation: DBMS_OUTPUT is a predefined package that enables us to display output, debugging information, and send messages from PL/SQL blocks, subprograms, packages and triggers.
3. What will be the output of the following PL/SQL code?
DECLARE a NUMBER (2) := 10; b NUMBER (2) := 10; BEGIN IF (a >= b) THEN dbms_output.put_line(a); END IF; IF (b >= a) THEN dbms_output.put_line(a); END IF; IF (a = b) THEN dbms_output.put_line(‘Equal’); END IF; END;
a) 10
b) Equal
c) Error
d) No Output
View Answer
Explanation: The output of the given PL/SQL code will be – Equal. As the values for a and b fulfils the third IF condition which in turn executes the dbms_output.put_line inside it. Anything that is written inside the put_line function will be printed if the function gets executed.
4. What will be the output of the following PL/SQL code?
DECLARE a NUMBER(2) := 25; BEGIN IF (a < 10 ) THEN dbms_output.put_line('Value of a is less than 10' ); ELSEIF (a < 20) THEN dbms_output.put_line('Value of a is less than 20' ); ELSE dbms_output.put_line('Value of a is greater than 20'); END IF; dbms_output.put_line('Value of a is: '|| a ); END;
a)
VALUE OF a IS less than 10 VALUE OF a IS 25
b)
VALUE OF a IS less than 20 VALUE OF a IS 25
c) Error
d)
VALUE OF a IS greater than 20 VALUE OF a IS 25
Explanation: The output of the given PL/SQL code will be –
VALUE OF a IS greater than 20 VALUE OF a IS 25
As the value for a fulfils the ELSE condition which in turn executes the dbms_output.put_line inside it. The last dbms_output.put_line function will be executed every time the program executes properly. Anything that is written inside the put_line function will be printed if the function gets executed.
5. What will be the output of the following PL/SQL code?
DECLARE a NUMBER(2) := 100; BEGIN IF (a < 50) THEN dbms_output.put_line('Value of a is less than 50' ); ELSEIF (a < 75) THEN dbms_output.put_line('Value of a is less than 75' ); ELSE dbms_output.put_line('Value of a is greater than 75'); END IF; dbms_output.put_line('Value of a is: '|| a ); END;
a)
VALUE OF a IS less than 50 VALUE OF a IS 100
b)
VALUE OF a IS less than 75 VALUE OF a IS 100
c) Error
d)
VALUE OF a IS greater than 75 VALUE OF a IS 100
Explanation: The output of the given PL/SQL code will result in an error because the size for the datatype number for a is 2 but the value assigned to a is 100 which is of size 3. This will result in an error.
6. Which of the following DBMS_OUTPUT procedure is used to put an end-of-line marker?
a) DBMS_OUTPUT.GET_LINES();
b) DBMS_OUTPUT.PUT_LINE(item IN VARCHAR2);
c) DBMS_OUTPUT.PUT(item IN VARCHAR2);
d) DBMS_OUTPUT.NEW_LINE;
View Answer
Explanation: DBMS_OUTPUT.NEW_LINE procedure is used to put an end-of-line marker. Every call to the PUT_LINE Procedure or NEW_LINE Procedure generates a line that is returned by GET_LINE(S). It’s syntax is –
DBMS_OUTPUT.NEW_LINE;
7. Which of the following is the correct syntax for the DBMS_OUTPUT.GET_LINE procedure?
a)
DBMS_OUTPUT.GET_LINE ( lineOUT VARCHAR2, statusOUT INTEGER);
b)
DBMS_OUTPUT.GET_LINE ( line IN VARCHAR2, STATUS IN INTEGER);
c)
DBMS_OUTPUT_GET_LINE ( line OUT VARCHAR2, STATUS OUT INTEGER);
d)
DBMS_OUTPUT.GET_LINE ( lineOUT INTEGER, STATUS OUT VARCHAR2);
Explanation: The correct syntax for the DBMS_OUTPUT.GET_LINE procedure is –
DBMS_OUTPUT.GET_LINE ( line OUT VARCHAR2, STATUS OUT INTEGER);
This procedure retrieves a single line of buffered information. Here, line returns a single line of buffered information, excluding the final newline character. If the call completes successfully, then the status is 0. If there are no more lines in the buffer, then the status is 1.
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]