Question : Which statement adds a column called salary to the employees table having 100 rows, which cannot contain null?
1. A 2. B 3. C 4. D
Correct Answer : 1 Explanation: NOT NULL Constraints
A NOT NULL constraint prohibits a column from containing nulls. The NULL keyword by itself does not actually define an integrity constraint, but you can specify it to explicitly permit a column to contain nulls. You must define NOT NULL and NULL using inline specification. If you specify neither NOT NULL nor NULL, then the default is NULL.
NOT NULL constraints are the only constraints you can specify inline on XMLType and VARRAY columns. To satisfy a NOT NULL constraint, every row in the table must contain a value for the column.
Note: Oracle Database does not index table rows in which all key columns are null except in the case of bitmap indexes. Therefore, if you want an index on all rows of a table, then you must either specify NOT NULL constraints for at least one of the index key columns or create a bitmap index. Restrictions on NOT NULL Constraints NOT NULL constraints are subject to the following restrictions: You cannot specify NULL or NOT NULL in a view constraint. You cannot specify NULL or NOT NULL for an attribute of an object. Instead, use a CHECK constraint with the IS [NOT] NULL condition.
Question : Which two statements are true regarding single row functions? A. MOD: returns the quotient of a division B. TRUNC: can be used with number and date values C. CONCAT: can be used to combine any number of values D. SYSDATE: returns the database server current date and time E. INSTR: can be used to find only the first occurrence of a character in a string F. TRIM: can be used to remove all the occurrences of a character from a string 1. A,C 2. A,B 3. D,E 4. B,F 5. B,D
Correct Answer : 5 Explanation: ROUND: Rounds value to a specified decimal TRUNC: Truncates value to a specified decimal , MOD: Returns remainder of division , SYSDATE is a date function that returns the current database server date and time. Date-Manipulation Functions : Date functions operate on Oracle dates. All date functions return a value of the DATE data type except MONTHS_BETWEEN, which returns a numeric value. 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. ADD_MONTHS(date, n): Adds n number of calendar months to date. The value of n must be an integer and can be negative. NEXT_DAY(date, 'char'): Finds the date of the next specified day of the week ('char') following date. The value of char may be a number representing a day or a character string. LAST_DAY(date): Finds the date of the last day of the month that contains date The above list is a subset of the available date functions. ROUND and TRUNC number functions can also be used to manipulate the date values as shown below: ROUND(date[, 'fmt']): Returns date rounded to the unit that is specified by the format model fmt. If the format model fmt is omitted, date is rounded to the nearest day. TRUNC(date[, 'fmt']): Returns date with the time portion of the day truncated to the unit that is specified by the format model fmt. If the format model fmt is omitted, date is truncated to the nearest day. The CONCAT Function : The CONCAT function joins two character literals, columns, or expressions to yield one larger character expression. Numeric and date literals are implicitly cast as characters when they occur as parameters to the CONCAT function. Numeric or date expressions are evaluated before being converted to strings ready to be concatenated. The CONCAT function takes two parameters. Its syntax is CONCAT(s1, s2), where s1 and s2 represent string literals, character column values, or expressions resulting in character values. The INSTR(source string, search item, [start position], [nth occurrence of search item]) function returns a number that represents the position in the source string, beginning from the given start position, where the nth occurrence of the search item begins: instr('http://www.domain.com', '.', 1, 2) = 18 The TRIM function literally trims off leading or trailing (or both) character strings from a given source string
Question : Which two statements are true regarding the count function? A. The count function can be used only for CHAR, VARCHAR2, and NUMBER data types. B. Count (*) returns the number of rows including duplicate rows and rows containing null value in any of the columns. C. Count (cust_id) returns the number of rows including rows with duplicate customer IDs and NULL value in the CUST_ID column. D. Count (distinct inv_amt) returns the number of rows excluding rows containing duplicates and NULL values in the INV_AMT column. E. A select statement using the COUNT function with a DISTINCT keyword cannot have a where clause. 1. A,C 2. A,B 3. D,E 4. B,E 5. B,D
Correct Answer : 5 Explanation: Using the COUNT Function The COUNT function has three formats: COUNT(*) COUNT(expr) COUNT(DISTINCT expr) COUNT(*) 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.
1. TO_CHAR may convert date items to character items. 2. TO_DATE may convert character items to date items. 3. TO_CHAR may convert numbers to character items. 4. TO_DATE may convert date items to character items.