# Using Single-Row Functions Questions

1. What will be the outcome of the following query?

`SELECT ROUND(144.23,-1) FROM dual;`
1. 140
2. 144
3. 150
4. 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.

```SQL> DESC employees
Name			 Null?	  Type
----------------------- -------- ----------------
EMPLOYEE_ID		 NOT NULL NUMBER(6)
FIRST_NAME			  VARCHAR2(20)
LAST_NAME		 NOT NULL VARCHAR2(25)
EMAIL			 NOT NULL VARCHAR2(25)
PHONE_NUMBER			  VARCHAR2(20)
HIRE_DATE		 NOT NULL DATE
JOB_ID 		 NOT NULL VARCHAR2(10)
SALARY 			  NUMBER(8,2)
COMMISSION_PCT 		  NUMBER(2,2)
MANAGER_ID			  NUMBER(6)
DEPARTMENT_ID			  NUMBER(4)```

2. You are currently located in New Jersey and have connected to a remote database in San Diego. You issue the following command.

`SELECT ROUND (sysdate-hire_date,0) FROM employees WHERE (sysdate-hire_date)/180 = 2;`

What is the outcome of this query?

1. An error because the ROUND function cannot be used with Date arguments.
2. An error because the WHERE condition expression is invalid.
3. Number of days since the employee was hired based on the current San Diego date and time.
4. 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?

1. `SELECT first_name, last_name FROM employees WHERE INSTR(first_name,'s') <> 0 AND SUBSTR(last_name,2,1) = 't';`
2. `SELECT first_name, last_name FROM employees WHERE INSTR(first_name,'s') <> '' AND SUBSTR(last_name,2,1) = 't';`
3. `SELECT first_name, last_name FROM employees WHERE INSTR(first_name,'e') IS NOT NULL AND SUBSTR(last_name,2,1) = 't';`
4. ```SELECT first_name, last_name FROM employees WHERE INSTR(first_name,'e') <> 0 AND SUBSTR(last_name,LENGTH(first_name),1) =
't';```

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.

4. Which of the following statements is true regarding the COUNT function?

1. COUNT (*) counts duplicate values and NULL values in columns of any data type.
2. COUNT function cannot work with DATE datatypes.
3. COUNT (DISTINCT job_id) returns the number of rows excluding rows containing duplicates and NULL values in the job_id column.
4. 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?

1. NOT NULL
2. INSTR
3. SUBSTR
4. 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.

6. What will be the outcome of the query given below?

`SELECT 100+NULL+999 FROM dual;`
1. 100
2. 999
3. NULL
4. 1099

Answer: C. Any arithmetic operation with NULL results in a NULL.

7. Which of the following statements are true regarding the single row functions?

1. They accept only a single argument.
2. They can be nested only to two levels.
3. Arguments can only be column values or constants.
4. They can return a data type value different from the one that is referenced.

Answer: D. Single row functions can take more than one argument and the return type can be different from the data type of the inputs.

8. Which of the below queries will format a value 1680 as \$16,80.00?

1. `SELECT TO_CHAR(1680.00,'\$99G99D99') FROM dual;`
2. `SELECT TO_CHAR(1680.00,'\$9,999V99') FROM dual;`
3. `SELECT TO_CHAR(1680.00,'\$9,999D99') FROM dual;`
4. `SELECT TO_CHAR(1680.00,'\$99G999D99') FROM dual;`

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.

9. Determine the output of the below query.

`SELECT RPAD(ROUND('78945.45'),10,'*') FROM dual;`
1. 78945*****
2. **78945.45
3. The function RPAD cannot be nested with other functions
4. 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?

1. NVL
2. NVLIF
3. NVL2
4. 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.

11. Which of the following type of single-row functions cannot be incorporated in Oracle DB?

1. Character
2. Numeric
3. Conversion
4. 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?

1. SELECT
2. WHERE
3. ORDER BY
4. All of the above

Answer: D. Single row function can be used in SELECT statement, WHERE clause and ORDER BY clause.

13. What is true regarding the NVL function in Oracle DB?

1. The syntax of NVL is NVL (exp1, exp2) where exp1 and exp2 are expressions.
2. NVL (exp1, exp2) will return the value of exp2 if the expression exp1 is NULL.
3. NVL (exp1, exp2) will return the value of the expression exp2 if exp1 is NOT NULL.
4. 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.

14. Examine the structure of the EMPLOYEES table as given.

