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
-
NULL
-
1 row
-
3 rows
-
4 rows
-
0 row
C
Correct answer
Explanation
ROWNUM IN (1,3,3,2) behaves similarly to ROWNUM IN (1,2,3) after deduplication. The first row gets ROWNUM=1 (matches), second row gets ROWNUM=2 (matches), third row gets ROWNUM=3 (matches). Rows 4-30 get ROWNUM values >3 and don't match. Thus, 3 rows are returned.
-
2
-
1+1
-
Error: invalid number
-
Error: invalid Character
-
Error: invalid identifier
A
Correct answer
Explanation
In Oracle, the '+' operator with strings causes implicit conversion to numbers. Both '1' strings are converted to numbers, then added. The result is 2 (numeric), not '11' (string concatenation would use ||). The implicit numeric conversion makes this a valid arithmetic operation.
A
Correct answer
Explanation
Oracle implicitly converts the string '1' to a number when used in arithmetic with + operator. So '1'+1 becomes 1+1, which equals 2. The second query 1+1 also equals 2. Both return the same result.
-
aa
-
a a
-
a'a
-
Error: invalid identifier
-
Error: invalid character
C
Correct answer
Explanation
In Oracle SQL, a single quote within a string literal is escaped by doubling it. Two consecutive single quotes ('') represent one literal quote character. The string 'a''a' contains characters a, ', a - outputting a'a.
-
NULL
-
Error: invalid identifier
-
X
-
Error: invalid SQL Statemet
-
A
C
Correct answer
Explanation
Oracle's DUAL table contains a pseudo-column called DUMMY. The DUMMY column always contains the value 'X'. Selecting this column returns X - this is documented Oracle behavior for backwards compatibility.
-
A
-
X
-
NULL
-
Error: Invalid SQL statement
-
Error: Invalid Identifier
B
Correct answer
Explanation
In Oracle SQL, the DUAL table is a dummy table containing a single row with a single column DUMMY that has the value 'X'. Querying it with select * retrieves this default row and returns 'X'.
-
No rows returned
-
Error: invalid SQL statement
-
Error: invalid identifier
-
Error: syntax error
-
1 row
A
Correct answer
Explanation
The DUAL table contains exactly one column named DUMMY and one row with the value 'X'. Because select dummy from dual and select * from dual both return exactly the same single row (X), subtracting one from the other via MINUS yields an empty set with no rows.
-
Error: "VERSION": invalid identifier
-
Error: "VERSION": invalid character
-
Error: invalid SQL statement
-
shows oracle database version
-
Null
A
Correct answer
Explanation
VERSION is not a column in the DUAL table. Selecting a non-existent column causes ORA-00904 invalid identifier error. To get version info, use V$VERSION or PRODUCT_COMPONENT_VERSION from the dictionary views, not DUAL.
-
Columns specified in condition
-
Columns specified other than the condition
-
Primary key
-
Foreign key
A
Correct answer
Explanation
In Informatica Lookup transformations, the columns used in the lookup condition are cached in the index cache for fast searching. Other columns go to the data cache. This optimization improves lookup performance by indexing on the join/condition columns.
-
0
-
Error: divisor is equal to zero
-
Error: Invalid Identifier
-
NULL
A
Correct answer
Explanation
NVL returns the first argument if it is not null, otherwise returns the second argument. Since 'abc' is not null, both NVL('abc','a') and NVL('abc',0) return 'abc'. The second argument's type is irrelevant when the first is non-null.
-
No rows returned
-
abc
-
Two rows of value 'abc'
-
Error: Syntax error
A
Correct answer
Explanation
Both NVL queries return 'abc' (non-null value). The REPLACE query also returns 'abc'. UNION ALL combines the two 'abc' rows, then MINUS removes rows matching the REPLACE result. Since both are 'abc', MINUS removes everything, leaving no rows.
-
Error: Syntax error
-
0
-
5
-
Error: Argument '-1' is out of range
D
Correct answer
Explanation
INSTR's fourth parameter (occurrence) cannot be negative - valid values are positive integers. The function throws ORA-01428 'argument out of range' when occurrence is -1. Negative values work for the third parameter (start position) to search backwards, but not for occurrence.
-
select instr('Hi Partha Sarathi Ojha',last,'a') from dual
-
select instr('Hi Partha Sarathi Ojha','a',-1) from dual
-
select instr('Hi Partha Sarathi Ojha',left,'a') from dual
-
select instr('Hi Partha Sarathi Ojha',-1,'a') from dual
-
select instr('Hi Partha Sarathi Ojha','-a') from dual
B
Correct answer
Explanation
INSTR with a negative start position (third parameter) searches backwards from the end of the string. Setting start to -1 means start searching from the last character. This finds the last occurrence of 'a' in the string.
B
Correct answer
Explanation
TRANSLATE does character-by-character replacement following position mapping: 'a'→'e', 'b'→'f', remaining characters unchanged. So 'abcda' becomes 'efcde'. The 'a' at positions 1 and 5 both become 'e'; 'b' becomes 'f'; 'c' and 'd' stay unchanged.