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
-
For loop.. end loop
-
loop..end loop
-
While loop.. end loop
-
Do while loop..end loop
D
Correct answer
Explanation
There is no 'Do while' loop in PL/SQL. To write conditional loops, we can either use the 'simple' or the 'while' loop.
D
Correct answer
Explanation
All PL/SQL 'select' statements must contain the 'into' keyword. The 'into' keyword is used to copy the values returned by a select statement into variables. For example, the statement - 'select bookno, bookname, price into bkno, bkname,bkprice from books where title='Oracle''- will copy the values of bookno, bookname and price columns in the variables bkno, bkname and bkprice, respectively. The 'into' clause is not used when the 'select' statement is used at the SQL prompt.
-
%ISOPEN
<!--?xml:namespace prefix = o /--><o:p></o:p>
<o:p></o:p>
-
%EXISTS
-
%FOUND
<o:p></o:p>
-
%ROWCOUNT
B
Correct answer
Explanation
The %exists is not a valid cursor attribute. If used with a cursor name, it will result in compilation error.
-
Alter
-
Update
-
Delete
-
Insert
A
Correct answer
Explanation
A trigger is a PL/SQL block structure, which is fired when DML statements like Insert, Delete, Update are executed on a database table. 'Alter' is not a DML statement but a DDL statement that is used to alter or change the structure of a table like adding, dropping and resizing a column. We cannot write a trigger for a DDL command.
-
If condition then
statements
elseif condition then
statements
else
statements
end if;
-
if condition
statements
elseif condition
statements
else
statements
end if;
-
if condition then
statements
elif condition then
statements
else
statements
end if;
-
if condition
statements
elsif condition
statements
else
statements
endif;
A
Correct answer
Explanation
'If-else' is a condition statement that is used to write conditional statement in a PL/SQL program. For example, the following code will print a message depending on whether the value of A is greater, B is greater or both of them have the same values -
if a>b then
dbms_output.put_line('A is greater');
elsif b>a then
dbms_output.put_line('B is greater');
else
dbms_output.put_line('Both are equal');
end if;
D
Correct answer
Explanation
There is no OUTIN parameter in PL/SQL. Therefore, the program will return an error.
-
A trigger can be written for handling updates of a particular column.
-
A trigger can be run either before or after the execution of an SQL statement.
-
A trigger cannot be written on a view.
-
A trigger cannot contains a condition.
C
Correct answer
Explanation
A trigger can be written on a view if it is declared using the 'instead of' keyword. The difference between a normal trigger and an instead of trigger is that when a normal trigger is fired, both the triggers and the firing DML statement like Delete, Insert or Update is also executed. On the other hand, in case of an instead of trigger the DML statements only invoke the trigger, they are not executed. A normal trigger is written against a table whereas an instead of trigger is written on a view.
-
Data constant number (3)=10
-
Data constant number (3) := 10;
-
Data constant number (3);
-
Constant Data number (3) := 10;
B
Correct answer
Explanation
A constant is a value used in a PL/SQL block that remains unchanged throughout the program. It is declared using the assignment operator ':='. We must assign a value to a constant at the time of declaration. If we do not assign a value to a constant while declaring it and try to assign a value in the execution section, we will get an error.
-
SQL is declarative, while PL/SQL is procedural.
-
SQL is used to write queries, whereas PL/SQL is used to code programs.
-
SQL can be embedded within PL/SQL but a PL/SQL statement cannot be embedded in SQL.
-
PL/SQL executes one statement at a time, whereas SQL is used to write a code block.
D
Correct answer
Explanation
PL/SQL is used to write individual statement in the form of a unit or program. When the program is executed, all the statements written in a complete logic are executed. On the other hand, SQL statements are executed one at a time when the user presses enter key to run the statement.
-
default
-
else
-
case
-
otherwise
B
Correct answer
Explanation
The 'case' statement is a conditional statement like the 'if-else' statement. It contains both the conditions and the statements that are processed if the condition is true. A 'case' statement can have as many 'cases' or statements as required. If all specified conditions in the 'case' statement are false, the control automatically transfers to the 'else' part. Although optional, the 'else' part will be processed if none of the conditions above is true.
-
Varname tablename.colname%rowtype
-
Varname tablename.colname%istype
-
Varname tablename.colname%totype
-
Varname tablename.colname%type
D
Correct answer
Explanation
PL/SQL provides a very useful feature called variable anchors. It refers to the use of keyword %TYPE to declare a variable with the same data type as the column data type in a table. For example, if we want to declare a variable named 'salary' with the same data type as of 'basic_salary' column of a table named 'employee' we can write the following statement:
salary employee.basic_salary%type;
-
For an INSERT trigger, OLD contains no value and NEW contains new values.
-
For an ALTER trigger, OLD contains the old values, and NEW contains the new values.
-
For an UPDATE trigger, OLD contains the old values, and NEW contains the new values.
-
For a DELETE trigger, OLD contains old values, and NEW contains no value.
B
Correct answer
Explanation
ALTER is a DDL statement and triggers are written on execution of a DML statement. Therefore, we cannot create a trigger that fires when an Alter statement is issued.
-
Oracle performs the open, fetches, and close for you automatically.
-
It is less efficient than an explicit cursor.
-
It is less vulnerable to data errors.
-
It gives you less programmatic control.
C
Correct answer
Explanation
If an implicit SELECT statement returns more than one row, it raises the TOO_MANY_ROWS exception. In this case, execution in the current block terminates and control is passed to the exception section. An implicit cursor is more prone to errors.
-
CONNECT
-
RENAME
-
SELECT
-
INSERT
-
DELETE
B
Correct answer
Explanation
In Oracle, the RENAME command performs an automatic commit because it is a DDL (Data Definition Language) operation. All DDL commands in Oracle have implicit commit behavior. Other options listed are either DML (INSERT, DELETE) or session commands (CONNECT, SELECT) which do not auto-commit.
-
Conventional
-
Direct-Load
-
Parallel Direct-Load
-
Serial-Conventional
B
Correct answer
Explanation
The APPEND hint in Oracle INSERT statements enables Direct-Load insert, which bypasses the buffer cache and writes data directly to data files. This method is faster than conventional path inserts and is used for bulk data loading operations. The '+' prefix indicates a hint.