This set of PL/SQL Multiple Choice Questions & Answers (MCQs) focuses on “PL/SQL Variables”.
1. Which of the following variable name is valid in PL/SQL?
a) _person123
b) person
c) person@123
d) 11person
View Answer
Explanation: The name of a PL/SQL variable should start with a letter, optionally followed by letters, numerals, dollar signs and underscores.
2. Which of the following is an incorrect variable declaration in PL/SQL?
a) var_number varchar2(10);
b) var_text number (10);
c) var_char char (1) := ‘Y’;
d) var_text varchar2(10) := ‘hello world’;
View Answer
Explanation: The incorrect variable declaration is – var_text varchar2(10) := ‘hello world’;
As the “hello world” string exceeds the word limit of 10 characters while declaring the variable.
3. Which of the following is not a valid variable type in PL/SQL?
a) VARCHAR1
b) VARCHAR2
c) CHAR
d) NUMBER
View Answer
Explanation: There is no variable type named VARCHAR1 in PL/SQL. VARCHAR2 is used to store strings. CHAR is used to store single character and NUMBER is used to store numeric values in variables.
4. Which of the following is the DEFAULT value of an uninitialized variable in PL/SQL?
a) 0
b) /0
c) NULL
d) \0
View Answer
Explanation: Whenever we declare a variable, PL/SQL assigns it a default value of NULL. If we want to initialize a variable with a value other than the NULL value then we can do it by using the assignment operator or the DEFAULT keyword during the variable’s declaration.
5. Which of the following variable is declared in the outermost block or package of PL/SQL?
a) Local Variable
b) Global Variable
c) Reference Variable
d) Static Variable
View Answer
Explanation: Global variables are the variables that are declared in the outermost block or a package and can be accessible to the whole package. Local variables are the variables that are declared in an inner block and are not accessible to outer blocks.
6. What will be the output of the following PL/SQL code?
DECLARE a INTEGER := 30; b INTEGER := 40; c INTEGER; d REAL; BEGIN c := a + b; dbms_output.put_line('Value of c: ' || c); d := 70.0/3.0; dbms_output.put_line('Value of d: ' || d); END; /
a)
VALUE OF c: 70 VALUE OF d: 23.333333333333333333
b)
VALUE OF c: 70 VALUE OF d: 23.333333333333333333 PL/SQL PROCEDURE successfully completed.
c)
VALUE OF c: 70 VALUE OF d: 23 PL/SQL PROCEDURE successfully completed.
d)
VALUE OF c: 70.000000000000000000 VALUE OF d: 23.333333333333333333 PL/SQL PROCEDURE successfully completed.
Explanation: The correct output of the given code would be –
VALUE OF c: 70 VALUE OF d: 23.333333333333333333 PL/SQL PROCEDURE successfully completed.
After every successful PL/SQL code execution, “PL/SQL procedure successfully completed” is printed. Since, d has real as it’s datatype so it will return the output in decimal form.
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]