databases Online Quiz - 99
Description: databases Online Quiz - 99 | |
Number of Questions: 20 | |
Created by: Aliensbrain Bot | |
Tags: databases |
Select invalid variable types
-
VARCHAR2
-
VARCHAR1
-
CHAR
-
CHAR2
-
INTEGER
-
NUMBER
SELECT ROUND (-123.39953,-2) FROM DUAL;
-
-123.40
-
-100
-
-120
-
-123.30
SELECT ROUND(-123.39953,-3) FROM DUAL;
-
0
-
100
-
123
-
-123
AI Explanation
To answer this question, we need to understand the ROUND function in SQL.
The ROUND function is used to round a number to a specified number of decimal places or to the nearest whole number. It takes two arguments: the number to be rounded and the number of decimal places to round to.
In this case, the number to be rounded is -123.39953 and the number of decimal places to round to is -3.
When rounding to -3 decimal places, we are rounding to the nearest thousands place.
The correct answer is A) 0.
This is because -123.39953, when rounded to the nearest thousands place, becomes 0.
SELECT CONCAT(SUBSTR('MINDWORKS',-5,6),SUBSTR('KNOWMAX',-3,4)) FROM DUAL;
-
KNOWMIND
-
WORKSM
-
WORKSMAX
-
MAXWORKS
AI Explanation
To answer this question, let's break down the query step by step:
The given query is:
SELECT CONCAT(SUBSTR('MINDWORKS',-5,6),SUBSTR('KNOWMAX',-3,4)) FROM DUAL;
SUBSTR('MINDWORKS',-5,6)
:- This function extracts a substring from the string 'MINDWORKS'.
- The starting point (-5) specifies that the substring should start from the 5th character from the end of the string.
- The length (6) specifies that the substring should have a length of 6 characters.
- Therefore, this expression returns 'WORKS'.
SUBSTR('KNOWMAX',-3,4)
:- This function extracts a substring from the string 'KNOWMAX'.
- The starting point (-3) specifies that the substring should start from the 3rd character from the end of the string.
- The length (4) specifies that the substring should have a length of 4 characters.
- Therefore, this expression returns 'MAX'.
CONCAT(SUBSTR('MINDWORKS',-5,6),SUBSTR('KNOWMAX',-3,4))
:- This function concatenates the two substrings obtained from the previous steps.
- The result of the concatenation is 'WORKSMAX'.
Therefore, the correct answer is option C) WORKSMAX.
SELECT DECODE('MINDWORKS','WORKS','MINDWORK','KNOWMAX') FROM DUAL;
-
KNOWMAX
-
MINDWORKS
-
WORKS
-
MINDWORK
How many columns are presented after executing this query: SELECT address1||','||address2||','||address2 "Adress" FROM employee;
-
1
-
2
-
3
-
0
-
4
AI Explanation
To determine the number of columns presented after executing the given query, let's break down the query and analyze it step by step:
The query is: SELECT address1||','||address2||','||address2 "Adress" FROM employee;
Here, we are selecting three columns: address1, address2, and address2 (renamed as "Address" using the alias "Adress"). Each column is concatenated with a comma (',').
So, the query will produce three columns: address1, address2, and Address.
Therefore, the correct answer is C) 3.
Which Oracle access method is the fastest way for Oracle to retrieve a single row?
-
Primary key access
-
Access via unique index
-
Table access by ROWID
-
Full table scan
AI Explanation
To answer this question, let's go through each option to understand why it is correct or incorrect:
Option A) Primary key access - This option involves accessing a table using the primary key. While primary key access can be efficient for retrieving a single row, it is not always the fastest method as it depends on the table's structure and data distribution.
Option B) Access via unique index - This option involves accessing a table using a unique index. Accessing a table via a unique index can be efficient for retrieving a single row. However, it may not always be the fastest method compared to other options.
Option C) Table access by ROWID - This option involves accessing a table directly using the ROWID. The ROWID is a unique identifier for each row in a table and allows for direct access to the desired row. This method is typically the fastest way to retrieve a single row as it bypasses index lookups.
Option D) Full table scan - This option involves scanning the entire table to find the desired row. This method is generally slower compared to other options, especially when retrieving a single row.
The correct answer is C) Table access by ROWID. This option is correct because it allows for direct access to the desired row, making it the fastest way for Oracle to retrieve a single row.
You need to modify the STUDENTS table to add a primary key on the STUDENT_ID column. The table is currently empty. Which statement accomplishes this task?
-
ALTER TABLE students ADD PRIMARY KEY student_id;
-
ALTER TABLE students ADD CONSTRAINT PRIMARY KEY (student_id);
-
ALTER TABLE students ADD CONSTRAINT stud_id_pk PRIMARY KEY student_id;
-
ALTER TABLE students ADD CONSTRAINT stud_id_pk PRIMARY KEY (student_id);
-
ALTER TABLE students MODIFY CONSTRAINT stud_id_pk PRIMARY KEY (student_id);
AI Explanation
To add a primary key on the STUDENT_ID column in the STUDENTS table, you can use the following statement:
D. ALTER TABLE students ADD CONSTRAINT stud_id_pk PRIMARY KEY (student_id);
Explanation for each option:
A. ALTER TABLE students ADD PRIMARY KEY student_id; This option is incorrect because it is missing the CONSTRAINT keyword before PRIMARY KEY.
B. ALTER TABLE students ADD CONSTRAINT PRIMARY KEY (student_id); This option is incorrect because it is missing a name for the constraint. A constraint must have a unique name.
C. ALTER TABLE students ADD CONSTRAINT stud_id_pk PRIMARY KEY student_id; This option is incorrect because it is missing parentheses around the column name student_id.
D. ALTER TABLE students ADD CONSTRAINT stud_id_pk PRIMARY KEY (student_id); This option is correct because it uses the correct syntax to add a constraint with a name (stud_id_pk) on the column student_id as the primary key.
E. ALTER TABLE students MODIFY CONSTRAINT stud_id_pk PRIMARY KEY (student_id); This option is incorrect because MODIFY CONSTRAINT is used to modify an existing constraint, not to add a new constraint.
The correct answer is D. ALTER TABLE students ADD CONSTRAINT stud_id_pk PRIMARY KEY (student_id). This option is correct because it adds a primary key constraint with the name stud_id_pk on the column student_id in the STUDENTS table.
-
TIMESTAMP
-
INTERVAL MONTH TO DAY
-
INTERVAL DAY TO SECOND
-
INTERVAL YEAR TO MONTH
-
TIMESTAMP WITH DATABASE TIMEZONE
Evaluate the set of SQL statements: CREATE TABLE dept (deptno NUMBER(2), dname VARCNAR2(14), loc VARCNAR2(13)); ROLLBACK; DESCRIBE DEPT What is true about the set?
-
The DESCRIBE DEPT statement displays the structure of the DEPT table.
-
The ROLLBACK statement frees the storage space occupies by the DEPT table.
-
The DESCRIBE DEPT statement returns an error ORA-04043: object DEPT does not exist.
-
The DESCRIBE DEPT statement displays the structure of the DEPT table only if there is a COMMIT statement introduced before the ROLLBACK statement.
AI Explanation
To answer this question, let's go through each option to understand why it is correct or incorrect:
Option A) The DESCRIBE DEPT statement displays the structure of the DEPT table. This option is correct because the DESCRIBE statement is used to display the structure of a table, and in this case, it will display the structure of the DEPT table.
Option B) The ROLLBACK statement frees the storage space occupied by the DEPT table. This option is incorrect. The ROLLBACK statement is used to undo transactions and restore the database to the state it was in before the transaction was initiated. It does not free the storage space occupied by the table.
Option C) The DESCRIBE DEPT statement returns an error ORA-04043: object DEPT does not exist. This option is incorrect. Since the CREATE TABLE statement is executed before the DESCRIBE statement, the DEPT table will exist, and the DESCRIBE statement will be able to display its structure.
Option D) The DESCRIBE DEPT statement displays the structure of the DEPT table only if there is a COMMIT statement introduced before the ROLLBACK statement. This option is incorrect. The DESCRIBE statement does not depend on the presence of a COMMIT statement before the ROLLBACK statement. It will display the structure of the DEPT table regardless of whether a COMMIT statement was used or not.
The correct answer is A. The DESCRIBE DEPT statement displays the structure of the DEPT table.
Which data dictionary table should you query to view the object privileges granted to the user on specific columns?
-
USER_TAB_PRIVS_MADE
-
USER_TAB_PRIVS
-
USER_COL_PRIVS_MADE
-
USER_COL_PRIVS
AI Explanation
To view the object privileges granted to the user on specific columns, you should query the USER_COL_PRIVS data dictionary table.
Let's go through each option to understand why it is correct or incorrect:
Option A) USER_TAB_PRIVS_MADE - This option is incorrect because the USER_TAB_PRIVS_MADE table provides information about the object privileges the user has granted to other users, not the privileges granted to the user on specific columns.
Option B) USER_TAB_PRIVS - This option is incorrect because the USER_TAB_PRIVS table provides information about the object privileges granted to the user on tables, not specific columns.
Option C) USER_COL_PRIVS_MADE - This option is incorrect because the USER_COL_PRIVS_MADE table provides information about the column privileges the user has granted to other users, not the privileges granted to the user on specific columns.
Option D) USER_COL_PRIVS - This option is correct because the USER_COL_PRIVS table provides information about the column privileges granted to the user, including the privileges granted on specific columns of tables.
The correct answer is D. This option is correct because querying the USER_COL_PRIVS table allows you to view the object privileges granted to the user on specific columns.
The EMP table contains these columns: LAST NAME VARCHAR2(25) SALARY NUMBER(6,2) DEPARTMENT_ID NUMBER(6) You need to display the employees who have not been assigned to any department. You write the SELECT statement: SELECT LAST_NAME, SALARY, DEPARTMENT_ID FROM EMP WHERE DEPARTMENT_ID = NULL; What is true about this SQL statement?
-
The SQL statement displays the desired results.
-
The column in the WHERE clause should be changed to display the desired results.
-
The operator in the WHERE clause should be changed to display the desired results.
-
The WHERE clause should be changed to use an outer join to display the desired results.
AI Explanation
To answer this question, let's analyze the given SQL statement:
SELECT LAST_NAME, SALARY, DEPARTMENT_ID FROM EMP WHERE DEPARTMENT_ID = NULL;
The statement is attempting to display the employees who have not been assigned to any department. However, the statement is incorrect.
The correct comparison operator to check for a null value is not the equality operator (=), but rather the "IS NULL" operator. Therefore, option C is correct:
C. The operator in the WHERE clause should be changed to display the desired results.
The correct SQL statement should be:
SELECT LAST_NAME, SALARY, DEPARTMENT_ID FROM EMP WHERE DEPARTMENT_ID IS NULL;
-
0
-
1
-
0.00
-
An error statement
To evaluate the SQL statement, we need to understand the functions ROUND, TRUNC and MOD.
ROUND: rounds a number to a specified number of decimal places. If the second argument is negative, it rounds to the left of the decimal point. For example, ROUND(123.456, 2) = 123.46, ROUND(123.456, -1) = 120. TRUNC: truncates a number to a specified number of decimal places. If the second argument is negative, it truncates to the left of the decimal point. For example, TRUNC(123.456, 2) = 123.45, TRUNC(123.456, -1) = 120. MOD: returns the remainder of a division operation. For example, MOD(7, 3) = 1, MOD(1600, 10) = 0. Using these functions, we can evaluate the SQL statement step by step:
MOD(1600,10) returns 0, since there is no remainder when dividing 1600 by 10. TRUNC(0,-1) returns 0, since there is nothing to truncate to the left of the decimal point. ROUND(0,2) returns 0, since there is nothing to round to the right of the decimal point. Therefore, the final result displayed by the SQL statement is 0.
-
NOT NULL
-
PRIMARY KEY
-
FOREIGN KEY
-
CHECK
-
UNIQUE KEY
-
You can use aggregate functions in any clause of a SELECT statement.
-
You can use aggregate functions only in the column list of the SELECT clause and in the WHERE clause of a SELECT statement.
-
You can mix single row columns with aggregate functions in the column list of a SELECT statement by grouping on the single row columns.
-
You can pass column names, expressions, constants, or functions as parameters to an aggregate function.
-
You can use aggregate functions on a table, only by grouping the whole table as one single group.
-
You cannot group the rows of a table by more than one column while using aggregate functions.
Which two statements about subqueries are true? (Choose two.)
-
A single row subquery can retrieve data from only one table.
-
A SQL query statement cannot display data from table B that is referred to in its subquery, unless table B is included in the main query's FROM clause.
-
A SQL query statement can display data from table B that is referred to in its subquery, without including table B in its own FROM clause.
-
A single row subquery can retrieve data from more than one table.
-
A single row subquery cannot be used in a condition where the LIKE operator is used for comparison.
-
A multiple-row subquery cannot be used in a condition where the LIKE operator is used for comparison.
AI Explanation
To answer this question, we need to understand the concept of subqueries.
A subquery is a query that is nested within another query. It is used to retrieve data from one or more tables and is enclosed within parentheses.
Let's go through each option to understand which are true about subqueries:
Option A) A single row subquery can retrieve data from only one table. This statement is false. A single row subquery can retrieve data from multiple tables as long as they are related through a common column.
Option B) A SQL query statement cannot display data from table B that is referred to in its subquery unless table B is included in the main query's FROM clause. This statement is true. When a subquery references a table, that table must be included in the main query's FROM clause for the data to be displayed.
Option C) A SQL query statement can display data from table B that is referred to in its subquery without including table B in its own FROM clause. This statement is false. To display data from table B that is referred to in a subquery, table B must be included in the main query's FROM clause.
Option D) A single row subquery can retrieve data from more than one table. This statement is true. A single row subquery can retrieve data from multiple tables if they are related through a common column.
Option E) A single row subquery cannot be used in a condition where the LIKE operator is used for comparison. This statement is false. A single row subquery can be used in a condition where the LIKE operator is used for comparison.
Option F) A multiple-row subquery cannot be used in a condition where the LIKE operator is used for comparison. This statement is false. A multiple-row subquery can be used in a condition where the LIKE operator is used for comparison.
Based on the explanations above, the two true statements about subqueries are:
B. A SQL query statement cannot display data from table B that is referred to in its subquery unless table B is included in the main query's FROM clause. D. A single row subquery can retrieve data from more than one table.
Therefore, the correct answer is B and D.
You added a PHONE_NUMBER column of NUMBER data type to an existing EMPLOYEES table. The EMPLOYEES table already contains records of 100 employees. Now, you want to enter the phone numbers of each of the 100 employees into the table. Some of the employees may not have a phone number available. Which data manipulation operation do you perform?
-
MERGE
-
INSERT
-
UPDATE
-
ADD
-
ENTER
-
You cannot enter the phone numbers for the existing employee records.
AI Explanation
To enter the phone numbers of each of the 100 employees into the existing EMPLOYEES table, the appropriate data manipulation operation to perform is the INSERT operation.
Option A) MERGE - The MERGE operation is used to update or insert data into a target table based on a condition. It is not necessary in this scenario since we are only inserting data.
Option B) INSERT - This option is correct. The INSERT operation is used to add new rows of data into a table. In this case, we are adding the phone numbers of each employee into the table.
Option C) UPDATE - The UPDATE operation is used to modify existing data in a table. It is not necessary in this scenario since we are not modifying existing data, but rather adding new data.
Option D) ADD - The ADD operation is used to add new columns to an existing table. It is not necessary in this scenario since we are not adding a new column, but rather adding data to an existing column.
Option E) ENTER - This option is not a valid data manipulation operation in SQL. It is not applicable in this scenario.
Option F) You cannot enter the phone numbers for the existing employee records - This option is incorrect. It is possible to enter the phone numbers for the existing employee records by performing the INSERT operation.
Therefore, the correct answer is B) INSERT.
In which case would you use a FULL OUTER JOIN?
-
Both tables have NULL values.
-
You want all unmatched data from one table.
-
You want all matched data from both tables.
-
You want all unmatched data from both tables.
-
One of the tables has more data than the other.
-
You want all matched and unmatched data from only one table.
To answer this question, the user must know the different types of joins in SQL.
- INNER JOIN: returns only matched data from both tables.
- LEFT OUTER JOIN: returns all data from the left table and matched data from the right table.
- RIGHT OUTER JOIN: returns all data from the right table and matched data from the left table.
- FULL OUTER JOIN: returns all matched and unmatched data from both tables.
Now, let's go through each option and determine whether it is a valid case to use a FULL OUTER JOIN:
A. Both tables have NULL values.
- This option is not a determining factor in deciding to use a FULL OUTER JOIN.
B. You want all unmatched data from one table.
- This option does not require a FULL OUTER JOIN, as a LEFT OUTER JOIN or RIGHT OUTER JOIN would suffice depending on which table has the unmatched data.
C. You want all matched data from both tables.
- This option requires an INNER JOIN, not a FULL OUTER JOIN.
D. You want all unmatched data from both tables.
- This option requires a FULL OUTER JOIN, as it returns all matched and unmatched data from both tables.
E. One of the tables has more data than the other.
- This option does not necessarily require a FULL OUTER JOIN, as a LEFT OUTER JOIN or RIGHT OUTER JOIN could also be used depending on which table has more data.
F. You want all matched and unmatched data from only one table.
- This option does not require a FULL OUTER JOIN, as a LEFT OUTER JOIN or RIGHT OUTER JOIN could be used depending on which table has the data.
Therefore, the correct answer is:
The Answer is: D
Which two statements accurately describe a role? (Choose two.)
-
A role can be given to a maximum of 1000 users.
-
A user can have access to a maximum of 10 roles.
-
A role can have a maximum of 100 privileges contained in it.
-
Privileges are given to a role by using the CREATE ROLE statement.
-
A role is a named group of related privileges that can be granted to the user.
-
A user can have access to several roles, and several users can be assigned the same role.
AI Explanation
To answer this question, you need to understand the concept of roles and their characteristics. Let's go through each option to understand why it is correct or incorrect:
Option A) A role can be given to a maximum of 1000 users. - This statement is not accurate. A role can be assigned to any number of users, so there is no maximum limit.
Option B) A user can have access to a maximum of 10 roles. - This statement is not accurate. A user can have access to any number of roles, so there is no maximum limit.
Option C) A role can have a maximum of 100 privileges contained in it. - This statement is not accurate. A role can contain any number of privileges, so there is no maximum limit.
Option D) Privileges are given to a role by using the CREATE ROLE statement. - This statement is accurate. Privileges can be assigned to a role using the CREATE ROLE statement in SQL.
Option E) A role is a named group of related privileges that can be granted to the user. - This statement is partially accurate. A role is indeed a named group of related privileges, but it is granted to the user, not the other way around.
Option F) A user can have access to several roles, and several users can be assigned the same role. - This statement is accurate. A user can have access to multiple roles, and multiple users can be assigned the same role.
The correct answers are Option D and Option F. These statements accurately describe a role.
What is necessary for your query on an existing view to execute successfully?
-
The underlying tables must have data.
-
You need SELECT privileges on the view.
-
The underlying tables must be in the same schema.
-
You need SELECT privileges only on the underlying tables.
AI Explanation
To answer this question, you need to understand the concept of views in databases.
A view is a virtual table that is based on the result of a query. It does not store any data itself but instead retrieves data from the underlying tables whenever it is accessed.
Now let's go through each option to understand why it is correct or incorrect:
Option A) The underlying tables must have data - This option is incorrect because a view can still be executed successfully even if the underlying tables do not have data. The view will return an empty result set in such cases.
Option B) You need SELECT privileges on the view - This option is incorrect because having SELECT privileges on the view alone is not sufficient for the query to execute successfully. You also need SELECT privileges on the underlying tables from which the view is derived.
Option C) The underlying tables must be in the same schema - This option is incorrect because the underlying tables can be in different schemas and the view can still be executed successfully. The schema of the view itself is what matters.
Option D) You need SELECT privileges only on the underlying tables - This option is correct. In order to execute a query on an existing view successfully, you need to have SELECT privileges on the underlying tables from which the view is derived. This is because the view retrieves data from these tables when it is accessed.
The correct answer is D) You need SELECT privileges only on the underlying tables. This option is correct because having SELECT privileges on the underlying tables is necessary for the query on the view to execute successfully.