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
-
SELECT TO_CHAR('ll-oct-2007'. 'miDdspth "of Month. Year') FROM DUAL:
-
SELECT TO_CHAR(TO_DATE('ll-oct-2007'X 'miDdspth of month, year') FROM DUAL;
-
SELECT TO_CHAR(TO_DATE('ll-oct-2007'). 'miDdthsp "of* Month. Year') FROM DUAL;
-
SELECT TO_DATE(TO_CHAR('ll-oct-20077fiiiDdspth "of" Month. Year')) FROM DUAL:
C
Correct answer
Explanation
The correct approach uses TO_CHAR with TO_DATE to first parse the string into a date, then format it. The format model uses 'ddspth' for ordinal day number, 'Month' for full month name, and 'year' for spelled-out year. The question contains garbled formatting with incorrect quotes and delimiters.
-
A subquery that defines a view cannot include the GROUP BY clause
-
A view is created with the subquery having the DISTINCT keyword can be updated
-
A view that is created with the subquery having the pseudo column ROWNUM keyword cannot be updated
-
A Data Manipulation Language (DML) operation can be performed on a view that is created with the subquery having all the NOT NULL columns of a table
C,D
Correct answer
Explanation
Views using ROWNUM cannot be updated because the row numbers are generated dynamically, preventing direct row identification. Performing DML on a view with all NOT NULL columns from the base table is allowed because it satisfies the constraint integrity rules of the underlying table.
-
It ignores NULL values
-
Reversing the order of the intersected tables alters the result.
-
The names of columns in all SELECT statements must be identical.
-
The number of columns and data types must be identical for all SELECT statements in the
D
Correct answer
Explanation
INTERSECT returns rows common to both SELECT statements. It requires identical column counts and matching data types (D is true). Column names don't need to match (C is false). NULLs are treated like other values (A is false). INTERSECT is commutative (B is false).
A
Correct answer
Explanation
By definition, a primary key constraint uniquely identifies each record in a database table. Therefore, the column or set of columns designated as the primary key must contain unique values and cannot contain null values.
A
Correct answer
Explanation
Triggers can enforce referential integrity by executing custom logic before or after INSERT/UPDATE/DELETE operations. They can validate data, prevent invalid operations, or cascade changes similar to foreign key constraints. While foreign keys are declarative and preferred, triggers offer programmatic control for complex scenarios.
-
Between -20000 and -20999
-
Between -200000 and -209999
-
Between -20001 and -20999
-
Between -200001 and -209999
A
Correct answer
Explanation
RAISE_APPLICATION_ERROR in Oracle allows user-defined error numbers from -20000 to -20999, giving developers 1000 error codes for custom exceptions. This range is reserved specifically for application-defined errors. Error numbers outside this range are reserved for Oracle system errors.
-
ALTER SESSION SET NEW_DATE_FORMAT = <date_format>
-
ALTER SESSION SET CUR_DATE_FORMAT = <date_format>
-
ALTER SESSION SET NLS_DATE_FORMAT = <date_format>
-
ALTER SESSION SET SESS_DATE_FORMAT = <date_format>
C
Correct answer
Explanation
ALTER SESSION SET NLS_DATE_FORMAT changes the date format for the current session only. NLS (National Language Support) parameters control locale-specific formatting. The format string uses codes like 'DD-MON-YYYY' or 'MM/DD/YYYY'. This affects how dates are displayed and converted, not how they're stored.
A
Correct answer
Explanation
In PL/SQL, VARCHAR2 can hold up to 32767 bytes (32KB), which is much larger than the SQL limit of 4000 bytes. This extended capacity is useful for procedural code processing larger text strings. Options like 1024 or 255 are outdated limits from earlier versions or different contexts.
-
TO_CHAR, INOUT
-
PROC, PACKAGE
-
PRAGMA, MULTI_ROW
-
SELECT, EXCEPTION
D
Correct answer
Explanation
SELECT and EXCEPTION are both valid PL/SQL reserved words. SELECT is used for querying data, and EXCEPTION is used in exception handling blocks. The other options contain invalid words: INOUT is not a reserved word (it's a parameter mode), PROC is not reserved (PROCEDURE is), and MULTI_ROW is not a PL/SQL reserved term.
-
SET AUTOTRACE TRACEONLY
-
SET AUTOTRACE ON
-
SET AUTOTRACE ON STATISTICS
-
SET AUTOTRACE ON EXPLAIN
B
Correct answer
Explanation
SET AUTOTRACE ON displays both the execution plan (EXPLAIN) and statistics (STATISTICS) for SQL queries. The ON option combines both tracing capabilities. TRACEONLY suppresses query output, ON STATISTICS shows only statistics, and ON EXPLAIN shows only the execution plan - but ON gives you everything.
-
Comment marker
-
Not equal to operator
-
Label delimiter
-
Greater than or equal to operator
C
Correct answer
Explanation
In PL/SQL, <> and >> are used to define label delimiters, which mark named blocks for use with GOTO statements or to label loops for nested loop control. The << marks the start of a label and >> marks the end. This is distinct from comment markers (-- or /* */) or comparison operators like >= or !=.
-
SQL%ROWCOUNT
-
SQL%COUNT
-
SQL%FOUND
-
SQL%NUM_ROWS
A
Correct answer
Explanation
In PL/SQL, the implicit cursor attribute SQL%ROWCOUNT returns the exact number of rows affected by the last executed DML statement. SQL%FOUND returns a boolean, while SQL%COUNT and SQL%NUM_ROWS are not valid PL/SQL implicit cursor attributes.
-
The order of rows in a table is arbitrary
-
A table can contain only one row formats
-
The order of rows in a table is keyed to Primary Index.
-
A table can contain multiple row formats
A,B
Correct answer
Explanation
In relational databases, the order of rows in a table is arbitrary and not guaranteed - rows have no inherent positional order. Teradata tables can contain only one row format per table, which is a design constraint for performance and simplicity. Option C incorrectly ties row order to Primary Index, and option D is false because Teradata does not support multiple row formats in a single table.
-
select count() from emp group by empno having count() >2;
-
select empno, count() from emp having count() >2;
-
select empno, count() from emp where count() >2;
-
select empno, count() from emp group by empno having count() >2;
D
Correct answer
Explanation
To find employee numbers appearing more than twice, we need to: 1) Group by empno to aggregate occurrences, 2) Count occurrences with count(*), 3) Filter groups having count > 2 using HAVING clause. Option D correctly implements all three steps. Option A lacks the empno column in SELECT. Option B lacks GROUP BY. Option C incorrectly uses WHERE instead of HAVING for aggregate filtering.
-
Query
-
Attribute
-
Relation
-
Record
D
Correct answer
Explanation
In relational database terminology, a row represents a single complete record of data. Columns are called attributes or fields. The entire table represents a relation. Therefore, 'Record' is the correct term for a row in database context.