```SQL> DESC employees
Name			 Null?	  Type
----------------------- -------- ----------------
EMPLOYEE_ID		 NOT NULL NUMBER(6)
FIRST_NAME			  VARCHAR2(20)
LAST_NAME		 NOT NULL VARCHAR2(25)
EMAIL			 NOT NULL VARCHAR2(25)
PHONE_NUMBER			  VARCHAR2(20)
HIRE_DATE		 NOT NULL DATE
JOB_ID 		 NOT NULL VARCHAR2(10)
SALARY 			  NUMBER(8,2)
COMMISSION_PCT 		  NUMBER(2,2)
MANAGER_ID			  NUMBER(6)
DEPARTMENT_ID			  NUMBER(4)```
What will be the outcome of the following query?
```SELECT last_name, NVL(job_id, 'Unknown')
FROM employees
WHERE last_name LIKE 'A%'
ORDER BY last_name;```
1. It will throw an ORA error on execution.
2. It will list the job IDs for all employees from EMPLOYEES table.
3. It will list the job IDs of all employees and substitute NULL job IDs with a literal 'Unknown'.
4. It will display the last names for all the employees and their job IDs including the NULL values in the job ID.

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.

15. What will the outcome of the following query?

`SELECT NVL (NULL,'1') FROM dual;`
1. NULL
2. 1
3. 0
4. 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)

```SQL> DESC employees
Name			 Null?	  Type
----------------------- -------- ----------------
EMPLOYEE_ID		 NOT NULL NUMBER(6)
FIRST_NAME			  VARCHAR2(20)
LAST_NAME		 NOT NULL VARCHAR2(25)
EMAIL			 NOT NULL VARCHAR2(25)
PHONE_NUMBER			  VARCHAR2(20)
HIRE_DATE		 NOT NULL DATE
JOB_ID 		 NOT NULL VARCHAR2(10)
SALARY 			  NUMBER(8,2)
COMMISSION_PCT 		  NUMBER(2,2)
MANAGER_ID			  NUMBER(6)
DEPARTMENT_ID			  NUMBER(4)```
`SELECT employee_id , NVL(salary, 0) FROM employees WHERE first_name like 'P%' ORDER BY first_name;`
1. It will display 0 in the salary column for all the employees whose first name starts with a 'P'
2. It will display the salaries for the employees whose name start with a 'P' and 0 if the salaries are NULL.
3. It will throw an ORA error as the ORDER BY clause should also contain the salary column.
4. 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?

`SELECT NVL (arg1, arg2) FROM dual;`
1. The two expressions arg1 and arg2 should only be in VARCHAR2 or NUMBER data type format.
2. The arguments arg1 and arg2 should have the same data type
3. 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.
4. 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)

```SQL> DESC employees
Name			 Null?	  Type
----------------------- -------- ----------------
EMPLOYEE_ID		 NOT NULL NUMBER(6)
FIRST_NAME			  VARCHAR2(20)
LAST_NAME		 NOT NULL VARCHAR2(25)
EMAIL			 NOT NULL VARCHAR2(25)
PHONE_NUMBER			  VARCHAR2(20)
HIRE_DATE		 NOT NULL DATE
JOB_ID 		 NOT NULL VARCHAR2(10)
SALARY 			  NUMBER(8,2)
COMMISSION_PCT 		  NUMBER(2,2)
MANAGER_ID			  NUMBER(6)
DEPARTMENT_ID			  NUMBER(4)```
`SELECT NVL2(job_id,'Regular Employee','New Joinee') FROM employees;`
1. It will return the value 'Regular Employee' for all the employees who have NULL job IDs
2. It will return the value 'New Joinee' for all the employees who have NULL job IDs
3. It will return 'Regular Employee' if the job ID is NULL
4. 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.

`NVL2 (arg1, arg2, arg3)`
1. Arg2 and Arg3 can have any data type
2. Arg1 cannot have the LONG data type
3. Oracle will convert the data type of expr2 according to Arg1
4. If Arg2 is a NUMBER, then Oracle determines the numeric precedence, implicitly converts the other argument to that datatype, and returns that datatype.

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.

20. Examine the structure of the EMPLOYEES table as given.

