Tag: databases

Questions Related to databases

  1. A role can be given to a maximum of 1000 users.

  2. A user can have access to a maximum of 10 roles.

  3. A role can have a maximum of 100 privileges contained in it.

  4. Privileges are given to a role by using the CREATE ROLE statement.

  5. A role is a named group of related privileges that can be granted to the user.

  6. A user can have access to several roles, and several users can be assigned the same role.


Correct Option: D,F

What is necessary for your query on an existing view to execute successfully?

  1. The underlying tables must have data.

  2. You need SELECT privileges on the view.

  3. The underlying tables must be in the same schema.

  4. You need SELECT privileges only on the underlying tables.


Correct Option: D

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.

Evaluate these two SQL statements: SELECT last_name, salary , hire_date FROM EMPLOYEES ORDER BY salary DESC; SELECT last_name, salary, hire_date FROM EMPLOYEES ORDER BY 2 DESC;

  1. The two statements produce identical results.

  2. The second statement returns a syntax error.

  3. There is no need to specify DESC because the results are sorted in descending order by default.

  4. The two statements can be made to produce identical results by adding a column alias for the salary column in the second SQL statement.


Correct Option: A
Explanation:

To solve this question, the user needs to understand the SQL SELECT statement and the ORDER BY clause. The ORDER BY clause is used to sort the result set in ascending or descending order based on one or more columns.

Now, let's go through each option and explain why it is right or wrong:

A. The two statements produce identical results. This option is correct. Both SQL statements select the same columns from the same table, and they both sort the results by the salary column in descending order. The syntax used to specify the column to sort by is different (column name vs. column position), but they are functionally equivalent.

B. The second statement returns a syntax error. This option is incorrect. The second SQL statement is also valid syntax and should execute without errors.

C. There is no need to specify DESC because the results are sorted in descending order by default. This option is incorrect. The ORDER BY clause sorts the result set in ascending order by default. If you want to sort in descending order, you need to explicitly specify the DESC keyword.

D. The two statements can be made to produce identical results by adding a column alias for the salary column in the second SQL statement. This option is incorrect. The column alias does not affect the sorting behavior of the ORDER BY clause. It only changes the name of the column in the result set.

Therefore, the correct answer is:

The Answer is: A

You would like to display the system date in the format "Monday, 01 June, 2001". Which SELECT statement should you use?

  1. SELECT TO_DATE(SYSDATE, 'FMDAY, DD Month, YYYY') FROM dual;

  2. SELECT TO_CHAR(SYSDATE, 'FMDD, DY Month, 'YYY') FROM dual;

  3. SELECT TO_CHAR(SYSDATE, 'FMDay, DD Month, YYYY') FROM dual;

  4. SELECT TO_CHAR(SYSDATE, 'FMDY, DDD Month, YYYY') FROM dual;

  5. SELECT TO_DATE(SYSDATE, 'FMDY, DDD Month, YYYY') FROM dual;


Correct Option: C

AI Explanation

To display the system date in the format "Monday, 01 June, 2001", you can use the TO_CHAR function in Oracle SQL. Let's go through each option to understand why it is correct or incorrect:

Option A) SELECT TO_DATE(SYSDATE, 'FMDAY, DD Month, YYYY') FROM dual; This option is incorrect because the TO_DATE function is used to convert a string to a date. However, SYSDATE is already a date, so there is no need to convert it. Additionally, the format mask 'FMDAY' is not valid for the TO_DATE function.

Option B) SELECT TO_CHAR(SYSDATE, 'FMDD, DY Month, 'YYY') FROM dual; This option is incorrect because the format mask 'YYY' is missing a closing single quote. It should be 'YYYY'. Additionally, the format mask 'DY' is used to display the abbreviated name of the day, not the full name.

Option C) SELECT TO_CHAR(SYSDATE, 'FMDay, DD Month, YYYY') FROM dual; This option is correct because it uses the TO_CHAR function to convert the system date (SYSDATE) to a string in the desired format. The format mask 'FMDay' is used to display the full name of the day, 'DD' is used to display the day of the month, 'Month' is used to display the full name of the month, and 'YYYY' is used to display the four-digit year.

Option D) SELECT TO_CHAR(SYSDATE, 'FMDY, DDD Month, YYYY') FROM dual; This option is incorrect because the format mask 'FMDY' is not valid. It should be 'DY' to display the abbreviated name of the day.

Option E) SELECT TO_DATE(SYSDATE, 'FMDY, DDD Month, YYYY') FROM dual; This option is incorrect because it uses the TO_DATE function to convert SYSDATE to a date, but SYSDATE is already a date. Additionally, the format mask 'FMDY' is not valid for the TO_DATE function.

