Computer Knowledge

Database and SQL

3,929 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. TO_CHAR

  2. TO_DATE

  3. MAX

  4. LPAD

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

MAX is an aggregate function that works on any datatype - it finds the maximum value in a set regardless of whether the values are numbers, strings, or dates. TO_CHAR and TO_DATE are type conversion functions that require specific input types, while LPAD is a string manipulation function.

Multiple choice technology databases
  1. NUMBER

  2. LONG

  3. VARCHAR2

  4. RAW

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

In Oracle, LONG is a legacy datatype with restrictions - you cannot create indexes on LONG columns. NUMBER, VARCHAR2, and RAW all support indexing. LONG has been deprecated in favor of CLOB. This is a well-known limitation of the LONG datatype.

Multiple choice technology web technology
  1. Define EFFDT

  2. Define EFF_STATUS

  3. Define EFFDT as key, in ascending order

  4. Define EFFDT as key, in descending order

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

Effective dated tables require EFFDT as a key field in DESCENDING order. This ensures the most recent effective date (highest date value) appears first when querying, which is critical for time-based data retrieval. EFF_STATUS is often used but not strictly required. The key requirement is EFFDT in descending order as the first key field.

Multiple choice technology web technology
  1. 3

  2. 2

  3. 0

  4. 5

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

When a record has Search Keys defined, PeopleSoft automatically builds indexes for them (one index per Search Key, or a composite index if multiple). Alternate Search Keys don't automatically generate indexes; they're primarily for search assistance in PeopleSoft query tools. So with 3 Search Keys and 2 Alternate Search Keys, only 3 indexes are built automatically.

Multiple choice technology databases
  1. ALTER TABLE DROP COLUMN

  2. ALTER TABLE DROP CONSTRAINT

  3. ALTER TABLE DISABLE CONSTRAINT

  4. -

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

In Oracle SQL, the CASCADE CONSTRAINTS clause is used with ALTER TABLE DROP COLUMN to automatically drop any referential integrity constraints (like foreign keys) that refer to the column being dropped. This prevents errors when removing columns that are part of a relationship.

Multiple choice technology databases
  1. CONNECT

  2. RENAME

  3. INSERT

  4. DELETE

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

In SQL databases, DDL (Data Definition Language) commands like RENAME typically cause an automatic commit of the current transaction. DML commands like INSERT and DELETE don't auto-commit unless autocommit mode is enabled. CONNECT establishes a session but doesn't commit anything.

Multiple choice technology databases
  1. NULL

  2. NOT NULL

  3. Function NVL2 is not defined

  4. None of the above

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

To solve this question, the user needs to know the function NVL2 in SQL.

The NVL2 function in SQL returns one value if an expression is not null, or another value if it is null. The syntax for the NVL2 function is:

NVL2( expression1, expression2, expression3 )

If expression1 is not null, then NVL2 returns expression2. If expression1 is null, then NVL2 returns expression3.

In this case, expression1 is NULL, so NVL2 will return the value of expression3, which is also NULL.

Therefore, the answer is:

The Answer is: A. NULL

Multiple choice technology databases
  1. When a SELECT statement returns more than one row

  2. When a SELECT statement returns no rows

  3. When INTO statement is missing in the SELECT statement

  4. Both I and II

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

To answer this question, the user needs to know the basics of PL/SQL and how it handles exceptions.

A. When a SELECT statement returns more than one row: This is one of the cases where PL/SQL raises an exception. If a SELECT statement returns more than one row in a context where a single value is expected, such as in an assignment statement or a SELECT INTO statement, then PL/SQL will raise the TOO_MANY_ROWS exception.

B. When a SELECT statement returns no rows: This is another case where PL/SQL raises an exception. If a SELECT statement returns no rows in a context where a single value is expected, such as in an assignment statement or a SELECT INTO statement, then PL/SQL will raise the NO_DATA_FOUND exception.

C. When INTO statement is missing in the SELECT statement: This is not a case where PL/SQL raises an exception. If an INTO statement is missing in a SELECT statement, then a compilation error will occur, but it will not result in an exception at runtime.

D. Both I and II: This option is correct. PL/SQL raises exceptions in both cases where a SELECT statement returns more than one row (TOO_MANY_ROWS) and where a SELECT statement returns no rows (NO_DATA_FOUND).

Therefore, the correct answer is: D.

Multiple choice technology databases
  1. NULL

  2. NOT NULL

  3. Function NVL2 is not defined

  4. None of the above

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

NVL2(expr1, expr2, expr3) returns expr2 if expr1 is NOT NULL, otherwise returns expr3. Since the first argument is NULL, NVL2 returns the third argument NULL. The second argument 'NOT NULL' is just a string literal in this context, not the SQL keyword.

Multiple choice technology databases
  1. SELECT INITCAP(TRIM ('HelloWorld', 1,1)) FROM dual;

  2. SELECT SUBSTR( 'HelloWorld',1) FROM dual;

  3. SELECT LOWER(SUBSTR('HelloWorld', 1, 1) FROM dual;

  4. SELECT LOWER(TRIM ('H' FROM 'HelloWorld')) FROM dual;

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

To solve this question, the user needs to know the basics of SQL SELECT statements and string manipulation functions. The user should be familiar with the INITCAP, TRIM, SUBSTR, and LOWER functions.

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

A. SELECT INITCAP(TRIM ('HelloWorld', 1,1)) FROM dual;

This option is incorrect. The TRIM function removes characters from the beginning and end of a string. In this case, the second and third arguments of the TRIM function are incorrect. INITCAP capitalizes the first letter of a string and converts the rest of the string to lowercase. Therefore, this SELECT statement will not return the correct result.

B. SELECT SUBSTR( 'HelloWorld',1) FROM dual;

This option is incorrect. The SUBSTR function returns a substring from a given string. In this case, the function only returns the first character of the string 'HelloWorld'. Therefore, this SELECT statement will not return the correct result.

C. SELECT LOWER(SUBSTR('HelloWorld', 1, 1) FROM dual;

This option is incorrect. The SUBSTR function returns a substring from a given string. In this case, the function only returns the first character of the string 'HelloWorld'. The LOWER function converts the substring to lowercase. Therefore, this SELECT statement will not return the correct result.

D. SELECT LOWER(TRIM ('H' FROM 'HelloWorld')) FROM dual;

This option is correct. The TRIM function removes the character 'H' from the beginning of the string 'HelloWorld'. The LOWER function converts the remaining string to lowercase. Therefore, this SELECT statement will return the correct result.

The Answer is: D

Multiple choice technology databases
  1. Both tables have NULL values.

  2. You want all matched data from both tables.

  3. You want all unmatched data from both tables.

  4. You want all unmatched data from one table.

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

A FULL OUTER JOIN returns all rows when there is a match in either left or right table records. It is specifically used to ensure that unmatched data from both tables is included in the result set.