Computer Knowledge

Database and SQL

4,213 Questions

Master structured query language commands, database joins, table constraints, and alias generation. This section covers relational database management concepts and query outputs essential for technical aptitude. These technical questions feature prominently in banking IT officer exams and computer knowledge sections.

SQL queries and aliasesDatabase table constraintsDatabase joins and transformationsStored procedures and functions

Database and SQL Questions

Multiple choice technology databases
  1. SELECT TO_CHAR(2000, '$#,###.##') from dual
  2. SELECT TO_CHAR(2000, '$0,000.00') from dual
  3. SELECT TO_CHAR(2000, '$9,999.00') from dual
  4. SELECT TO_CHAR(2000, '$9,999.99') from dual
  5. SELECT TO_CHAR(2000, '$2,000.00') FROM dual;
  6. SELECT TO_CHAR(2000, '$N,NNN.NN') FROM dual;
Reveal answer Fill a bubble to check yourself
B,C,D Correct answer
Explanation

In Oracle TO_CHAR, format codes control number display: '0' forces a digit (shows 0 if absent), '9' is optional (shows space if absent), and ',' inserts thousand separators. Options B, C, and D all produce "$2,000.00" for input 2000: B uses mandatory digits for exact formatting, while C and D use optional digits that still render correctly since the value has digits in those positions. Option A would fail because '$#,###.##' omits trailing zeros, showing "$2,000" instead of "$2,000.00". Option E treats the format string literally, and Option F uses invalid format symbols.

Multiple choice technology programming languages
  1. a) By using the insert="false" and update="false" attributes.

  2. b) By using the isinsert="false" and isupdate="false" attributes.

  3. c) By using the isinsert="no" and isupdate="no" attributes

  4. d) None

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

In Hibernate, making a property read-only from the application side (while still loading it from the database) is achieved by setting insert="false" and update="false" in the mapping XML or annotations. This tells Hibernate to retrieve the property value when loading objects but never include it in INSERT or UPDATE statements. Option A correctly states this. Options B and C use incorrect attribute names (should be 'insert' and 'update', not 'isinsert' and 'isupdate'), making them invalid.

Multiple choice technology databases
  1. It returns a single result row based on single rows

  2. It returns a single result row based on groups of rows

  3. It can only appear in ORDER BY clauses

  4. It cannot appear in select lists

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Aggregate functions (SUM, COUNT, AVG, MAX, MIN) operate on groups of rows and return a single result row per group. When used without a GROUP BY clause, they treat all rows as one group and return one result row. When used with GROUP BY, they return one row per unique group. Option B correctly captures this behavior. Option A is wrong because aggregates work on sets of rows, not single rows. Options C and D are incorrect because aggregates appear in SELECT lists, HAVING, and ORDER BY (with restrictions), not just ORDER BY.

Multiple choice technology databases
  1. SELECT ABS(-33) "Absolute" FROM DUAL;

  2. SELECT ABS(-33), Absolute FROM DUAL;

  3. SELECT ABS("-33") Absolute FROM DUAL;

  4. None of these

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

To solve this question, the user needs to know the syntax for calculating the absolute value in SQL. The ABS function can be used to calculate the absolute value of a number.

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

A. SELECT ABS(-33) "Absolute" FROM DUAL; This option is correct. The ABS function is used to calculate the absolute value of a number, and the syntax in this statement is correct. The "Absolute" alias is used to rename the column with the calculated value.

B. SELECT ABS(-33), Absolute FROM DUAL; This option is incorrect. The "Absolute" alias is not defined in the statement. Additionally, the ABS function is used correctly.

C. SELECT ABS("-33") Absolute FROM DUAL; This option is incorrect. The quotation marks around the number indicate that it is a string, not a number. The ABS function cannot calculate the absolute value of a string.

D. None of these This option is incorrect. Option A is the correct answer.

The Answer is: A