The correct answer is option C. This option is correct because it uses the TO_CHAR function with the correct format mask to convert the system date to a string in the desired format.

  1. SELECT SUBSTR( ‘Hello World’,1) FROM dual;

  2. SELECT INITCAP(TRIM (‘Hello World’, 1,1)) FROM dual;

  3. SELECT LOWER(SUBSTR(‘Hello World’, 1, 1) FROM dual;

  4. SELECT LOWER(SUBSTR(‘Hello World’, 2, 1) FROM dual;

  5. SELECT LOWER(TRIM (‘H’ FROM ‘Hello World’)) FROM dual;


Correct Option: E

Evaluate this SQL statement: SELECT e.employee_id, (.15* e.salary) + (.5 * e.commission_pct) + (s.sales amount * (.35 * e.bonus)) AS CALC_VALUE FROM employees e, sales s WHERE e.employee_id = s.emp_id; What will happen if you remove all the parentheses from the calculation?

  1. The value displayed in the CALC_VALUE column will be lower.

  2. The value displayed in the CALC_VALUE column will be higher.

  3. There will be no difference in the value displayed in the CALC_VALUE column.

  4. An error will be reported.


Correct Option: C

AI Explanation

To evaluate the SQL statement and understand the impact of removing parentheses from the calculation, let's break down the statement and analyze each part:

The SQL statement is as follows:

SELECT e.employee_id, (.15 * e.salary) + (.5 * e.commission_pct) + (s.sales_amount * (.35 * e.bonus)) AS CALC_VALUE
FROM employees e, sales s
WHERE e.employee_id = s.emp_id;

The statement selects the employee ID (e.employee_id) and calculates the value in the CALC_VALUE column. The calculation involves multiple mathematical operations, including multiplication and addition.

If we remove all the parentheses from the calculation, the statement would look like this:

SELECT e.employee_id, .15 * e.salary + .5 * e.commission_pct + s.sales_amount * .35 * e.bonus AS CALC_VALUE
FROM employees e, sales s
WHERE e.employee_id = s.emp_id;

Now, let's compare both versions of the SQL statement.

The original version of the statement uses parentheses to group certain parts of the calculation, which ensures that these parts are evaluated together before performing the addition operation. Removing the parentheses means that the calculation will be evaluated based on the order of operations (PEMDAS/BODMAS), where multiplication is performed before addition.

However, since the multiplication and addition operations are being performed on constants and column values, the order of operations does not affect the final result. The multiplication and addition operations are commutative, which means the order in which they are performed does not change the result.

Therefore, removing the parentheses from the calculation will not make any difference in the value displayed in the CALC_VALUE column. Hence, the correct answer is C) There will be no difference in the value displayed in the CALC_VALUE column.

From SQL*Plus, you issue this SELECT statement: SELECT* From orders; You use this statement to retrieve data from a data table for __________. (Choose all that apply)

  1. Updating

  2. Viewing

  3. Deleting

  4. Inserting

  5. Truncating


Correct Option: B,D

AI Explanation

To answer this question, you need to understand the purpose of the SELECT statement in SQL*Plus. Let's go through each option to understand why it is correct or incorrect:

Option A) Updating - The SELECT statement is not used for updating data in a table. It is used to retrieve data from a table, so this option is incorrect.

Option B) Viewing - The SELECT statement is used to retrieve and view data from a table. When you issue the SELECT statement "SELECT * FROM orders;", you are retrieving and viewing the data from the "orders" table. Therefore, this option is correct.

Option C) Deleting - The SELECT statement is not used for deleting data from a table. It is used to retrieve data, not delete it. So this option is incorrect.

Option D) Inserting - The SELECT statement is not used for inserting data into a table. It is used to retrieve data, not insert it. So this option is incorrect.

Option E) Truncating - The SELECT statement is not used for truncating a table. Truncating is a separate command in SQL that is used to remove all data from a table. So this option is incorrect.

The correct answers are B) Viewing and D) Inserting. The SELECT statement is used to retrieve and view data from a table, and it can also be used to insert data into another table using the INSERT INTO statement.

Which two are attributes of /SQL*Plus? (Choose two)

  1. /SQL*Plus commands cannot be abbreviated.

  2. /SQL*Plus commands are accesses from a browser.

  3. /SQL*Plus commands are used to manipulate data in tables.

  4. /SQL*Plus commands manipulate table definitions in the database.

  5. /SQL*Plus is the Oracle proprietary interface for executing SQL statements.


Correct Option: C,D

AI Explanation

To answer this question, let's go through each option and determine if it is an attribute of SQL*Plus:

Option A) SQL*Plus commands cannot be abbreviated. - This option is incorrect. SQL*Plus commands can be abbreviated using shortcuts or aliases to make them easier to type and execute.

Option B) SQL*Plus commands are accessed from a browser. - This option is incorrect. SQL*Plus is a command-line interface and is not accessed through a browser.

Option C) SQL*Plus commands are used to manipulate data in tables. - This option is correct. SQL*Plus commands can be used to insert, update, delete, and select data from tables.

Option D) SQL*Plus commands manipulate table definitions in the database. - This option is correct. SQL*Plus commands can be used to create, alter, and drop tables, as well as define constraints and indexes.

Option E) SQL*Plus is the Oracle proprietary interface for executing SQL statements. - This option is incorrect. While SQL*Plus is a proprietary interface for Oracle, it is not limited to executing SQL statements only. It can also be used for formatting reports, running scripts, and performing administrative tasks.

Therefore, the correct attributes of SQL*Plus are options C and D.

  1. The indexed column is declared as NOT NULL.

  2. The indexed columns are used in the FROM clause.

  3. The indexed columns are part of an expression.

  4. The indexed column contains a wide range of values.


Correct Option: D

Which clause would you use in a SELECT statement to limit the display to those employees whose salary is greater then 5000?

  1. ORDER BY SALARY > 5000

  2. GROUP BY SALARY > 5000

  3. HAVING SALARY > 5000

  4. WHERE SALARY > 5000


Correct Option: D