```SQL> DESC employees
Name			 Null?	  Type
----------------------- -------- ----------------
EMPLOYEE_ID		 NOT NULL NUMBER(6)
FIRST_NAME			  VARCHAR2(20)
LAST_NAME		 NOT NULL VARCHAR2(25)
EMAIL			 NOT NULL VARCHAR2(25)
PHONE_NUMBER			  VARCHAR2(20)
HIRE_DATE		 NOT NULL DATE
JOB_ID 		 NOT NULL VARCHAR2(10)
SALARY 			  NUMBER(8,2)
COMMISSION_PCT 		  NUMBER(2,2)
MANAGER_ID			  NUMBER(6)
DEPARTMENT_ID			  NUMBER(4)```
What will be the outcome of the query mentioned below?
```SeLECT first_name, salary, NVL2(commission_pct,  salary + (salary * commission_pct), salary) "Income"
FROM employees
WHERE first_name like 'P%'
ORDER BY first_name;```
1. Salary will be returned if the Commission for the employee is NOT NULL.
2. Commission_pct will be returned if the Commission for the employee is NOT NULL.
3. Employees with the first name starting with 'P' and salary+(salary*commission_pct) will be returned if the employee earns a commission.
4. 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.

21. What is true about the NULLIF function in Oracle DB?

