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
A
Correct answer
Explanation
SQL allows aliases to be defined on both tables (to shorten references and qualify columns in joins) and columns (to rename output headers and make them descriptive). This simplifies query writing and significantly improves the readability of complex SQL queries, making the statement true.
-
ORACLE BASICS
-
Oracle Basics
-
oracle basics
-
oracleBasics
B
Correct answer
Explanation
INITCAP converts each word to title case - first letter uppercase, remaining letters lowercase. For 'ORACLE BASICS', it produces 'Oracle Basics' with both words properly capitalized. This Oracle string function is commonly used for formatting names and headings.
-
ORACLE BASICS
-
ORACLEBASICS
-
oraclebasics
-
oracleBasics
B
Correct answer
Explanation
The || operator performs string concatenation in Oracle SQL. CONCAT('ORACLE' || 'BASICS') first evaluates 'ORACLE' || 'BASICS' to 'ORACLEBASICS', then CONCAT receives this single result. The output is 'ORACLEBASICS' with no space added. Option A shows a space that isn't present in the input.
A
Correct answer
Explanation
SUBSTR with negative start position counts from the string's end. For 'ORACLE BASICS' (13 characters), position -6 is 'B' (6th from end). Starting there and taking 5 characters gives 'BASIC' (positions 8-12). This Oracle function is useful for extracting text from the right side.
-
01-SEP-1995
-
01-JAN-1995
-
01-JAN-1996
-
1995
-
1996
B
Correct answer
Explanation
TRUNC with 'YEAR' precision truncates a date to January 1st of its year. For '01-SEP-1995', this yields '01-JAN-1995' - same year, first day. The 'YEAR' format zeroes month and day to 1. TRUNC is different from ROUND which would round up to next year on certain dates.
-
01-MAR-1996
-
01-FEB-1996
-
07-SEP-1995
-
06-SEP-1995
A
Correct answer
Explanation
ADD_MONTHS adds the specified number of months to a date. Starting September 1, 1995 and adding 6 months: Sep->Oct(1), Nov(2), Dec(3), Jan(4), Feb(5), Mar(6) = March 1, 1996. This function handles year rollovers automatically. Option C shows 6 days instead of months.
-
31-AUG-1995
-
30-SEP-1995
-
31-OCT-1995
-
31-DEC-1995
B
Correct answer
Explanation
LAST_DAY returns the last date of the month for any given date in that month. For September 1, 1995, it returns September 30, 1995 (September's last day). This is useful for month-end calculations. Option A shows August (previous month), not September.
-
ADD_MONTHS
-
COUNT
-
ROUND
-
DISTINCT
-
AVG
-
SUM
B,E,F
Correct answer
Explanation
COUNT, AVG, and SUM are group (aggregate) functions because they operate on sets of rows to return a single value. ROUND and ADD_MONTHS are single-row functions acting on individual values, while DISTINCT is an SQL query modifier keyword rather than a function.
B
Correct answer
Explanation
WHERE clause filters individual rows before any grouping occurs. HAVING is used to filter groups after GROUP BY is applied. The statement claims WHERE restricts groups, which is incorrect - it restricts rows, not groups.
-
WHERE clause
-
GROUP BY clause
-
GROUP functions
-
DISTINCT keyword
-
FROM clause
B,C,D
Correct answer
Explanation
A view is not deletable if its query contains aggregate functions, GROUP BY clauses, or the DISTINCT keyword, as the system cannot map the deletion to specific source table rows. A view must have a FROM clause and can optionally have a WHERE clause without affecting delete support.
-
select count(*) from orders;
-
select count(1) from orders;
-
select count(3) from orders;
-
select count(5) from orders;
A
Correct answer
Explanation
Indexes significantly improve SELECT query performance by providing fast lookup paths. However, they impose overhead on DML operations (INSERT, UPDATE, DELETE) because the index must be updated alongside the table data. This is a fundamental trade-off in database design - faster reads come at the cost of slower writes.
-
DECLARE
-
BEGIN
-
EXCEPTION
-
END
B,D
Correct answer
Explanation
In PL/SQL block structure, only the execution section (BEGIN) and its terminator (END) are mandatory. The declaration section (DECLARE) is optional and only needed when declaring variables, cursors, or exceptions. The exception handling section (EXCEPTION) is also optional.
A
Correct answer
Explanation
%ROWTYPE attribute declares a variable that inherits the entire row structure from a table or cursor, including all column names and data types. This provides automatic synchronization if the table structure changes.
A
Correct answer
Explanation
%TYPE attribute declares a variable that inherits the data type from a specific table column or an already declared variable. This ensures type compatibility and automatically updates if the referenced type changes.