Your cart is currently empty!
Category: sql Certificate
-
Khóa học miễn phí SQL – Conditional Expressions nhận dự án làm có lương
SQL – Conditional Expressions Questions
1. What is true about data types in Oracle DB?
- They are given to columns for sorting purposes.
- They are given to columns for a structured representation in a table.
- They are given to columns to constrain the nature of the data it can store.
- They are not mandatory.
Answer: C. Data types define the nature of data which a column can store in a table. A column can store only one type of data. The primary data types available in Oracle are NUMBER, VARCHAR2, and DATE.
2. What is true about nested functions?
- There is a limit to use the Nested functions only 5 times in Oracle DB.
- They are evaluated from the outermost level to the innermost level.
- They are evaluated from the innermost level to the outermost level.
- All the functions in a Nested expression return the same data type.
Answer: C. Single row functions can group functions can be nested in a SELECT query in which the innermost function is the first one to be executed. The result of the execution of innermost function serves as the input for the outer function.
3. Which of the following functions simplify working with columns that potentially contain null values?
- Nested functions
- General functions
- Conditional functions
- None of the above
Answer: B. The general functions like NVL, NVL2, NULLIF, and COALESCE are used to pacify the effect of NULL while displaying the query results. They bypass the NULL values by assigning an alternative value.
4. Which of the following data types are appropriate for general functions?
- VARCHAR2
- NUMBER
- DATE
- All Datatypes
Answer: D. General functions are usually compatible with all primary data types like NUMBER, VARCHAR2 and DATE.
5. What is true about the COALESCE function?
- It accepts minimum 2 and maximum 5 input parameters
- It always returns the first NULL value among the input parameters
- It can accept unlimited number of input parameters
- It returns the first non-null parameter else it returns a null.
Answer: C, D. The COALESCE function takes two mandatory parameters and any number of optional parameters. The syntax is COALESCE(expr1, expr2,Ö,exprn), where expr1 is returned if it is not null, else expr2 if it is not null, and so on. COALESCE is a general form of the NVL function, as the following two equations illustrate: COALESCE(expr1,expr2) = NVL(expr1,expr2), COALESCE(expr1,expr2,expr3) = NVL(expr1,NVL(expr2,expr3))
6. How many input parameters are mandatory in NVL function?
- 0
- 1
- 2
- 3
Answer: C. The NVL function takes two mandatory parameters. Its syntax is NVL(original, ifnull), where original represents the term being tested and ifnull is the result returned if the original term evaluates to null. The data types of the original and ifnull parameters must always be compatible. They must either be of the same type, or it must be possible to implicitly convert ifnull to the type of the original parameter. The NVL function returns a value with the same data type as the original parameter.
7. What is wrong in the following statement?
NVL (ifnull, original)
- There is nothing wrong
- The parameter original is not required
- The parameter ”ifnull” is not required
- The correct statement is NVL (original,ifnull)
Answer: D. The NVL function evaluates whether a column or expression of any data type is null or not. If the term is null, an alternative not null value is returned; otherwise, the initial term is returned.
8. What will be the output of the following query?
SELECT NVL(1234) FROM dual;
- 1234
- 1000
- NULL
- ORA-00909:invalid number of arguments error
Answer: D. he NVL function takes two mandatory parameters. Its syntax is NVL(original, ifnull), where original represents the term being tested and ifnull is the result returned if the original term evaluates to null.
9. What will be output of the following query?
SELECT NVL(1234,'' '') FROM dual;
- A white space i.e. ” ”
- 1234
- NULL value
- ORA-01722: invalid number
Answer: D. The data types of the original and ifnull parameters must always be compatible. They must either be of the same type, or it must be possible to implicitly convert ifnull to the type of the original parameter. The NVL function returns a value with the same data type as the original parameter. The 1234 should be in single quotes. Implicit conversion of data type doesn”t happen in this case.
10. What will be outcome of the following query?
SELECT NVL(SUBSTR(''abc'',-4),''SUBSTR didn''t work'') FROM dual;
- abc
- bc
- c
- SUBSTR didn”t work
Answer: D.
11. You need to extract a report which gives the first name, last name and the commission percentage earned by all the employees in department 100. The report should not have any columns which are empty. All the columns should have at least a ”0” if there is no value for them. Which of the following queries will fulfill this requirement? (Consider the table structure 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 first_name, last_name, commission_pct*salary FROM employees WHERE department_id = 100;
-
SELECT first_name, last_name, NVL(commission_pct*salary,0) monthly_commission FROM employees WHERE department_id = 100;
-
SELECT first_name, last_name, NVL(commission_pct,0)*salary monthly_commission FROM employees WHERE department_id = 100;
-
SELECT first_name, last_name, commission_pct*salary FROM employees;
Answer: B, C.
12. What are the types of Data conversions in Oracle DB?
- Implicit conversions
- Explicit conversions
- External conversions
- Physical conversions
Answer: A, B. TO_CHAR, TO_NUMBER and TO_DATE are the three most widely used conversion functions and are discussed in detail. The TO_CHAR function converts numeric and date information into characters, while TO_NUMBER and TO_DATE convert character data into numbers and dates, respectively.
13. What happens during an implicit conversion in Oracle DB?
- Oracle DB implicitly converts one data type to the expected data type
- The user has to convert the data type to the expected data type
- Oracle DB doesn”t convert any data type
- Implicit conversion can be controlled by the user
Answer: A. If Oracle database implicitly converts a value to a compatible data type, it is known as Implicit conversion.
14. What happens during an explicit conversion in Oracle DB?
- Oracle DB converts one data type to the other and displays to the user explicitly
- Oracle DB prompts the user to convert one data type to the other and then converts the data type
- The user uses conversion functions supplied by Oracle DB to convert data types
- The data type is never converted explicitly in Oracle DB
Answer: C. When the programmer has to programmatically convert a value using one of the conversion functions, it is known as explicit conversion.
15. Which of the following conversion methods is recommended for the reliability of SQL statements in Oracle DB?
- Implicit and Explicit conversions
- Implicit conversion
- Explicit conversion
- None of the above
Answer: C. TO_CHAR, TO_NUMBER and TO_DATE are the three most widely used conversion functions and are discussed in detail. The TO_CHAR function converts numeric and date information into characters, while TO_NUMBER and TO_DATE convert character data into numbers and dates, respectively.
16. Which of the following is a valid implicit conversion performed by Oracle?
- NUMBER TO VARCHAR2
- NUMBER TO DATE
- CHAR TO DATE
- DATE TO VARCHAR2
Answer: A, D.
17. 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)
Which conversion method is applied to the following query?
SELECT first_name, salary FROM employees WHERE hire_date > ''01-JAN-13
- No conversion happens and this query results in an ORA error
- Explicit conversion
- Implicit conversion
- Both Implicit and explicit conversion
Answer: C. The string (VARCHAR2 or CHAR) is converted implicitly to a DATE by Oracle giving the required output as selected.
18. Which of the following is supported with respect to expression evaluation is supported by Oracle DB?
- NUMBER TO CHAR
- DATE TO VARCHAR2
- CHAR to DATE
- NUMBER TO DATE
Answer: A, B. DATE and NUMBER values can easily be converted to their character equivalents. Implicit character to date conversions are possible when the character string conforms to the following date patterns: [D|DD] separator1 [MON|MONTH] separator2 [R|RR|YY|YYYY].
19. What is mandatory for and implicit conversion of CHAR to NUMBER in Oracle to work?
- Nothing in particular is mandatory for this type of conversion
- It is mandatory that the character string represents a valid number
- No such conversion is supported by Oracle
- CHAR to NUMBER has to be converted explicitly only
Answer: B. Character data must represent a valid number to be considered for implicit conversion.
20. Which of the following expressions can be used explicitly for a conversion of a CHAR to a NUMBER?
- TO_CHAR
- Use TO_DATE and then convert the date to a NUMBER
- TO_NUMBER
- Such conversion is not possible
Answer: C. The TO_NUMBER function returns an item of type NUMBER. Character strings converted into numbers must be suitably formatted so that any nonnumeric components are translated or stripped away with an appropriate format mask.
21. Which of the following expressions can be used explicitly for a conversion of a NUMBER to a CHAR?
- TO_CHAR
- Use TO_DATE and then convert the date to a NUMBER
- TO_NUMBER
- Such conversion is not possible
Answer: A. The TO_CHAR function returns an item of data type VARCHAR2. When applied to items of type NUMBER, several formatting options are available.
22. Which of the following expressions can be used explicitly for a conversion of a CHAR to a DATE?
- TO_CHAR
- Use TO_DATE and then convert the date to a NUMBER
- TO_NUMBER
- TO_DATE
Answer: D. The TO_DATE function returns an item of type DATE. Character strings converted to dates may contain all or just a subset of the date time elements comprising a DATE. When strings with only a subset of the date time elements are converted, Oracle provides default values to construct a complete date. Components of character strings are associated with different date time elements using a format model or mask.
23. Which of the following expressions can be used explicitly for a conversion of a DATE to a CHAR?
- TO_CHAR
- TO_DATE
- TO_NUMBER
- Such conversion is not possible
Answer: A. The TO_CHAR function returns an item of data type VARCHAR2. When applied to items of type NUMBER, several formatting options are available.
24. Which of the following are the functions for explicit conversion provided by Oracle to convert one data type to the other?
- TO_CHAR
- TO_DATE
- TO_NUMBER
- All of the above
Answer: D. TO_CHAR, TO_NUMBER and TO_DATE are the three most widely used conversion functions and are discussed in detail. The TO_CHAR function converts numeric and date information into characters, while TO_NUMBER and TO_DATE convert character data into numbers and dates, respectively.
25. Interpret the working of the below function.
TO_CHAR(number/date, [format], [nlsparameters])
- It converts a VARCHAR2 to a CHAR
- It converts a number/date to a VARCHAR2 string with the format model [format]
- It converts a VARCHAR2 to a NUMBER or a DATE
- [NLSPARAMETERS] is mandatory in the statement
Answer: B. The TO_CHAR function returns an item of data type VARCHAR2. When applied to items of type NUMBER, several formatting options are available.
26. What does the [NLSPARAMETERS] clause in the following statement specify?
TO_CHAR(number/date, [format], [nlsparameters])
- Decimal character
- Group separator
- Currency symbol
- All of the above
Answer: D.
27. What value will the TO_CHAR (number/date, [format], [nlsparameters]) use if the [nlsparameters] parameter is omitted?
- It throws an ORA error
- The [nlsparameters] parameter is mandatory and it can”t be omitted.
- It will use the default parameter values for the session.
- It will use the default parameter values set during the database design.
Answer: C. By default, the TO_CHAR function considers the NLS settings of the current active session.
28. What is true about the following statement?
TO_CHAR(number/date, [format], [nlsparameters])
- The nlsparameters parameter specifies the language in which the month and day names are returned.
- The nlsparameters parameter is omitted on the execution of the above statement.
- The nlsparameters parameter will return a NULL whether specified or not
- The nlsparameters parameter will return the default language of the DB on every execution
Answer: A.
29. What is true regarding the following statement in Oracle DB?
TO_NUMBER(char, [format],[nlsparameters])
- It converts any string to a number in the format specified in [format]
- It converts only a NUMBER to the desired format as mentioned in [format]
- It converts a string with digits to a number in the format specified in [format]
- The result of this function is always a character
Answer: C. The TO_NUMBER function returns an item of type NUMBER. Character strings converted into numbers must be suitably formatted so that any nonnumeric components are translated or stripped away with an appropriate format mask.
30. What is true regarding the following statement in Oracle DB?
TO_DATE(char, [format],[nlsparameters])
- It converts any string to a DATE in the format specified in [format]
- It converts only a DATE to another DATE in the desired format as mentioned in [format]
- It converts a string with DATE to a number in the format specified in [format]
- It converts a string with DATE to a DATE in the format specified in [format]
Answer: C. The TO_DATE function returns an item of type DATE. Character strings converted to dates may contain all or just a subset of the date time elements comprising a DATE.
31. What will be the result if the [format] parameter in the following statement is omitted?
TO_DATE(char, [format],[nlsparameters])
- It will return a DATE value with the format DD-MON-YY
- It will return a DATE value with the format DD-MON-RR
- It will return a character value
- It will return a NUMBER value
Answer: A.
32. Which of the following is true about the following statement in Oracle DB?
TO_CHAR(date, ''frmt'')
- The fmt can be written in double quotes as well as single quotes.
- Case of the fmt doesn”t matter in this function
- Fmt can include any character or NUMBER
- The fmt has to be enclosed in single quotes and has to be a valid date format.
Answer: D.
33. What will the following statement on execution yield?
SELECT TO_CHAR (''01-JAN-13'' ''DD-MON-YY'') FROM dual;
- 01-JAN-13
- 01-01-2013
- An ORA error
- 1-JAN-13
Answer: C. The parameters ”01-JAN-13” and format model should be separated by a “,”.
34. What is true about the [fmt] parameter in the following statement?
TO_DATE ([date as string],[format])
- The fmt can be written in double quotes as well as single quotes.
- Case of the fmt doesn”t matter in this function
- The [fmt] parameter has an ”fm” element which removes spaces and suppresses leading zeroes.
- Fmt can include any character or NUMBER
Answer: C.
35. What is the abbreviation for the FM modifier in Oracle DB?
- First Move
- Filter Mode
- Fill Mode
- First Mode
Answer: C. The format model ”fm” stands for Fill Mode.
36. What is the abbreviation for the FX modifier in Oracle DB?
- First Expression
- Fill Expression
- First Extra
- Format Exact
Answer: D. The format model ”fm” stands for Format Exact.
37. How many maximum places for display will Oracle DB allocate to the Month element in the following statement?
SELECT TO_CHAR (sysdate, ''fmMonth'') FROM dual;
- 5
- 6
- 7
- 9
Answer: D. The longest word for Month is ”September” and hence Oracle pads according to 9 places for the display of the Month parameter.
38. Which of the following is true about the FM modifier in Oracle DB?
- This modifier suppresses blank padding in the subsequent character elements such as MONTH
- This modifier suppresses leading zeroes for subsequent number of elements such as MI
- This modifier has no effect on the date format
- This modifier is mandatory for all the date formats used with the function TO_CHAR
Answer: A, B.
39. What happens when the FM modifier is not used in the DATE format model in Oracle DB?
- The result of the character element is left padded with blanks to a variable length
- The result of the character element is right padded with blanks to a fixed length
- The leading zeroes are not returned in the result of the character element
- The length of the return value is fixed if the FM modifier is used
Answer: B.
40. How is a number result justified in the output buffer in a number format element of a TO_CHAR function when the FM modifier is used?
- Right
- Left
- Centre
- None of the above
Answer: B. The FM modifier suppresses blanks added to the left of the number.
41. What will be the outcome of the following query?
SELECT TO_CHAR (TO_DATE(''01-JAN-13''), ''fmDD Month YYYY'') FROM dual;
- 1 January2013
- 1 January 2013
- 1 Jan 2013
- 1 January 13
Answer: B. The TO_CHAR formats the input date as per the given format model.
42. How many spaces will be added to the ”DD” of the following query?
SELECT TO_CHAR (TO_DATE(''01-JAN-13'',''DD-MON-YY''), ''fmDD Month YYYY'') FROM dual;
- 0
- 1
- 2
- 3
Answer: A. The FM modifier removes all the padded spaces from the Date format..
43. What will be the outcome of the following query?
SELECT TO_CHAR (TO_DATE(''01-JAN-13'',''DD-MON-YY''), ''fmDdspth "of" Month YYYY fmHH:MI:SS AM'') FROM dual;
- It will return an ORA error because of the use of double quotes in the Date format
- 1st January 2013
- First of JANUARY 2013 12:00:00 AM
- First of January 2013 12:00:00 AM
Answer: D. The TO_CHAR formats the input date ”01-JAN-13” as per the given format.
44. Which of the following specifies the exact match for the character argument and the date format model of a TO_DATE function?
- TO_DATE
- TO_CHAR
- FM
- FX
Answer: D.
45. What is true about the FX modifier in the Oracle DB?
- It is case sensitive
- It ignores the spaces in the character argument when matching with the Date format model mentioned
- The punctuations and quoted text in the character argument do not necessarily match the format model
- None of the above
Answer: D.
46. What will be the outcome of the following query?
SELECT TO_DATE (''January 21, 2013'' , ''fxMonth DD, YYYY'') FROM dual;
- It will execute successfully
- It will give the result January 21, 2013
- It creates an ORA error
- It will give the result JANUARY 21, 2013
Answer: C. The character argument should match exactly with the format model if FX is used. Here the extra spaces after January are mismatching.
47. What is true about the FX modifier in Oracle DB?
- It can be used with TO_CHAR
- It can be used with both TO_CHAR and TO_DATE
- It can be used with only TO_DATE
- None of the above
Answer: C. The FX format modifier can only be used with the TO_DATE function.
48. Assuming the SYSDATE is 01-JAN-13, what will be the outcome of the following query?
SELECT TO_CHAR (SYSDATE, ''DDTH'') FROM dual;
- 1st of January
- 1st
- 1 ST
- 01ST
Answer: D.
49. Assuming the SYSDATE is 01-JAN-13, what will be the outcome of the following query?
SELECT TO_CHAR (SYSDATE, ''fmDDTH'') FROM dual;
- 1st of January
- 1st
- 1ST
- 01ST
Answer: C.
50. Assuming the SYSDATE is 01-JAN-13 and falls on Tuesday, what will be the outcome of the following query?
SELECT TO_CHAR (SYSDATE, ''fmDay'')||''''''s Meeting'' FROM dual;
- Tuesday
- TUESDAY
- TUESDAY”s Meeting
- Tuesday”s Meeting
Answer: D.
51. What will be the outcome of the following query?
SELECT TO_DATE(''01 / JAN / 13'',''DD-MON-YY'') FROM dual;
- ORA error
- 01-JAN-2013
- 01-JANUARY-13
- 01-JAN-13
Answer: D.
52. What will be the outcome of the following query?
SELECT TO_DATE(''01 ## JAN / 13'',''DD-MON-YY'') FROM dual;
- ORA error
- 01-JAN-2013
- 01-JANUARY-13
- 01-JAN-13
Answer: A. Use a single delimiter between the dates.
53. What will be the outcome of the following query?
SELECT TO_DATE(''01/JAN/13'',''fxDD-MON-YY'') FROM dual;
- 01-JAN-2013
- ORA error
- 01-JAN-13
- 01-JANUARY-13
Answer: B. With the format exact modifier, the input literal must match the format string.
54. What will be the outcome of the following query?
SELECT TO_DATE(''01-JAN-13'',''fxDD-MON-YY'') FROM dual;
- 01-JAN-2013
- ORA error
- 01-JAN-13
- 01-JANUARY-13
Answer: C.
55. What will be the outcome of the following query?
SELECT TO_DATE (''11-JAN-2013'',''fxDD-MON-YYYY'') FROM dual;
- 11-JAN-13
- 11-01-13
- 11-JAN-2013
- ORA error
Answer: C.
56. An employee Allen was hired on 1-JAN -13. What will be the outcome of the following query? (Assume that the NLS parameter for the session is set to DD-MON-YY)
SELECT TO_DATE(hire_date, ''fxfmDD-MON-YY'') FROM employees WHERE first_name=''ALLEN
- ORA error
- 01-JAN-2013
- 1-JAN-13
- 1-JAN-2013
Answer: C.
57. What will be the outcome of the following query?
SELECT TO_CHAR(TO_DATE (''01-JAN-2013''), ''DD-Month-RR'') FROM dual;
- 01-JAN-13
- 01-01-2013
- 01-January-13
- 01-January -13
Answer: D. The Month modifier is padded up to 9 places with spaces.
Examine the structure of the EMPLOYEES table as given and answer the questions 58 and 59 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)
58. You need to list out the first and the last names for all the employees who were hired before the year 1990. Which of the following WHERE statements will give you the required results? (Assume that this list is to be generated on ”01-JAN-2013”)
- WHERE TO_DATE (hire_date, ”DD-MON-YY”)
- WHERE TO_DATE (hire_date, ”DD-MON-YYYY”)
- WHERE TO_DATE (hire_date, ”DD-MON-YY”)
- WHERE TO_DATE (hire_date, ”DD-MON-RR”)
Answer: D. Using the RR format will consider the year portion of the date between 1950 and 1999.
59. Which of the following is an example of a nested function?
-
SELECT lower(last_name) FROM employees;
-
SELECT upper (last_name) FROM employees;
-
SELECT concat (first_name, last_name) FROM employees;
-
SELECT upper (concat(SUBSTR(first_name,1,6),''_UK'')) FROM employees;
Answer: D. More than one functions in a function is known as nesting of functions.
60. What is true about the COALESCE function in Oracle DB?
- It can take only 2 arguments
- All the arguments in the COALESCE function can be of different data types
- All the arguments in the COALESCE function should be of the same data type
- None of the above
Answer: C. The COALESCE function takes two mandatory parameters and any number of optional parameters. The syntax is COALESCE(expr1, expr2,Ö,exprn), where expr1 is returned if it is not null, else expr2 if it is not null, and so on.
61. Which of the following functions is used for conditional expressions?
- TO_CHAR
- COALESCE
- NVL
- CASE
Answer: D. The CASE expression facilitates if-then-else conditional logic. There are two variants of the CASE expression. The simple CASE expression lists the conditional search item once, and equality to the search item is tested by each comparison expression. The searched CASE expression lists a separate condition for each comparison expression.
62. What will be the outcome of the following query?
SELECT TO_CHAR(TO_DATE(''01-JAN-13'',''DD-MON-YY''),''dy-mon-yyyy'') FROM dual;
- 01-jan-2013
- 01-jan-13
- tue-jan-13
- tue-jan-2013
Answer: D. The format model ”dy” spells the first three letters of the day from the input date. ”DY” will give ìTUEî and not ìtueî as in the query given above.
63. What will be the outcome of the following query?
SELECT TO_CHAR(TO_DATE(''01-JAN-13'',''DD-MON-YY''),''fmDAY-mon-yyyy'') FROM dual;
- 1-jan-2013
- 01-jan-13
- TUESDAY -jan-13
- TUESDAY-jan-2013
Answer: D. fmDAY (for all capital letters) or fmday (for all small letters) format model will spell the day of the input date without any trailing or leading spaces.
64. What will be the outcome of the following query?
SELECT TO_CHAR(TO_DATE(''19-JUN-13''),''qth'') FROM dual;
- 1st
- 2nd
- 3rd
- 4th
Answer: B. The format model ”q” gives the quarter in which the given date falls. In the given query, APR-JUN is the 2nd quarter.
Examine the structure of the EMPLOYEES table as given and answer the questions 65 to 67 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)
65. Some employees joined company ABC in the second week of the current year i.e. 2013. You need to list out the first names, last names and the department IDs for all these employees. Which of the following queries will give you the required result?
-
SELECT first_name, last_name, department_id FROM employees WHERE TO_DATE(hire_date,''w'') >2;
-
SELECT first_name, last_name, department_id FROM employees WHERE TO_DATE(hire_date,''w'') between 1 and 2;
-
SELECT first_name, last_name, department_id FROM employees WHERE TO_CHAR(hire_date,''w'')
-
SELECT first_name, last_name, department_id FROM employees WHERE TO_CHAR(sysdate,''ww'') =2;
Answer: D. The format model ”ww” gives the week of the year.
66. The management of a company ”ABC” wants to find out how many employees were hired in the 3rd quarter of the year 2012. Which of the following queries will give the required result?
-
SELECT count(employee_id ) FROM employees WHERE TO_CHAR(hire_date, ''q'') > 1;
-
SELECT count(employee_id ) FROM employees Where TO_CHAR(hire_date, ''q'') = 3;
-
SELECT employee_id FROM employees Where TO_CHAR(hire_date, ''q'') = 3;
-
SELECT count(employee_id ) FROM employees Where TO_CHAR(hire_date, ''q'') between 0 and 3;
Answer: B. The format model ”q” gives the quarter of a year.
67. A certificate of achievement has to be printed and presented to all those employees who joined the organization before the year 2008 and are still a part of the organization. The printing of the first name, last name and the dates will happen by using placeholders fetched from a query. The Certificate should contain all the digits spelled out. Example: Tuesday, the 1st of January, Two Thousand and eight. The final text of the Certificate should be in the following form: This is to certify that first_name last_name who joined the organization on Tuesday, the 1st of January, Two Thousand and eight has successfully completed 5 glorious years in the company. Which of the following queries will be helpful in printing the dates as in the required format?
-
SELECT TO_CHAR (hire_date, ''fmDay,"the "ddth "of " Month, Yysp.'') FROM employees;
-
SELECT TO_CHAR (hire_date, ''Day,"the "ddth "of " Mon, Yyyy.'') FROM employees;
-
SELECT TO_CHAR (hire_date, ''fmDAY,"the "ddth "of " Month, Ysp.'') FROM employees;
-
SELECT TO_CHAR (hire_date, ''fmDay,"the "ddth "of " MONTH, Rsp.'') FROM employees;
Answer: A. The ”sp” identifier spells the year in simple english language.
68. A report has to be generated which creates an audit history table for all the employees from an available paper source. The paper source only has data for the year 2011 when the employees were hired. This data only has the year of the hire date. You need to put the date in the audit-history table as 1st of January of that particular year (without leading zeroes and spaces). Which of the following clauses will achieve this requirement?
- TO_DATE(”2011”,”YYYY”)
- TO_CHAR (TO_DATE (”2011”,”YYYY”),”fmMM/DD/YYYY”)
- TO_CHAR(”2011”,”DD-MON-YYYY”)
- TO_DATE (”01-01-2011”,”DD-MM-YYYY”)
Answer: B.
69. What will be the outcome of the following query?
SELECT TO_NUMBER (''$3000'') FROM dual;
- 3000
- $3000
- NULL
- ORA error
Answer: D. The query throws error of “ORA-01722: invalid number” because the given string cannot be recognized in numbers.
70. What will be the outcome of the following query?
SELECT TO_NUMBER(''$3,000.67'',''$999,999.99'') FROM dual;
- $3000.67
- 3000
- 3000.67
- ORA error as the input string has lesser characters than the format model mentioned.
Answer: C. The appropriate format model helps the TO_NUMBER to convert given string in numbers.
71. What will be the outcome of the following query?
SELECT TO_NUMBER(''$3,000,000.67'',''$999,999.99'') FROM dual;
- $3,000,000.67
- 3000,000.67
- 3000.67
- ORA error as the format model has lesser characters than the input string. It should be the same.
Answer: D.
72. What will the following query yield?
SELECT TO_NUMBER(''456.23'',''999.99'') FROM dual;
- ORA error
- 456.23
- 456
- None of the above
Answer: B.
73. What is true about the nested functions?
- Nesting implies the use of output from one function as an input to another.
- Nesting can be applied up to 3 levels of nesting.
- Nesting are applied to Multiple row functions to any level of depth
- None of the above
Answer: A. The output from a function execution is used as input for its preceding function.
74. What will be the result of the following query?
SELECT NULLIF(1,2-1) FROM dual;
- 0
- 1
- NULL
- None of the above
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. Here 1 and the expression “2-1” are considered equal by oracle and hence NULL is returned.
75. What will be the outcome of the following query?
SELECT NULLIF(''01-JAN-2013'',''01-JAN-13'') FROM dual;
- 1-JAN-13
- 01-JAN-2013
- NULL
- ORA error
Answer: B. Since the lengths for both the dates is different, the first parameter is returned.
76. What is the ratio of mandatory parameters to optional parameters in the COALESCE function in Oracle DB?
- 0:1
- 1:2
- 2: any number
- None of the above
Answer: C. The COALESCE function takes two mandatory parameters and any number of optional parameters. OALESCE is a general form of the NVL function, as the following two equations illustrate: COALESCE(expr1,expr2) = NVL(expr1,expr2), COALESCE(expr1,expr2,expr3) = NVL(expr1,NVL(expr2,expr3)).
77. Which of the following equations are true?
- COALESCE(expr1,expr2) = NVL(expr1,expr2)
- COALESCE(expr1,expr2) = NVL2(expr1,expr2,expr3)
- COALESCE(expr1,expr2,expr3) = NVL(expr1,NVL(expr2,expr3))
- All of the above
Answer: A, C.
78. Which of the following is the correct syntax of NVL2?
- NVL(original,ifnotnull)
- NVL2(original,ifnull,ifnotnull)
- NVL(original,NULL)
- NVL(original,ifnull) and NVL2(original,ifnotnull,ifnull)
Answer: D.
79. Which of the following functions is an ANSI standard keyword inherited in Oracle?
- CASE
- DECODE
- Both A and B
- None of the above
Answer: A. CASE is an ANSI SQL compliant and not Oracle specific.
80. What is true about the DECODE statement in Oracle DB?
DECODE(expr1,comp1,iftrue1,comp2,[iftrue2])
- Comp2 is not optional
- If expr1 is equal to comp1 then comp2 is returned
- If expr1 is equal to comp1 then iftrue1 is returned
- None of the above
Answer: C. The DECODE function implements if-then-else conditional logic by testing its first two terms for equality and returns the third if they are equal and optionally returns another term if they are not. The DECODE function takes at least three mandatory parameters, but can take many more.
81. What is true about the parameters in the DECODE function?
- All parameters must be VARCHAR2
- No expressions can be parameters to the DECODE function
- All parameters must be NUMBER
- The return data type is the same as that of the first matching comparison item.
Answer: D. The DECODE function implements if-then-else conditional logic by testing its first two terms for equality and returns the third if they are equal and optionally returns another term if they are not.
82. What will be the outcome of the following query?
SELECT DECODE (null,null,''expr3'') FROM dual;
- NULL
- 0
- Expr3
- ORA error
Answer: C. DECODE considers two NULL values to be equivalent. One of the anomalies of NULL in Oracle.
83. What will be the outcome of the following query?
SELECT DECODE (''elephant'',''rat'',''lion'',''tiger'',''cat'',''squirrel'',''elephant'',''koala'',''rat'',''And it continues'') FROM dual;
- elephant
- rat
- koala
- And it continues
Answer: D. The DECODE function takes at least three mandatory parameters, but can take many more.
84. What is the number of minimum mandatory parameters for the CASE expression in Oracle DB?
- 0
- 1
- 2
- 3
Answer: D. The CASE expression facilitates if-then-else conditional logic. There are two variants of the CASE expression. The simple CASE expression lists the conditional search item once, and equality to the search item is tested by each comparison expression. The searched CASE expression lists a separate condition for each comparison expression. It takes atleast 3 mandatory parameters but it can take more also.
85. Which of the following keyword combinations is used to enclose a CASE statement in Oracle DB?
- CASEÖEND IF;
- IFÖEND IF;
- CASEÖ;
- CASEÖEND;
Answer: D.
86. Which of the following values is returned in case of a false value if the ELSE block in the CASE statement is undefined?
- 0
- NULL
- Either 0 or NULL
- None of the above
Answer: B.
87. Which of the following options is true if more than one WHEN..THEN levels exist in a CASE statement?
- The CASE searches or compares only the first level and exists without checking other levels of WHENÖTHEN.
- The CASE statement will search in all the levels of WHENÖTHEN until it finds a match.
- Both A and B
- None of the above
Answer: B.
88. What data types can be the search, comparison and result parameters in the CASE statement?
- VARCHAR2
- DATE
- NUMBER
- Column values, literals and expressions
Answer: D.
89. The CASE statement cannot be used in which of the following parts of an Oracle SQL query?
- SELECT
- None of these options
- WHERE
- ORDER BY
Answer: B.
90. 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 in Oracle DB?
SELECT first_name, salary, CASE department_id WHEN 100 THEN ''Accounts'' WHEN 101 THEN ''Human Resources'' WHEN 102 THEN ''Sales'' ELSE ''Unknown'' END FROM employees;
- It will create an ORA error as more than one WHENÖTHEN statements cannot be written in the CASE statement.
- It will display the department IDs as 100,101,102
- It will only display ”Accounts” where ever the department ID 100 appears and ignore the remaining commands.
- None of the above
Answer: D. The CASE expression facilitates if-then-else conditional logic. There are two variants of the CASE expression. The simple CASE expression lists the conditional search item once, and equality to the search item is tested by each comparison expression. The searched CASE expression lists a separate condition for each comparison expression.
91. What is the maximum number of WHENÖTHEN levels a CASE statement in Oracle DB can have?
- Unlimited
- 1000
- 216
- 255
Answer: D.
92. What will be the outcome of the following query?
SELECT NVL2( NULLIF (''BMW'',''AUDI''), ''HYUNDAI'', ''FERRARI'' ) FROM dual;
- BMW
- FERRARI
- NULL
- HYUNDAI
Answer: D. The NVL2 function provides an enhancement to NVL but serves a very similar purpose. It evaluates whether a column or expression of any data type is null or not. If the first term is not null, the second parameter is returned, else the third parameter is returned.
93. Assuming the SYSDATE is 01-JAN-13 , what will the following query yield?
SELECT TO_CHAR (sysdate, ''fmddth" of" Month YYYY'') FROM dual;
- 1st January, 2013
- 1st of Jan, 2013
- 01st of January, 2013
- 1st of January 2013
Answer: D. The ìthî format model gives the day of the date as ìstî or ìthî.
94. What will be the outcome of the following query?
SELECT TO_CHAR (TO_DATE(''01-JAN-13'',''DD-MON-YY''), ''MmSP Month Yyyysp'') FROM dual;
- First January Two Thousand Thirteen
- First JAN Two Thousand Thirteen
- One January Two Thousand Thirteen
- None of the above
Answer: C.
95. What will be the outcome of the following query?
SELECT TO_CHAR (TO_DATE(''01-JAN-13'',''DD-MON-YY''), ''DD-MON-YYYY hh24SpTh'') FROM dual;
- First January Two Thousand Thirteen
- One January Two Thousand Thirteen
- ORA error
- 01-JAN-2013 zeroeth
Answer: D. Spelling out the timestamp component can be done using ”SpTh” format modifier.
96. Which of these functions do the work similar to if-then-else logic in SQL statements?
- TO_CHAR
- TO_NUMBER
- Both A and B
- CASE
Answer: D. The CASE expression facilitates if-then-else conditional logic. There are two variants of the CASE expression. The simple CASE expression lists the conditional search item once, and equality to the search item is tested by each comparison expression. The searched CASE expression lists a separate condition for each comparison expression.
97. 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 SQL query?
SELECT DECODE (salary,10000) FROM employees;
- 10000
- NULL
- 0
- ORA error
Answer: B. The DECODE function implements if-then-else conditional logic by testing its first two terms for equality and returns the third if they are equal and optionally returns another term if they are not. The DECODE function takes at least three mandatory parameters, but can take many more. If the default value in the DECODE function is omitted, a NULL is returned.
98. You need to display the time of the Oracle DB session up to 3 decimal places of the fractional seconds. Which of the following queries will give the required output?
-
SELECT TO_CHAR(sysdate, ''DD-MON-YY HH24:MI:SS.FF'') FROM dual;
-
SELECT TO_CHAR(sysdate, ''DD-MON-YY HH24:MI:SS'') FROM dual;
-
SELECT TO_CHAR(sysdate, ''DD-MON-YY HH24:MI:SS.FF3'') FROM dual;
-
SELECT TO_CHAR(sysdate, ''DD-MON-YY'') FROM dual;
Answer: C. The FF [1..9] extension to the HH:MI:SS format yields fractional seconds up to 1..9 digits in the fractional seconds.
99. Which of the following punctuation marks can be used with Dates and Times in Oracle DB?
- #
- @
- ,
- :
Answer: C, D.
100. 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 find the day of the year when the employee Jaimie Patrick was hired in the company ”ABC”. Which of the following queries will give the required output?
-
SELECT TO_CHAR(hire_date, ''DDD'') FROM employees WHERE last_name = ''Patrick'' AND first_name = ''John
-
SELECT TO_CHAR(hire_date, ''YYYY'') FROM employees WHERE last_name = ''Patrick'' AND first_name = ''John
-
SELECT TO_CHAR(hire_date, ''DD-MON-YYYY'') FROM employees WHERE last_name = ''Patrick'' AND first_name = ''John
-
SELECT TO_CHAR(hire_date, ''DD-MON-RR'') FROM employees WHERE last_name = ''Patrick'' AND first_name = ''John
Answer: A. The format model ”DDD” returns the day of the year on which the given date falls.
101. A report is required to be generated which gives the timings for all the batch runs that started on midnight 1st June, 2013. These timings should be in the precision of seconds after midnight. Which of the following clauses will fulfill the requirement?
- TO_CHAR(sysdate,”HH24:MI:SS”)
- TO_CHAR(sysdate,”HH24:MI:SS.FF”)
- TO_CHAR(sysdate,”HH24:MI:SSSS”)
- TO_CHAR(sysdate,”HH24:MI:SS.FF3”)
Answer: C. the ”SSSS” format model gives the seconds after midnight.
Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc
Khóa học miễn phí SQL – Conversion Functions nhận dự án làm có lương
SQL – Conversion Functions Questions
1. What will be the outcome of the following query?
SELECT ROUND(144.23,-1) FROM dual;
- 140
- 144
- 150
- 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?
- An error because the ROUND function cannot be used with Date arguments.
- An error because the WHERE condition expression is invalid.
- Number of days since the employee was hired based on the current San Diego date and time.
- 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?
-
SELECT first_name, last_name FROM employees WHERE INSTR(first_name,''s'') 0 AND SUBSTR(last_name,2,1) = ''t
-
SELECT first_name, last_name FROM employees WHERE INSTR(first_name,''s'') '''' AND SUBSTR(last_name,2,1) = ''t
-
SELECT first_name, last_name FROM employees WHERE INSTR(first_name,''e'') IS NOT NULL AND SUBSTR(last_name,2,1) = ''t
-
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?
- COUNT (*) counts duplicate values and NULL values in columns of any data type.
- COUNT function cannot work with DATE datatypes.
- COUNT (DISTINCT job_id) returns the number of rows excluding rows containing duplicates and NULL values in the job_id column.
- 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?
- NOT NULL
- INSTR
- SUBSTR
- 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;
- 100
- 999
- NULL
- 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?
- They accept only a single argument.
- They can be nested only to two levels.
- Arguments can only be column values or constants.
- 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?
-
SELECT TO_CHAR(1680.00,''$99G99D99'') FROM dual;
-
SELECT TO_CHAR(1680.00,''$9,999V99'') FROM dual;
-
SELECT TO_CHAR(1680.00,''$9,999D99'') FROM dual;
-
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;
- 78945*****
- **78945.45
- The function RPAD cannot be nested with other functions
- 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?
- NVL
- NVLIF
- NVL2
- 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?
- Character
- Numeric
- Conversion
- 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?
- SELECT
- WHERE
- ORDER BY
- 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?
- The syntax of NVL is NVL (exp1, exp2) where exp1 and exp2 are expressions.
- NVL (exp1, exp2) will return the value of exp2 if the expression exp1 is NULL.
- NVL (exp1, exp2) will return the value of the expression exp2 if exp1 is NOT NULL.
- 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;
- It will throw an ORA error on execution.
- It will list the job IDs for all employees from EMPLOYEES table.
- It will list the job IDs of all employees and substitute NULL job IDs with a literal ”Unknown”.
- 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;
- NULL
- 1
- 0
- 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;
- It will display 0 in the salary column for all the employees whose first name starts with a ”P”
- It will display the salaries for the employees whose name start with a ”P” and 0 if the salaries are NULL.
- It will throw an ORA error as the ORDER BY clause should also contain the salary column.
- 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;
- The two expressions arg1 and arg2 should only be in VARCHAR2 or NUMBER data type format.
- The arguments arg1 and arg2 should have the same data type
- 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.
- 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;
- It will return the value ”Regular Employee” for all the employees who have NULL job IDs
- It will return the value ”New Joinee” for all the employees who have NULL job IDs
- It will return ”Regular Employee” if the job ID is NULL
- 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)
- Arg2 and Arg3 can have any data type
- Arg1 cannot have the LONG data type
- Oracle will convert the data type of expr2 according to Arg1
- 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;
- Salary will be returned if the Commission for the employee is NOT NULL.
- Commission_pct will be returned if the Commission for the employee is NOT NULL.
- Employees with the first name starting with ”P” and salary+(salary*commission_pct) will be returned if the employee earns a commission.
- 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?
- NULLIF(expr1,expr2) will return expr2 if the two expressions are NOT NULL.
- NULLIF(expr1,expr2) will return 0 if the two expressions are NULL.
- NULLIF(expr1,expr2) will return NULL if the two expressions are equal.
- 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)
- Arg1 and Arg2 can be of different data types.
- Arg1 and Arg2 have to be equal in order to be used in the NULLIF function.
- There is no internal conversion of data types if NULLIF used as in the case of NVL and NVL2.
- This is equivalent to CASE WHEN Arg1 = Arg22 THEN NULL ELSE Arg1 END.
Answer: D.
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?
- It will display the old job ID when the new job ID is NULL.
- It will execute successfully and produce the required output.
- It will display the new job ID if the new job ID is equal to the old job ID
- It will throw an ORA error on execution.
Answer: B.
24. Which of the following is not a property of functions?
- Perform calculations on data
- Convert column data types
- Modify individual data items
- 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?
- They return no value
- They return one result per row and operate on all the rows of a table.
- They return one result per row with input arguments
- 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?
- Multiple-row functions
- Single column functions
- Single value functions
- 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?
- VARCHAR2
- Character
- LONG
- NULLIF
Answer: B. Character, Date, Conversion, General, Number are the types of Single row functions.
28. What is the most appropriate about Multiple Row Functions?
- They return multiple values per each row.
- They return one result per group of rows and can manipulate groups of rows.
- They return one result per row and can manipulate groups of rows.
- 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?
- Single row functions
- Multi group functions
- Multiple row functions
- 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?
- They can be nested
- They accept arguments and return more than one value.
- They cannot modify a data type
- 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?
- 0
- Only 1
- Only 2
- 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?
- Data types
- SELECT statements
- Expression
- 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?
- They return only character values
- They accept NUMBER values
- They accept character arguments and can return both character and number values
- 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?
- They return both Character as well as Number values
- They can”t accept expressions as input
- Number functions can”t be nested.
- They accept Number arguments and return Number values only.
Answer: D.
35. Which of the following is an exception to the return value of a DATE type single-row function?
- TO_DATE
- SYSDATE
- MONTHS_BETWEEN
- 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?
- TO_CHAR
- TO_DATE
- NVL
- 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?
- CONCAT
- SUBSTR
- INITCAP
- 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;
- Hi World !!!
- Hi WORLD !!!
- hi world !!!
- 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;
- Hello World
- HELLO world
- hello World
- hello world
Answer: C. 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;
- SELECT first_name||last_name FROM employees;
- SELECT first_name||” ” || last_name FROM employees;
- SELECT last_name||”, ”||first_name FROM employees;
- 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;
- The job id for ABEL is a sa_rep
- The job id forABEL is a sa_rep
- The job id for abel is SA_REP
- The job id for abel is sa_rep
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?
SELECT employee_id, last_name, department_id FROM employees WHERE last_name = ''smith
- It will display the details of the employee with the last name as Smith
- It will give no result.
- It will give the details for the employee having the last name as ”Smith” in all Lower case.
- 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?
- It can have only characters as input.
- It can have only 2 input parameters.
- It can have 2 or more input parameters
- 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?
- It extracts a string of determined length
- It shows the length of a string as a numeric value
- It finds the numeric position of a named character
- 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;
- 2
- 3
- 1
- 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?
- They give the same results when operated on a string.
- LENGTH gives the position of a particular character in a string
- INSTR gives the position of a particular character in a string while LENGTH gives the length of the string.
- LENGTH and INSTR can be used interchangeably.
Answer: C.
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;
- It results in an error as substitution variables cannot be used with single row functions
- It prompts the user to input the jobid on each execution and then displays the job id in UPPER case
- It gives the jobid as it is present in the table EMPLOYEES without making any change
- 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?
- It is owned by the user SYS and can be access by all the users.
- It contains only one column and one row.
- The value in the DUMMY column of the DUAL table is ”X”
- 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;
- The query produces error.
- No of hours to a date with date as the result.
- Sysdate arithmetic is ignored.
- 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;
- 100
- 100+100
- ORA error
- 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;
- 20-may-2013
- ORA error as LOWER and UPPER cannot accept date values.
- 20-MAY-13
- 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;
- 4
- 24
- 24/6
- 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?
-
SELECT INITCAP (last_name||'' works as a ''||job_id "Job Description" FROM employees WHERE initcap (last_name) like ''A%
-
SELECT INITCAP (last_name) ||INITCAP('' works as a: '')|| INITCAP(job_id) "Job Description" FROM employees WHERE initcap (last_name) like ''A %
-
SELECT INITCAP (last_name||'' works as a ''||INITCAP(job_id)) "Job Description" FROM employees WHERE initcap (last_name) = ''A
-
SELECT UPPER (LOWER (last_name||'' works as a ''||job_id)) "Job Description" FROM employees WHERE lower (last_name) = ''A
Answer: A, B.
54. Assuming the SYSDATE is 20-FEB-13, What will be the outcome of the following query?
SELECT CONCAT (''Today is :'', SYSDATE) FROM dual;
- Today is : 20-feb-13
- The query throws error of incompatible type arguments.
- Today is : 20-Feb-13
- 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;
- First_namelast_namejob_id
- First_name, last_name, job_id
- Error as CONCAT cannot be nested
- 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?
-
SELECT concat (first_name,concat ('' '', concat(last_name, concat('' earns '', SALARY)))) Concat_String FROM employees WHERE department_id = 100;
-
SELECT concat (first_name, last_name||'' ''|| salary) FROM employees WHERE department_id = 100;
-
SELECT concat (first_name, concat(last_name, '' ''))||earns||salary FROM employees WHERE department_id = 100;
-
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;
- 25
- 19
- 20
- 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?
-
SELECT country_name FROM countries WHERE LENGTH (country_name)= 5;
-
SELECT country_name FROM countries WHERE length (country_name)> 5;
-
SELECT SUBSTR(country_name, 1,5) FROM countries WHERE length (country_name)
-
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?
- It aligns the string to the left hand side of a column
- It returns a string padded with a specified number of characters to the right of the source string
- It aligns character strings to the left and number strings to right of a column
- It returns a string padded with a specified number of characters to the left of the source string
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?
- The character strings used for padding include only characters.
- The character strings used for padding include only literals
- The character strings used for padding cannot include expressions.
- The character strings used for padding include literals, characters and expressions.
Answer: D.
61. What is the maximum number of input arguments in LPAD and RPAD functions?
- 1
- 2
- 3
- 0
Answer: C. LPAD and RPAD take maximum of 3 arguments. If there are 2 arguments given, the padding happens by spaces.
62. What will be the outcome of the following query?
SELECT lpad (1000 +300.66, 14, ''*'') FROM dual;
- *******1300.66
- 1300*******
- 1300.66
- ****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?
- It is similar to SUBSTR function in Oracle
- It removes characters from the beginning or end of character literals, columns or expression
- TRIM function cannot be applied on expressions and NUMBERS
- 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?
-
SELECT LTRIM(Title,''"'') FROM MAGAZINE;
-
SELECT LTRIM(RTRIM(Title,''."''),''"'') FROM MAGAZINE;
-
SELECT LTRIM (Title,''"THE'') FROM MAGAZINE;
-
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
- 2
- 0
- 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;
- 2
- 10
- 7
- 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;
- #5
- #3
- #7
- #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?
-
SELECT rpad(salary, 15,0) FROM employees;
-
SELECT lpad(salary,15,0) FROM employees;
-
SELECT ltrim(salary,15,0) FROM employees;
-
SELECT trim(salary,15,0) FROM employees;
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?
-
SELECT SUBSTR(first_name, 2) FROM employees;
-
SELECT SUBSTR(first_name, -2) FROM employees;
-
SELECT RTRIM(first_name, 2) FROM employees;
-
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;
- 3
- N-13
- 0
- 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?
- LTRIM
- TRIM
- TRUNC
- REPLACE
Answer: D.
72. What will be the outcome of the following query?
SELECT replace(9999.00-1,''8'',88) FROM dual;
- 999
- 9998
- 99988
- 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?
-
SELECT first_name, last_name ,SUBSTR(first_name, 1,1)||'' ''||SUBSTR(last_name, 1,14) formal_name FROM employees;
-
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)
-
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;
-
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;
Answer: D.
74. What will be the outcome of the following query?
SELECT round(148.50) FROM dual;
- 148.50
- 140
- 150
- 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;
- 10-JUN-13
- 1-JUN-13
- ORA error as the TRUNC function can”t have an input parameter when used with dates.
- 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;
- 2000
- 1000
- 1901
- 1901.00
Answer: B.
77. What is the syntax of the MOD function in Oracle DB?
- Mod(divisor,dividend)
- MOD(divisor,1)
- MOD(dividend,divisor)
- 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;
- ORA error
- 1.23
- 100
- 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?
- ROUND
- TRUNC
- MOD
- 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?
-
SELECT * FROM employees WHERE employee_id between 100 and 111 ORDER BY employee_id;
-
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;
-
SELECT first_name, last_name,mod(employee_id, 2) Team# FROM employees WHERE employee_ID 100;
-
SELECT first_name, last_name, mod(employee_id, 4) Team# FROM employees WHERE employee_ID = 100;
Answer: B.
81. What will be the outcome of the following query?
SELECT SUBSTR(''Life is Calling'',1) FROM dual;
- ORA error as there should be minimum 3 arguments to the SUBSTR function.
- Life is Calling
- NULL
- 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?
- DD-MON-YY
- DD-MON-RR
- DD/MON/RR
- 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;
- 09-MAY-2013 12:05pm
- 10-MAY-2013 12:05pm
- 10-JUL-2013 12:05pm
- 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;
- 02-JAN-2013
- Friday
- 04-JAN-2013
- 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?
- 0
- 1
- 2
- 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?
- 19
- 21
- 20
- 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?
- 19
- 21
- 20
- 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?
- 19
- 21
- 20
- 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?
- 19
- 21
- 20
- 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
- 2
- 4
- 0
Answer: D. The SYSDATE is a pseudo column in Oracle.
91. What is true about the SYSDATE function in Oracle DB?
- It returns only the system date
- It takes 2 parameters at least.
- The default format is DD-MON-YY
- The default format of SYSDATE is DD-MON-RR and it returns the date and time of the system according to the database server.
Answer: D.
92. What will be the datatype of the result of the following operation?
“Date3 = Date1-Date2”- Date
- Num1
- 0
- 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”- Date
- Num1
- 0
- 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?
- The number of days between them
- Difference in dates in not possible in Oracle DB
- A date
- NULL
Answer: A.
95. What will be the outcome of the following query?
SELECT months_between(''21-JUN-13'',''19-JUN-13'') FROM dual;
- ORA error
- A positive number
- A negative number
- 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?
- It represents the difference in number between the start date and end date.
- The result cannot be a fractional number, it has to be a whole number.
- NULL
- 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?
-
SELECT sysdate FROM dual;
-
SELECT round(sysdate) FROM dual;
-
SELECT trunc (sysdate) FROM dual;
-
SELECT current_date FROM dual;
Answer: D.
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;
- Approximately 0
- 1
- The query will throw an ORA error
- 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;
- 31-feb-2009
- 28-feb-2009
- 31-mar-2009
- 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?
-
SELECT next_day (''30-nov-2012'' , ''Friday'') FROM dual;
-
SELECT next_day (''30-nov-2012'' , ''Friday'') -7 FROM dual;
-
SELECT last_day (''01-nov-2012'' ) FROM dual;
-
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.
Khóa học lập trình tại Toidayhoc vừa học vừa làm dự án vừa nhận lương: Khóa học lập trình nhận lương tại trung tâm Toidayhoc