Using Single Row Functions Questions
Using Single Row Functions Questions
Using Single Row Functions Questions
http://www.tutorialspoint.com/sql_certificate/using_single_row_functions_questions.htm
Copyright © tutorialspoint.com
A. 140
B. 144
C. 150
D. 100
Answer: A. The ROUND function will round off the value 144.23 according to the specified
precision -1 and returns 140.
Examine the structure of the EMPLOYEES table as given and answer the questions 2 and
3 that follow.
2. You are currently located in New Jersey and have connected to a remote database in
San Diego. You issue the following command.
A. An error because the ROUND function cannot be used with Date arguments.
B. An error because the WHERE condition expression is invalid.
C. Number of days since the employee was hired based on the current San Diego date and
time.
D. Number of days since the employee was hired based on the current New Jersey date and
time.
Answer: C. The SYSDATE function will take the current time of the database which it is connecting
to remotely. You must perform basic arithmetic operation to adjust the time zone.
3. You need to display the names of the employees who have the letter 's' in their first
name and the letter 't' at the second position in their last name. Which query would
give the required output?
Answer: A. The INSTR function returns the position of a given character in the required string. The
SUBSTR function returns set of characters from the string from a given starting and end position.
A. COUNT (*) counts duplicate values and NULL values in columns of any data type.
B. COUNT function cannot work with DATE datatypes.
C. COUNT (DISTINCT job_id) returns the number of rows excluding rows containing duplicates
and NULL values in the job_id column.
D. A SELECT statement using the COUNT function with a DISTINCT keyword cannot have a
WHERE clause.
Answer: A. The COUNT(*) function returns the number of rows in a table that satisfy the criteria of
the SELECT statement, including duplicate rows and rows containing null values in any of the
columns. If a WHERE clause is included in the SELECT statement, COUNT(*) returns the number of
rows that satisfy the condition in the WHERE clause. In contrast, COUNT(expr) returns the number
of non-null values that are in the column identified by expr. COUNT(DISTINCT expr) returns the
number of unique, non-null values that are in the column identified by expr.
5. Which of the following commands is used to count the number of rows and non-NULL
values in Oracle database?
A. NOT NULL
B. INSTR
C. SUBSTR
D. COUNT
Answer: D. The COUNT (ALL column_name) is used to count number of rows excluding NULLs.
Similarly, COUNT(*) is used to count the column values including NULLs.
A. 100
B. 999
C. NULL
D. 1099
7. Which of the following statements are true regarding the single row functions?
Answer: A, D. The format model $99G999D99 formats given number into numeric, group
separator, and decimals. Other format elements can be leading zeroes, decimal position, comma
position, local currency, scientific notation, and sign.
A. 78945*****
B. **78945.45
C. The function RPAD cannot be nested with other functions
D. 78945.45****
Answer: A. The LPAD(string, num, char) and RPAD(string, num, char) functions add a character to
the left or right of a given string until it reaches the specified length (num) after padding. The
ROUND function rounds the value 78945.45 to 78945 and then pads it with '*' until length of 10 is
reached.
10. Which of the following commands allows you to substitute a value whenever a NULL
or non-NULL value is encountered in an SQL query?
A. NVL
B. NVLIF
C. NVL2
D. LNNVL
Answer: C. The NVL2 function takes minimum three arguments. The NVL2 function checks the
first expression. If it is not null, the NVL2 function returns the second argument. If the first
argument is null, the third argument is returned.
A. Character
B. Numeric
C. Conversion
D. None of the above
Answer: D. The types of single-row functions like character, numeric, date, conversion and
miscellaneous as well as programmer-written can be incorporated in Oracle DB.
12. Out of the below clauses, where can the single-row functions be used?
A. SELECT
B. WHERE
C. ORDER BY
D. All of the above
Answer: D. Single row function can be used in SELECT statement, WHERE clause and ORDER BY
clause.
A. The syntax of NVL is NVL (exp1, exp2) where exp1 and exp2 are expressions.
B. NVL (exp1, exp2) will return the value of exp2 if the expression exp1 is NULL.
C. NVL (exp1, exp2) will return the value of the expression exp2 if exp1 is NOT NULL.
D. NVL (exp1, exp2) will return exp1 if the expression exp2 is NULL.
Answer: B. NVL function replaces a null value with an alternate value. Columns of data type date,
character, and number can use NVL to provide alternate values. Data types of the column and its
alternative must match.
Answer: C. The NVL function replaces a null value with an alternate value. Columns of data type
date, character, and number can use NVL to provide alternate values. Data types of the column
and its alternative must match.
A. NULL
B. 1
C. 0
D. Gives an error because NULL cannot be explicitly specified to NVL function
Answer: B. The NVL will treat NULL as a value and returns the alternate argument i.e. 1 as the
result.
16. What will be the outcome of the following query? (Consider the structure of the
EMPLOYEES table as given)
SELECT employee_id , NVL(salary, 0) FROM employees WHERE first_name like 'P%' ORDER BY
first_name;
A. It will display 0 in the salary column for all the employees whose first name starts with a 'P'
B. It will display the salaries for the employees whose name start with a 'P' and 0 if the salaries
are NULL.
C. It will throw an ORA error as the ORDER BY clause should also contain the salary column.
D. The NVL function should be correctly used as NVL (0, salary)
Answer: B. NVL function replaces a null value with an alternate value. Columns of data type date,
character, and number can use NVL to provide alternate values. Data types of the column and its
alternative must match.
17. Which of the following statements is true regarding the NVL statement?
A. The two expressions arg1 and arg2 should only be in VARCHAR2 or NUMBER data type
format.
B. The arguments arg1 and arg2 should have the same data type
C. If arg1 is VARCHAR2, then Oracle DB converts arg2 to the datatype of arg1 before
comparing them and returns VARCHAR2 in the character set of arg1.
D. An NVL function cannot be used with arguments of DATE datatype.
Answer: C. If arg1 is of VARCHAR2 data type, Oracle does implicit type conversion for arg2 id
arg2 is of NUMBER datatype. In all other cases, both the arguments must be of same datatype.
18. What will be the outcome of the following query? (Consider the structure of the
EMPLOYEES table as given)
A. It will return the value 'Regular Employee' for all the employees who have NULL job IDs
B. It will return the value 'New Joinee' for all the employees who have NULL job IDs
C. It will return 'Regular Employee' if the job ID is NULL
D. It will throw an ORA error on execution.
Answer: B. The NVL2 function examines the first expression. If the first expression is not null, the
NVL2 function returns the second expression. If the first expression is null, the third expression is
returned.
19. Which of the following is true for the statement given as under.
Answer: D. The data types of the arg2 and arg3 parameters must be compatible, and they cannot
be of type LONG. They must either be of the same type, or it must be possible to convert arg3 to
the type of the arg2 parameter. The data type returned by the NVL2 function is the same as that of
the arg2 parameter.
A. Salary will be returned if the Commission for the employee is NOT NULL.
B. Commission_pct will be returned if the Commission for the employee is NOT NULL.
C. Employees with the first name starting with 'P' and salary+(salary*commission_pct) will be
returned if the employee earns a commission.
D. The query throws an error because a mathematical expression is written inside NVL2.
Answer: C. The NVL2 function examines the first expression. If the first expression is not null, the
NVL2 function returns the second expression. If the first expression is null, the third expression is
returned.
A. NULLIF(expr1,expr2) will return expr2 if the two expressions are NOT NULL.
B. NULLIF(expr1,expr2) will return 0 if the two expressions are NULL.
C. NULLIF(expr1,expr2) will return NULL if the two expressions are equal.
D. Expr1 can be NULL in NULLIF(expr1, expr2)
Answer: C. The NULLIF function tests two terms for equality. If they are equal the function returns
a null, else it returns the first of the two terms tested. The NULLIF function takes two mandatory
parameters of any data type. The syntax is NULLIF(arg1,arg2), where the arguments arg1 and arg2
are compared. If they are identical, then NULL is returned. If they differ, the arg1 is returned.
22. Pick the correct answer given after the statement shown as under.
NULLIF (arg1,arg2)
Answer: D.
You need to create a report from the HR schema displaying employees who have changed jobs
since they were hired. You execute the query given below.
A. It will display the old job ID when the new job ID is NULL.
B. It will execute successfully and produce the required output.
C. It will display the new job ID if the new job ID is equal to the old job ID
D. It will throw an ORA error on execution.
Answer: D.
24. Which of the following is not a property of functions?
Answer: D. Functions can perform calculations, perform case conversions and type conversions.
Answer: B. Single row functions always return one result per row and they operate on single rows
only; hence the name ‘Single Row' is given to them.
A. Multiple-row functions
B. Single column functions
C. Single value functions
D. Multiple columns functions
Answer: A. There are basically two types of functions - Single row and Multiple row functions.
A. VARCHAR2
B. Character
C. LONG
D. NULLIF
Answer: B and D. As Character and NULLIF are single row function and rest are the datatypes.
Answer: B. Multiple Row functions always work on a group of rows and return one value per
group of rows.
Answer: C. Group functions are same as Multi row functions and aggregate functions.
30. Which of the following is true about Single Row Functions?
A. 0
B. Only 1
C. Only 2
D. 1 or more than 1
Answer: D. Single row functions can accept one or more arguments depending upon the
objective they serve.
32. Which of the following can be an argument for a Single Row Function?
A. Data types
B. SELECT statements
C. Expression
D. Table name
Answer: C. A user-supplied constant, variable value, column value and expression are the types
of arguments of a single row function.
Answer: C. The character function INSTR accepts a string value but returns numeric position of a
character in the string.
Answer: D.
35. Which of the following is an exception to the return value of a DATE type single-row
function?
A. TO_DATE
B. SYSDATE
C. MONTHS_BETWEEN
D. TO_NUMBER
Answer: C. All the DATE data type functions return DATE as return values except
MONTHS_BETWEEN which returns a number.
36. Which of the following is not a Conversion type Single Row function?
A. TO_CHAR
B. TO_DATE
C. NVL
D. TO_NUMBER
Answer: C. Conversion functions convert a value from one data type to another. The NVL function
replaces a null value with an alternate value.
A. CONCAT
B. SUBSTR
C. INITCAP
D. REPLACE
Answer: C. The CONCAT, SUBSTR and REPLACE are Character-manipulation Character functions
while INITCAP, LOWER and UPPER are case conversion character functions.
A. Hi World !!!
B. Hi WORLD !!!
C. hi world !!!
D. HI WORLD !!!
A. Hello World
B. HELLO world
C. hello World
D. hello world
Examine the structure of the EMPLOYEES table as given and answer the questions 40 to 42 that
follow.
40.Which of the following queries will give the same result as given in the query given
below?
Answer: A. The CONCAT function joins two strings without any space in between.
Answer: A.
42. Assuming the last names of the employees are in a proper case in the table
employees, what will be the outcome of the following query?
A. It will display the details of the employee with the last name as Smith
B. It will give no result.
C. It will give the details for the employee having the last name as 'Smith' in all Lower case.
D. It will give the details for the employee having the last name as 'Smith' in all INITCAP case.
Answer: B. Provided the last names in the employees table are in a proper case, the condition
WHERE last_name = 'smith' will not be satistified and hence no results will be displayed.
Answer: B. The CONCAT function accepts only two arguments of NUMBER or VARCHAR2
datatypes.
Answer: A. The SUBSTR(string, x, y) function accepts three parameters and returns a string
consisting of the number of characters extracted from the source string, beginning at the specified
start position (x). When position is positive, then the function counts from the beginning of string to
find the first character. When position is negative, then the function counts backward from the end
of string.
A. 2
B. 3
C. 1
D. hi
Answer: A. the LENGTH function simply gives the length of the string.
46. What is the difference between LENGTH and INSTR functions in Oracle DB?
Answer: C.
A. It results in an error as substitution variables cannot be used with single row functions
B. It prompts the user to input the jobid on each execution and then displays the job id in UPPER
case
C. It gives the jobid as it is present in the table EMPLOYEES without making any change
D. It will not ask the user to input the job id and will convert all the job IDs in the table in UPPER
case
Answer: B. Substitution variables can be used with the UPPER and LOWER functions.
Answer: C. The DUAL table has one column named DUMMY and one row which has a value 'X'.
A. 100
B. 100+100
C. ORA error
D. 200
51. What will be the outcome of the following query if the SYSDATE = 20-MAY-13?
A. 20-may-2013
B. ORA error as LOWER and UPPER cannot accept date values.
C. 20-MAY-13
D. 20-May-13
Answer: C. The functions UPPER and LOWER can accept date type inputs and will yield the same
result as they do on Strings.
A. 4
B. 24
C. 24/6
D. No result
You need to display the last name of all employees which starts with the letter 'A'. Which of the
following queries will yield the required result?
Answer: A, B.
54. Assuming the SYSDATE is 20-FEB-13, What will be the outcome of the following
query?
A. Today is : 20-feb-13
B. The query throws error of incompatible type arguments.
C. Today is : 20-Feb-13
D. Today is : 20-FEB-13
A. First_namelast_namejob_id
B. First_name, last_name, job_id
C. Error as CONCAT cannot be nested
D. First_namelast_name, job_id
Answer: A. The CONCAT function can be nested with self or other character function.
You need to generate a report which shows the first name, last name and the salary for all the
employees in the department 100. The report should show the results in the form 'Andy Smith
earns 50000'. Which of the following queries will give the required output?
A. SELECT concat (first_name,concat (' ', concat(last_name, concat(' earns ', SALARY))))
Concat_String FROM employees WHERE department_id =
100;
Answer: A. The CONCAT function can be nested with self or other character function.
A. 25
B. 19
C. 20
D. 0
Answer: A. The LENGTH functions counts blank spaces, tabs and special characters too.
58. You need to display the country name from the COUNTRIES table. The length of the
country name should be greater than 5 characters. Which of the following queries will
give the required output?
Answer: D. The LPAD(string, length after padding, padding string) and RPAD(string, length after
padding, padding string) functions add a padding string of characters to the left or right of a string
until it reaches the specified length after padding.
60. Which of the following options is true regarding LPAD and RPAD functions?
Answer: D.
61. What is the maximum number of input arguments in LPAD and RPAD functions?
A. 1
B. 2
C. 3
D. 0
Answer: C. LPAD and RPAD take maximum of 3 arguments. If there are 2 arguments given, the
padding happens by spaces.
A. *******1300.66
B. 1300*******
C. 1300.66
D. ****1300.66
Answer: A. To make the total length of 14 characters, the return value 1300.66 is padded with 7
asterisks (*) on the left.
Answer: B. The TRIM function literally trims off leading or trailing (or both) character strings from
a given source string. TRIM function when followed by TRAILING or LEADING keywords, can remove
characters from one or both sides of a string.
64. You need to remove the occurrences of the character '.' and the double quotes '"'
from the following titles of a book present in the table MAGAZINE.
Answer: B. The LTRIM and RTRIM functions can be used in combination with each other.
A. 1
B. 2
C. 0
D. 3
Answer: C. INSTR function returns a 0 when the search string is absent in the given string.
A. 2
B. 10
C. 7
D. 4
Answer: B. INSTR function search for the 4th occurrence of '$' starting from the 3rd position.
A. #5
B. #3
C. #7
D. #9
Answer: D. SUBSTR function will search 3 places starting from the end of string and will give 2
characters in the forward direction giving #9.
Examine the structure of the EMPLOYEES table as given below and answer the
questions 68 and 69 that follow.
68. You need to extract a consistent 15 character string based on the SALARY column in
the EMPLOYEES table. If the SALARY value is less than 15 characters long, zeros must
be added to the left of the value to yield a 15 character string. Which query will fulfill
this requirement?
Answer: B. The LPAD and RPAD functions add a padding string of characters to the left or right of
a string until it reaches the specified length after padding.
69. You need to display the last 2 characters from the FIRST_NAME column in the
EMPLOYEES table without using the LENGTH function. Which of the following queries
can fulfill this requirement?
Answer: B. The SUBSTR(string, x, y) function accepts three parameters and returns a string
consisting of the number of characters extracted from the source string, beginning at the specified
start position (x). When position is positive, then the function counts from the beginning of string to
find the first character. When position is negative, then the function counts backward from the end
of string.
70. Assuming the SYSDATE is 13-JUN-13, what will be the outcome of the following
query?
A. 3
B. N-13
C. 0
D. NULL
Answer: D. The query will give a NULL as the position 10 to start with in the SYSDATE doesn't
exist.
71. Which of the following is used to replace a specific character in a given string in
Oracle DB?
A. LTRIM
B. TRIM
C. TRUNC
D. REPLACE
Answer: D.
A. 999
B. 9998
C. 99988
D. 9999.88
Answer: C. The REPLACE function searches for '8' in 9998 and replaces it with '88'.
You need to retrieve the first name, last name (separated by a space) and the formal names of
employees where the combined length of the first name and last name exceeds 15 characters. A
formal name is formed by the first letter of the First Name and the first 14 characters of the last
name. Which of the following queries will fulfill this requirement?
Answer: D.
A. 148.50
B. 140
C. 150
D. 149
Answer: D. if the decimal precision is absent, the default degree of rounding is 0 and the source
is rounded to the nearest whole number.
75. Assuming the sysdate is 10-JUN-13, What will be the outcome of the following
query?
A. 10-JUN-13
B. 1-JUN-13
C. ORA error as the TRUNC function can't have an input parameter when used with dates.
D. 31-JUN-13
Answer: B. The date is truncated to the first day of the month. Similarly, it can be done for year
also.
A. 2000
B. 1000
C. 1901
D. 1901.00
Answer: B.
A. Mod(divisor,dividend)
B. MOD(divisor,1)
C. MOD(dividend,divisor)
D. None of the above
Answer: C. The MOD function is used to get the remainder of a division operation.
A. ORA error
B. 1.23
C. 100
D. 0
Answer: B. The MOD function gives the same answer for a positive divisor as well as a negative
divisor.
79. Which of the following functions are used to differentiate between even or odd
numbers in Oracle DB?
A. ROUND
B. TRUNC
C. MOD
D. REPLACE
Answer: C. The MOD function can be used to check whether a given number is even or odd. If
MOD (num,2) returns zero, the number 'num' is an even. If MOD (num,2) returns 1, the number
'num' is odd.
You need to allocate the first 12 employees to one of the four teams in a round-robin manner. The
employee IDs start with a 100. Which of the following queries will fulfill the requirement?
A. SELECT * FROM employees WHERE employee_id between 100 and 111 ORDER BY
employee_id;
Answer: B.
Answer: B. Calling the SUBSTR function with just the first two parameters results in the function
extracting a string from a start position to the end of the given source string.
82. What is the default data format for the sysdate in SQL Developer?
A. DD-MON-YY
B. DD-MON-RR
C. DD/MON/RR
D. DD/MON/YYYY
Answer: C. For SQL*PLUS the default date format is DD-MON-RR.
83. Assuming the SYSDATE to be 10-JUN-2013 12:05pm, what value is returned after
executing the below query?
A. 09-MAY-2013 12:05pm
B. 10-MAY-2013 12:05pm
C. 10-JUL-2013 12:05pm
D. 09-JUL-2013 12:05pm
Answer: B. The ADD_MONTHS(date, x) function adds 'x' number of calendar months to the given
date. The value of 'x' must be an integer and can be negative.
84. What value will be returned after executing the following statement? Note that 01-
JAN-2013 occurs on a Tuesday.
A. 02-JAN-2013
B. Friday
C. 04-JAN-2013
D. None of the above
Answer: C. The NEXT_DAY(date,'day') finds the date of the next specified day of the week ('day')
following date. The value of char may be a number representing a day or a character string.
85. What is the maximum number of parameters the ROUND function can take?
A. 0
B. 1
C. 2
D. 3
Answer: C. If there is only one parameter present, then the rounding happens to the nearest
whole number
86. Assuming the present date is 02-JUN-2007, what will be the century returned for the
date 24-JUL-2004 in the DD-MON-RR format?
A. 19
B. 21
C. 20
D. NULL
Answer: C. If the two digits of the current year and the specified year lie between 0 and 49, the
current century is returned.
87. Assuming the present date is 02-JUN-2007, what will be the century returned for the
date 24-JUL-94 in the DD-MON-RR format?
A. 19
B. 21
C. 20
D. NULL
Answer: A. If the two digits of the current year lie between 0 and 49 and the specified year falls
between 50 and 99, the previous century is returned.
88. Assuming the present date is 02-JUN-1975, what will be the century returned for the
date 24-JUL-94 in the DD-MON-RR format?
A. 19
B. 21
C. 20
D. NULL
Answer: A. if the two digits of the current and specified years lie between 50 and 99, the current
century is returned by default.
89. Assuming the present date is 02-JUN-1975, what will be the century returned for the
date 24-JUL-07 in the DD-MON-RR format?
A. 19
B. 21
C. 20
D. NULL
Answer: C. if the two digits of the current year lie between 50 and 99 and the specified year falls
between 0 and 49, the next century is returned.
A. 1
B. 2
C. 4
D. 0
Answer: D.
92. What will be the datatype of the result of the following operation?
"Date3 = Date1-Date2"
A. Date
B. Num1
C. 0
D. NULL
93. What will be the datatype of the result of the following operation?
"Date2 = Date1-Num1"
A. Date
B. Num1
C. 0
D. NULL
94. What does a difference between two dates represent in Oracle DB?
Answer: A.
A. ORA error
B. A positive number
C. A negative number
D. 0
Answer: C. If the first parameter is less than the second parameter, the MONTHS_BETWEEN
returns a negative number.
A. It represents the difference in number between the start date and end date.
B. The result cannot be a fractional number, it has to be a whole number.
C. NULL
D. It represents the days and the time remaining after the integer difference between years and
months is calculated and is based on a 31-day month.
Answer: D.
97. You are connected to a remote database in Switzerland from India. You need to find
the Indian local time from the DB. Which of the following will give the required result?
Answer: D.
Answer: D. The MONTHS_BETWEEN(date1, date2) finds the number of months between date1
and date2. The result can be positive or negative. If date1 is later than date2, the result is positive;
if date1 is earlier than date2, the result is negative. The noninteger part of the result represents a
portion of the month.
A. 31-feb-2009
B. 28-feb-2009
C. 31-mar-2009
D. 15-jan-2009
Answer: B. the fractional part of 2.5 will be ignored and 2 months will be added to 31-dec-2012
which is 31-feb-2013 but as it is not a valid date, the result is 28-feb-2009.
100. You need to identify the date in November when the staff will be paid. Bonuses are
paid on the last Friday in November. Which of the following will fulfill the requirement?
Answer: B. The NEXT_DAY(date,'day') and LAST_DAY (date,'day') functions find the date of the
next or last specified day of the week ('day') following date. The value of char may be a number
representing a day or a character string.