Multiple choice technology programming languages
  1. a) Session.load();

  2. b) Session.get();

  3. c) Session.fetch();

  4. d) None of the above

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Session.get() is the better choice when you're uncertain whether a row exists. The get() method returns null if no matching row is found, allowing you to handle the absence gracefully. In contrast, Session.load() assumes the row exists and throws an ObjectNotFoundException if it doesn't, which would cause an uncaught exception in your code. Option B is correct. Options C and D are incorrect because there's no Session.fetch() method in standard Hibernate, and load() would cause an exception.

Multiple choice technology programming languages
  1. a) bag has index column

  2. b) bag permits duplicate element values

  3. c) bag does not permits duplicate element values

  4. d) None

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

To solve this question, the user needs to have knowledge about the concept of a bag data structure. A bag is a collection of unordered elements that may contain duplicates.

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

a) bag has index column: This statement is incorrect. A bag is an unordered collection, which means it does not have an index column. Items in a bag are stored in any order.

b) bag permits duplicate element values: This statement is correct. A bag allows duplicate elements to be added to it. For example, a bag can contain two or more items with the same value.

c) bag does not permit duplicate element values: This statement is incorrect. A bag permits duplicate elements to be added to it. Therefore, this statement is false.

d) None: This option is incorrect because option B is correct.

The Answer is: B

Multiple choice technology databases
  1. it has a syntax error, the AVG clause is not valid

  2. it calculates the average of the maximum salaries of all the departments

  3. it has a syntax error, the MAX clause is not valid

  4. it has no error, but the GROUP BY clause is not effective

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

GROUP BY divides employees by department first. MAX(salary) finds each department's highest salary. AVG then averages those departmental maximums into a single value representing the mean of top salaries across departments.

Multiple choice technology mainframe
  1. Sum up value in the fields specified in the SORT FIELDS statement and keep it as only one occurence in the o/p

  2. Removes the duplicates for the fields specified in the SORT FIELDS statement and keeps only the 1st occurence of it

  3. Works only for those records in the i/p file where no duplicates for the fields specified in SORT FIELDS statement,

  4. None of the above

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

SUM FIELDS = NONE removes duplicates by keeping only the first occurrence of records with matching sort keys. Despite the name 'SUM', it doesn't perform arithmetic summation when =NONE is specified - it deduplicates. The matching fields are those in SORT FIELDS statement.

Multiple choice technology databases
  1. a) DELCARE and BEGIN

  2. b) DECALRE and EXCEPTION

  3. c) EXCEPTION and END

  4. d) BEGIN and END

Reveal answer Fill a bubble to check yourself
A,B Correct answer
Explanation

In PL/SQL block structure, only the EXECUTE section is mandatory. DECLARE (for declarations) and EXCEPTION (for exception handling) are both optional. BEGIN marks the start of the executable section and is required. END marks the end of the block and is required. Therefore, both DECLARE and EXCEPTION can be omitted in a simple PL/SQL block.

Multiple choice technology databases
  1. True

  2. False

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

The statement is False because ROLLBACK can be used to close a transaction. When you issue a ROLLBACK statement, it undoes all changes made in the current transaction and effectively ends/closes that transaction. After a ROLLBACK, a new transaction begins with the next SQL statement. COMMIT also closes a transaction. Both ROLLBACK and COMMIT are transaction control statements that terminate the current transaction.

Multiple choice technology databases
  1. a) A stored procedure on the server.

  2. b) A block of code in a PL/SQL library.

  3. c) A standalone procedure on the client machine.

  4. d) A block of code in the body of the program unit ORDERTOTAL.

  5. e) A local subprogram defined within the program unit ORDERTOTAL.

Reveal answer Fill a bubble to check yourself
E Correct answer
Explanation

Option E is correct because the code is only used within the program unit ORDERTOTAL. A local subprogram (procedure or function defined within ORDERTOTAL) is the most appropriate choice - it encapsulates the logic, makes it reusable within the unit, and keeps the scope limited. Stored procedures (A) would make it globally available on the server, which is unnecessary. PL/SQL libraries (B) or standalone procedures (C) are also overkill for local-only use. Option D is incorrect because putting code directly in the body doesn't make it reusable from multiple places within ORDERTOTAL.