1. NULLIF(expr1,expr2) will return expr2 if the two expressions are NOT NULL.
2. NULLIF(expr1,expr2) will return 0 if the two expressions are NULL.
3. NULLIF(expr1,expr2) will return NULL if the two expressions are equal.
4. 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) `
1. Arg1 and Arg2 can be of different data types.
2. Arg1 and Arg2 have to be equal in order to be used in the NULLIF function.
3. There is no internal conversion of data types if NULLIF used as in the case of NVL and NVL2.
4. This is equivalent to CASE WHEN Arg1 = Arg22 THEN NULL ELSE Arg1 END.

23. Examine the structure of the EMPLOYEES table as given.

```SQL> DESC employees
Name			 Null?	  Type
----------------------- -------- ----------------
EMPLOYEE_ID		 NOT NULL NUMBER(6)
FIRST_NAME			  VARCHAR2(20)
LAST_NAME		 NOT NULL VARCHAR2(25)
EMAIL			 NOT NULL VARCHAR2(25)
PHONE_NUMBER			  VARCHAR2(20)
HIRE_DATE		 NOT NULL DATE
JOB_ID 		 NOT NULL VARCHAR2(10)
SALARY 			  NUMBER(8,2)
COMMISSION_PCT 		  NUMBER(2,2)
MANAGER_ID			  NUMBER(6)
DEPARTMENT_ID			  NUMBER(4)```

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.

```SELECT e.last_name, NULLIF(e.job_id, j.job_id,"Old Job ID")
FROM employees e, job_history j
WHERE e.employee_id = j.employee_id
ORDER BY last_name;```

What will be the outcome of the query given above?

1. It will display the old job ID when the new job ID is NULL.
2. It will execute successfully and produce the required output.
3. It will display the new job ID if the new job ID is equal to the old job ID
4. It will throw an ORA error on execution.

24. Which of the following is not a property of functions?

1. Perform calculations on data
2. Convert column data types
3. Modify individual data items
4. None of the above

Answer: D. Functions can perform calculations, perform case conversions and type conversions.

25. What is the most appropriate about single row functions?

1. They return no value
2. They return one result per row and operate on all the rows of a table.
3. They return one result per row with input arguments
4. They return one result per set of rows and operate on multiple rows.

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.

26. What among the following is a type of Oracle SQL functions?

1. Multiple-row functions
2. Single column functions
3. Single value functions
4. Multiple columns functions

Answer: A. There are basically two types of functions - Single row and Multiple row functions.

27. What among the following is a type of single-row function?

1. VARCHAR2
2. Character
3. LONG
4. NULLIF

Answer: B and D. As Character and NULLIF are single row function and rest are the datatypes.

28. What is the most appropriate about Multiple Row Functions?

1. They return multiple values per each row.
2. They return one result per group of rows and can manipulate groups of rows.
3. They return one result per row and can manipulate groups of rows.
4. They return multiple values per a group of row.

Answer: B. Multiple Row functions always work on a group of rows and return one value per group of rows.

29. Which of the following are also called Group functions?

1. Single row functions
2. Multi group functions
3. Multiple row functions
4. Single group functions.

Answer: C. Group functions are same as Multi row functions and aggregate functions.

30. Which of the following is true about Single Row Functions?

1. They can be nested
2. They accept arguments and return more than one value.
3. They cannot modify a data type
4. They cannot accept expressions as arguments.

Answer: A. Single row functions can be nested up to multiple levels.

31. What is the number of arguments Single Row functions accept?

1. 0
2. Only 1
3. Only 2
4. 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?

1. Data types
2. SELECT statements
3. Expression
4. Table name

Answer: C. A user-supplied constant, variable value, column value and expression are the types of arguments of a single row function.

33. What is true about Character functions?

1. They return only character values
2. They accept NUMBER values
3. They accept character arguments and can return both character and number values
4. They accept values of all data type

Answer: C. The character function INSTR accepts a string value but returns numeric position of a character in the string.

34. What is true about Number functions?

1. They return both Character as well as Number values
2. They can't accept expressions as input
3. Number functions can't be nested.
4. They accept Number arguments and return Number values only.

35. Which of the following is an exception to the return value of a DATE type single-row function?

1. TO_DATE
2. SYSDATE
3. MONTHS_BETWEEN
4. 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?

1. TO_CHAR
2. TO_DATE
3. NVL
4. 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.

37. Which of the following is a Case-Conversion Character function?

1. CONCAT
2. SUBSTR
3. INITCAP
4. REPLACE

Answer: C. The CONCAT, SUBSTR and REPLACE are Character-manipulation Character functions while INITCAP, LOWER and UPPER are case conversion character functions.

38. What will be the outcome of the following query?

`SELECT lower('HI WORLD !!!')  FROM dual;`
1. Hi World !!!
2. Hi WORLD !!!
3. hi world !!!
4. HI WORLD !!!

Answer: C. The LOWER function converts a string to lower case characters.

39. What will be the outcome of the following query?

`SELECT lower(upper(initcap('Hello World') )) FROM dual;`
1. Hello World
2. HELLO world
3. hello World
4. hello world

Answer: D. Case conversion characters can be nested in the SELECT queries.

Examine the structure of the EMPLOYEES table as given and answer the questions 40 to 42 that follow.

```SQL> DESC employees
Name			 Null?	  Type
----------------------- -------- ----------------
EMPLOYEE_ID		 NOT NULL NUMBER(6)
FIRST_NAME			  VARCHAR2(20)
LAST_NAME		 NOT NULL VARCHAR2(25)
EMAIL			 NOT NULL VARCHAR2(25)
PHONE_NUMBER			  VARCHAR2(20)
HIRE_DATE		 NOT NULL DATE
JOB_ID 		 NOT NULL VARCHAR2(10)
SALARY 			  NUMBER(8,2)
COMMISSION_PCT 		  NUMBER(2,2)
MANAGER_ID			  NUMBER(6)
DEPARTMENT_ID			  NUMBER(4)```

40.Which of the following queries will give the same result as given in the query given below?

`SELECT CONCAT(first_name, last_name) FROM employees;`
1. SELECT first_name||last_name FROM employees;
2. SELECT first_name||' ' || last_name FROM employees;
3. SELECT last_name||', '||first_name FROM employees;
4. SELECT first_name||','||last_name FROM employees;

Answer: A. The CONCAT function joins two strings without any space in between.

41. What will be the outcome of the following query?

`SELECT 'The job id for '||upper(last_name) ||' is a '||lower(job_id) FROM employees;`
1. The job id for ABEL is a sa_rep
2. The job id forABEL is a sa_rep
3. The job id for abel is SA_REP
4. The job id for abel is sa_rep

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?

`SELECT employee_id, last_name, department_id  FROM employees WHERE last_name = 'smith';`
1. It will display the details of the employee with the last name as Smith
2. It will give no result.
3. It will give the details for the employee having the last name as 'Smith' in all Lower case.
4. 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.

43. What is true about the CONCAT function in Oracle DB?

1. It can have only characters as input.
2. It can have only 2 input parameters.
3. It can have 2 or more input parameters
4. It joins values by putting a white space in between the concatenated strings by default.

Answer: B. The CONCAT function accepts only two arguments of NUMBER or VARCHAR2 datatypes.

44. What is true about the SUBSTR function in Oracle DB?

1. It extracts a string of determined length
2. It shows the length of a string as a numeric value
3. It finds the numeric position of a named character
4. It trims characters from one (or both) sides from a character string

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.

45. What will be the outcome of the following query?

`SELECT length('hi') FROM dual;`
1. 2
2. 3
3. 1
4. 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?

1. They give the same results when operated on a string.
2. LENGTH gives the position of a particular character in a string
3. INSTR gives the position of a particular character in a string while LENGTH gives the length of the string.
4. LENGTH and INSTR can be used interchangeably.

47. Examine the structure of the EMPLOYEES table as given.

```SQL> DESC employees
Name			 Null?	  Type
----------------------- -------- ----------------
EMPLOYEE_ID		 NOT NULL NUMBER(6)
FIRST_NAME			  VARCHAR2(20)
LAST_NAME		 NOT NULL VARCHAR2(25)
EMAIL			 NOT NULL VARCHAR2(25)
PHONE_NUMBER			  VARCHAR2(20)
HIRE_DATE		 NOT NULL DATE
JOB_ID 		 NOT NULL VARCHAR2(10)
SALARY 			  NUMBER(8,2)
COMMISSION_PCT 		  NUMBER(2,2)
MANAGER_ID			  NUMBER(6)
DEPARTMENT_ID			  NUMBER(4)```
What will be the outcome of the following query?
`SELECT upper(&jobid) FROM employees;`
1. It results in an error as substitution variables cannot be used with single row functions
2. It prompts the user to input the jobid on each execution and then displays the job id in UPPER case
3. It gives the jobid as it is present in the table EMPLOYEES without making any change
4. 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.

48. What is false about the table DUAL in Oracle database?

1. It is owned by the user SYS and can be access by all the users.
2. It contains only one column and one row.
3. The value in the DUMMY column of the DUAL table is 'X'
4. The DUAL table is useful when you want to return a value only once

Answer: C. The DUAL table has one column named DUMMY and one row which has a value 'X'.

49. What will be the result of the following query?

`SELECT sysdate+4/12 FROM dual;`
1. The query produces error.
2. No of hours to a date with date as the result.
3. Sysdate arithmetic is ignored.
4. Returns the system date as result.

Answer: B. Arithmetic operations can be performed on dates in the Oracle DB.

50. What will be the outcome of the following query?

`SELECT lower (100+100) FROM dual;`
1. 100
2. 100+100
3. ORA error
4. 200

Answer: D. Arithmetic expressions can be specified within case conversion functions.

51. What will be the outcome of the following query if the SYSDATE = 20-MAY-13?

`SELECT upper (lower (sysdate)) FROM dual;`
1. 20-may-2013
2. ORA error as LOWER and UPPER cannot accept date values.
3. 20-MAY-13
4. 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.

52. What is the result of the following query?

`SELECT INITCAP (24/6) FROM dual;`
1. 4
2. 24
3. 24/6
4. No result

Answer: A. Arithmetic expressions can be specified within case conversion functions.

53. Examine the structure of the EMPLOYEES table as given here.

```SQL> DESC employees
Name			 Null?	  Type
----------------------- -------- ----------------
EMPLOYEE_ID		 NOT NULL NUMBER(6)
FIRST_NAME			  VARCHAR2(20)
LAST_NAME		 NOT NULL VARCHAR2(25)
EMAIL			 NOT NULL VARCHAR2(25)
PHONE_NUMBER			  VARCHAR2(20)
HIRE_DATE		 NOT NULL DATE
JOB_ID 		 NOT NULL VARCHAR2(10)
SALARY 			  NUMBER(8,2)
COMMISSION_PCT 		  NUMBER(2,2)
MANAGER_ID			  NUMBER(6)
DEPARTMENT_ID			  NUMBER(4)```

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?

1. `SELECT INITCAP (last_name||' works as a '||job_id "Job Description" FROM employees WHERE initcap (last_name) like 'A%';`
2. ```SELECT INITCAP (last_name) ||INITCAP(' works as a: ')|| INITCAP(job_id) "Job Description" FROM employees WHERE initcap (last_name) like 'A
%';```
3. `SELECT INITCAP (last_name||' works as a '||INITCAP(job_id)) "Job Description" FROM employees WHERE initcap (last_name) = 'A';`
4. `SELECT UPPER (LOWER (last_name||' works as a '||job_id)) "Job Description" FROM employees WHERE lower (last_name) = 'A';`

54. Assuming the SYSDATE is 20-FEB-13, What will be the outcome of the following query?

`SELECT CONCAT ('Today is :', SYSDATE) FROM dual;`
1. Today is : 20-feb-13
2. The query throws error of incompatible type arguments.
3. Today is : 20-Feb-13
4. Today is : 20-FEB-13

Answer: D. The CONCAT function accepts arguments of all types.

55. What will be the result pattern of the following query?

`SELECT CONCAT(first_name, CONCAT (last_name, job_id)) FROM dual;`
1. First_namelast_namejob_id
2. First_name, last_name, job_id
3. Error as CONCAT cannot be nested
4. First_namelast_name, job_id

Answer: A. The CONCAT function can be nested with self or other character function.

56. Examine the structure of the EMPLOYEES table as given here.

```SQL> DESC employees
Name			 Null?	  Type
----------------------- -------- ----------------
EMPLOYEE_ID		 NOT NULL NUMBER(6)
FIRST_NAME			  VARCHAR2(20)
LAST_NAME		 NOT NULL VARCHAR2(25)
EMAIL			 NOT NULL VARCHAR2(25)
PHONE_NUMBER			  VARCHAR2(20)
HIRE_DATE		 NOT NULL DATE
JOB_ID 		 NOT NULL VARCHAR2(10)
SALARY 			  NUMBER(8,2)
COMMISSION_PCT 		  NUMBER(2,2)
MANAGER_ID			  NUMBER(6)
DEPARTMENT_ID			  NUMBER(4)```

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?

1. ```SELECT concat (first_name,concat (' ', concat(last_name, concat(' earns ', SALARY)))) Concat_String FROM employees WHERE department_id =
100;```
2. `SELECT concat (first_name, last_name||' '|| salary) FROM employees WHERE department_id = 100;`
3. `SELECT concat (first_name, concat(last_name, ' '))||earns||salary FROM employees WHERE department_id = 100;`
4. `SELECT concat (first_name, concat(last_name, 'earns salary') FROM employees WHERE department_id = 100;`

Answer: A. The CONCAT function can be nested with self or other character function.

57. What will the following query show as a result?

`SELECT LENGTH('It is a lovely day today!') FROM dual;`
1. 25
2. 19
3. 20
4. 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?

1. `SELECT country_name FROM countries WHERE LENGTH (country_name)= 5;`
2. `SELECT country_name FROM countries WHERE length (country_name)> 5;`
3. `SELECT SUBSTR(country_name, 1,5) FROM countries WHERE length (country_name)< 5;`
4. `SELECT country_name FROM countries WHERE length (country_name) <> 5;`

Answer: B. The LENGTH function can be used in WHERE clause.

59. How does the function LPAD works on strings?

1. It aligns the string to the left hand side of a column
2. It returns a string padded with a specified number of characters to the right of the source string
3. It aligns character strings to the left and number strings to right of a column
4. It returns a string padded with a specified number of characters to the left of the source string

60. Which of the following options is true regarding LPAD and RPAD functions?

1. The character strings used for padding include only characters.
2. The character strings used for padding include only literals
3. The character strings used for padding cannot include expressions.
4. The character strings used for padding include literals, characters and expressions.

61. What is the maximum number of input arguments in LPAD and RPAD functions?

1. 1
2. 2
3. 3
4. 0

62. What will be the outcome of the following query?

`SELECT lpad (1000 +300.66, 14, '*') FROM dual;`
1. *******1300.66
2. 1300*******
3. 1300.66
4. ****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.

63. What is true regarding the TRIM function?

1. It is similar to SUBSTR function in Oracle
2. It removes characters from the beginning or end of character literals, columns or expression
3. TRIM function cannot be applied on expressions and NUMBERS
4. TRIM function can remove characters only from both the sides of a string.

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.

`"HUNTING THOREAU IN NEW HAMPSHIRE" THE ETHNIC NEIGHBORHOOD."`

Which of the following queries will give the required result?

1. `SELECT LTRIM(Title,'"') FROM MAGAZINE;`
2. `SELECT LTRIM(RTRIM(Title,'."'),'"') FROM MAGAZINE;`
3. `SELECT LTRIM (Title,'"THE') FROM MAGAZINE;`
4. `SELECT LTRIM(RTRIM(Title,'."THE'),'"') FROM MAGAZINE;`

Answer: B. The LTRIM and RTRIM functions can be used in combination with each other.

65. What will be returned as a result of the following query?

`SELECT INSTR('James','x') FROM dual;`
1. 1
2. 2
3. 0
4. 3

Answer: C. INSTR function returns a 0 when the search string is absent in the given string.

66. What will be the outcome of the following query?

`SELECT INSTR('1\$3\$5\$7\$9\$','\$',3,4)FROM dual;`
1. 2
2. 10
3. 7
4. 4

Answer: B. INSTR function search for the 4th occurrence of '\$' starting from the 3rd position.

67. What will be the result of the following query?

`SELECT INSTR('1#3#5#7#9#', -3,2) FROM dual;`
1. #5
2. #3
3. #7
4. #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.

```SQL> DESC employees
Name			 Null?	  Type
----------------------- -------- ----------------
EMPLOYEE_ID		 NOT NULL NUMBER(6)
FIRST_NAME			  VARCHAR2(20)
LAST_NAME		 NOT NULL VARCHAR2(25)
EMAIL			 NOT NULL VARCHAR2(25)
PHONE_NUMBER			  VARCHAR2(20)
HIRE_DATE		 NOT NULL DATE
JOB_ID 		 NOT NULL VARCHAR2(10)
SALARY 			  NUMBER(8,2)
COMMISSION_PCT 		  NUMBER(2,2)
MANAGER_ID			  NUMBER(6)
DEPARTMENT_ID			  NUMBER(4)```

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?

1. `SELECT rpad(salary, 15,0) FROM employees;`
2. `SELECT lpad(salary,15,0) FROM employees;`
3. `SELECT ltrim(salary,15,0) FROM employees;`
4. `SELECT trim(salary,15,0) FROM employees;`

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?

1. `SELECT SUBSTR(first_name, 2) FROM employees;`
2. `SELECT SUBSTR(first_name, -2) FROM employees;`
3. `SELECT RTRIM(first_name, 2) FROM employees;`
4. `SELECT TRIM(first_name, 2) FROM employees;`

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?

`SELECT SUBSTR(sysdate,10,7) FROM dual;`
1. 3
2. N-13
3. 0
4. 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?

1. LTRIM
2. TRIM
3. TRUNC
4. REPLACE

72. What will be the outcome of the following query?

`SELECT replace(9999.00-1,'8',88) FROM dual;`
1. 999
2. 9998
3. 99988
4. 9999.88

Answer: C. The REPLACE function searches for '8' in 9998 and replaces it with '88'.

73. Examine the structure of the EMPLOYEES table as given here.

```SQL> DESC employees
Name			 Null?	  Type
----------------------- -------- ----------------
EMPLOYEE_ID		 NOT NULL NUMBER(6)
FIRST_NAME			  VARCHAR2(20)
LAST_NAME		 NOT NULL VARCHAR2(25)
EMAIL			 NOT NULL VARCHAR2(25)
PHONE_NUMBER			  VARCHAR2(20)
HIRE_DATE		 NOT NULL DATE
JOB_ID 		 NOT NULL VARCHAR2(10)
SALARY 			  NUMBER(8,2)
COMMISSION_PCT 		  NUMBER(2,2)
MANAGER_ID			  NUMBER(6)
DEPARTMENT_ID			  NUMBER(4)```

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?

1. `SELECT first_name, last_name ,SUBSTR(first_name, 1,1)||' '||SUBSTR(last_name, 1,14) formal_name FROM employees;`
2. ```SELECT first_name, last_name ,SUBSTR(first_name, 1,14)||' '||SUBSTR(last_name, 1,1) formal_name FROM employees WHERE length
(first_name) + length(last_name) < 15;```
3. ```SELECT first_name, last_name ,SUBSTR(first_name, 1,1)||' '||SUBSTR(last_name, 1,14) formal_name FROM employees WHERE length
(first_name) + length(last_name) =15;```
4. ```SELECT first_name, last_name ,SUBSTR(first_name, 1,1)||' '||SUBSTR(last_name, 1,14) formal_name FROM employees WHERE length
(first_name) + length(last_name) > 15;```

74. What will be the outcome of the following query?

`SELECT round(148.50) FROM dual;`
1. 148.50
2. 140
3. 150
4. 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?

`SELECT trunc (sysdate,'mon') FROM dual;`
1. 10-JUN-13
2. 1-JUN-13
3. ORA error as the TRUNC function can't have an input parameter when used with dates.
4. 31-JUN-13

Answer: B. The date is truncated to the first day of the month. Similarly, it can be done for year also.

76. What will be the result of the following query?

`SELECT trunc(1902.92,-3) FROM dual;`
1. 2000
2. 1000
3. 1901
4. 1901.00

77. What is the syntax of the MOD function in Oracle DB?

1. Mod(divisor,dividend)
2. MOD(divisor,1)
3. MOD(dividend,divisor)
4. None of the above

Answer: C. The MOD function is used to get the remainder of a division operation.

78. What will be outcome of the following query?

`SELECT mod(100.23,-3) FROM dual;`
1. ORA error
2. 1.23
3. 100
4. 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?

1. ROUND
2. TRUNC
3. MOD
4. 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.

80. Examine the structure of the EMPLOYEES table as given below.

```SQL> DESC employees
Name			 Null?	  Type
----------------------- -------- ----------------
EMPLOYEE_ID		 NOT NULL NUMBER(6)
FIRST_NAME			  VARCHAR2(20)
LAST_NAME		 NOT NULL VARCHAR2(25)
EMAIL			 NOT NULL VARCHAR2(25)
PHONE_NUMBER			  VARCHAR2(20)
HIRE_DATE		 NOT NULL DATE
JOB_ID 		 NOT NULL VARCHAR2(10)
SALARY 			  NUMBER(8,2)
COMMISSION_PCT 		  NUMBER(2,2)
MANAGER_ID			  NUMBER(6)
DEPARTMENT_ID			  NUMBER(4)```

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?

1. `SELECT * FROM employees WHERE employee_id between 100 and 111 ORDER BY employee_id;`
2. ```SELECT first_name, last_name, employee_id, mod(employee_id, 4) Team# FROM employees WHERE employee_id between 100 and 111
ORDER BY employee_id;```
3. `SELECT first_name, last_name,mod(employee_id, 2) Team# FROM employees WHERE employee_ID <> 100;`
4. `SELECT first_name, last_name, mod(employee_id, 4) Team# FROM employees WHERE employee_ID = 100;`

81. What will be the outcome of the following query?

`SELECT SUBSTR('Life is Calling',1) FROM dual;`
1. ORA error as there should be minimum 3 arguments to the SUBSTR function.
2. Life is Calling
3. NULL
4. Life

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?

1. DD-MON-YY
2. DD-MON-RR
3. DD/MON/RR
4. 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?

`SELECT add_months(sysdate,-1) FROM dual;`
1. 09-MAY-2013 12:05pm
2. 10-MAY-2013 12:05pm
3. 10-JUL-2013 12:05pm
4. 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.

`SELECT next_day('01-JAN-2013','friday') FROM dual;`
1. 02-JAN-2013
2. Friday
3. 04-JAN-2013
4. 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?

1. 0
2. 1
3. 2
4. 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?

1. 19
2. 21
3. 20
4. 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?

1. 19
2. 21
3. 20
4. 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?

1. 19
2. 21
3. 20
4. 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?

1. 19
2. 21
3. 20
4. 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.

90. How many parameters does the SYSDATE function take?

1. 1
2. 2
3. 4
4. 0

Answer: D. The SYSDATE is a pseudo column in Oracle.

91. What is true about the SYSDATE function in Oracle DB?

1. It returns only the system date
2. It takes 2 parameters at least.
3. The default format is DD-MON-YY
4. The default format of SYSDATE is DD-MON-RR and it returns the date and time of the system according to the database server.

92. What will be the datatype of the result of the following operation?

"Date3 = Date1-Date2"
1. Date
2. Num1
3. 0
4. NULL

Answer: B. Subtraction of two dates results in number of days.

93. What will be the datatype of the result of the following operation?

"Date2 = Date1-Num1"
1. Date
2. Num1
3. 0
4. NULL

Answer: A. Subtraction of a number from a date value results in date.

94. What does a difference between two dates represent in Oracle DB?

1. The number of days between them
2. Difference in dates in not possible in Oracle DB
3. A date
4. NULL

95. What will be the outcome of the following query?

`SELECT months_between('21-JUN-13','19-JUN-13') FROM dual; `
1. ORA error
2. A positive number
3. A negative number
4. 0

Answer: C. If the first parameter is less than the second parameter, the MONTHS_BETWEEN returns a negative number.

96. What can be deduced if the result of MONTHS_BETWEEN (start_date,end_date) function is a fraction?

1. It represents the difference in number between the start date and end date.
2. The result cannot be a fractional number, it has to be a whole number.
3. NULL
4. 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.

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?

1. `SELECT sysdate FROM dual;`
2. `SELECT round(sysdate) FROM dual;`
3. `SELECT trunc (sysdate) FROM dual;`
4. `SELECT current_date FROM dual;`

98. What will be the outcome of the following query?

`SELECT months_between (to_date ('29-feb-2008'), to_date ('29-feb-2008 12:00:00','dd-mon-yyyy hh24:mi:ss'))*31 FROM dual; `
1. Approximately 0
2. 1
3. The query will throw an ORA error
4. 0.5 days

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.

99. What will be the outcome of the following query?

`SELECT add_months ('31-dec-2008',2.5) FROM dual; `
1. 31-feb-2009
2. 28-feb-2009
3. 31-mar-2009
4. 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?

1. `SELECT next_day ('30-nov-2012' , 'Friday') FROM dual;`
2. `SELECT next_day ('30-nov-2012' , 'Friday') -7 FROM dual;`
3. `SELECT last_day ('01-nov-2012' ) FROM dual;`
4. `SELECT next_day ('30-nov-2012' , 'sat') -1 FROM dual;`

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.