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

Multiple choice technology databases
  1. Querying with the SELECT * notification.

  2. Declaring variables with the %TYPE attribute.

  3. Specifying schema names when referencing objects.

  4. Declaring records by using the %ROWTYPE attribute.

  5. Specifying package.procedure notation while executing procedures.

Reveal answer Fill a bubble to check yourself
A,B,D Correct answer
Explanation

SELECT * with notifications (A) automatically captures schema changes. %TYPE attribute (B) anchors variables to column datatypes, reducing coupling. %ROWTYPE attribute (D) mirrors table structure for records, minimizing maintenance when tables change. Schema names (C) increase coupling by hardcoding references. Package.procedure notation (E) doesn't affect dependency failure - it's just execution syntax.

Multiple choice technology databases
  1. A stored procedure is typically written in SQL.

  2. A stored procedure is a named PL/SQL block that can accept parameters.

  3. A stored procedure is a type of PL/SQL subprogram that performs an action.

  4. A stored procedure has three parts: the specification, the body, and the exception handler part.

  5. The executable section of a stored procedure contains statements that assigns values, control execution, and return values to the calling environment.

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

Stored procedures in PL/SQL are named program units that can accept parameters (B) and are subprograms that perform specific actions (C). Option A is misleading because stored procedures use PL/SQL (which includes SQL), not pure SQL. Option D incorrectly describes the structure; procedures have a header (specification) and body, but not a separate 'exception handler part'. Option E describes what an executable section does but doesn't define what a stored procedure is.

Multiple choice technology databases
  1. A package.

  2. A stored function.

  3. A stored procedure.

  4. Another database trigger.

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

Within a trigger body, the CALL statement is used to invoke a stored procedure. Triggers can call stored procedures to execute complex business logic or perform operations that cannot be done directly in trigger SQL. You cannot CALL packages, functions (use direct invocation), or other triggers from within a trigger.

Multiple choice technology databases
  1. EXECUTE UPD_BAT_STAT(V_ID);

  2. UPD_BAT_STAT(V_ID);

  3. RUN UPD_BAT_STAT(V_ID);

  4. START UPD_BAT_STAT(V_ID);

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

In PL/SQL, you invoke a stored procedure by simply writing its name followed by parameters in parentheses. You do not use keywords like EXECUTE (SQL*Plus command), RUN, or START. The correct syntax is just the procedure name with parameters: UPD_BAT_STAT(V_ID).

Multiple choice technology databases
  1. SHOW FUNCTION_ERROR

  2. SHOW USER_ERRORS

  3. SHOW ERRORS

  4. SHOW ALL_ERRORS

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

The SHOW ERRORS command in SQL*Plus displays the compilation errors for the most recently created PL/SQL object (function, procedure, package, etc.). This is the standard way to view the specific error details after receiving a compilation warning. Options A, B, and D are not valid SQL*Plus commands.

Multiple choice technology databases

Examine this code: CREATE OR REPLACE FUNCTION gen_email_name (p_first_name VARCHAR2, p_last_name VARCHAR2, p_id NUMBER) RETURN VARCHAR2 is v_email_name VARCHAR2(19); BEGIN v_email_home := SUBSTR(p_first_name, 1, 1) || SUBSTR(p_last_name, 1, 7) || [email protected] .; UPDATE employees SET email = v_email_name WHERE employee_id = p_id; RETURN v_email_name; END; You run this SELECT statement: SELECT first_name, last_name gen_email_name(first_name, last_name, 108) EMAIL FROM employees; What occurs?

  1. Employee 108 has his email name updated based on the return result of the function.

  2. The statement fails because functions called from SQL expressions cannot perform DML.

  3. The statement fails because the functions does not contain code to end the transaction.

  4. The SQL statement executes successfully, because UPDATE and DELETE statements are ignoring in stored functions called from SQL expressions.

  5. The SQL statement executes successfully and control is passed to the calling environment.

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

The SELECT statement fails at runtime because the function gen_email_name attempts to perform an UPDATE operation. Functions called within SQL queries are not permitted to execute DML statements.

Multiple choice technology databases
  1. You need to execute the command CALCTAX(1000); .

  2. You need to execute the command EXECUTE FUNCTION calc tax; .

  3. You need to create a SQL *Plus environment variable X and issue the command :X := CALCTAX(1000); .

  4. You need to create a SQL *Plus environment variable X and issue the command EXECUTE :X := CALCTAX;

  5. You need to create a SQL *Plus environment variable X and issue the command EXECUTE :X := CALCTAX(1000);

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

To run the given function from the SQL*Plus prompt, the user needs to know the correct syntax for invoking a function in Oracle SQL. The function CALCTAX takes in a single parameter, sal, and returns the result of sal * 0.05.

Option A is incorrect because it is missing the keyword SELECT to return the result of the function.

Option B is incorrect because the keyword FUNCTION is not used in the EXECUTE statement, and the argument sal is not provided.

Option C is incorrect because SQL*Plus environment variables are not required to execute a function, and it is missing the keyword SELECT to return the result of the function.

Option D is incorrect because it is missing the argument sal.

Option E is the correct answer because it first declares an SQL*Plus environment variable X, executes the function CALCTAX with the argument 1000, and assigns the result to the variable X. The keyword SELECT is not required because the result is assigned to a variable.

Therefore, the answer is: E. You need to create a SQL*Plus environment variable X and issue the command EXECUTE :X := CALCTAX(1000);

Multiple choice technology databases
  1. Use a drop procedure statement to drop a standalone procedure.

  2. Use a drop procedure statement to drop a procedure that is part of a package. Then recompile the package specification.

  3. Use a drop procedure statement to drop a procedure that is part of a package. Then recompile the package body.

  4. For faster removal and re-creation, do not use a drop procedure statement. Instead, recompile the procedure using the alter procedure statement with the REUSE SETTINGS clause.

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

To remove a standalone procedure from the database, use the DROP PROCEDURE statement. Procedures inside a package cannot be dropped individually; the entire package body must be modified and recompiled.

Multiple choice technology databases
  1. add_dept;

  2. add_dept( .Accounting .);

  3. add_dept(, .New York .);

  4. add_dept(p_location=> .New York .);

Reveal answer Fill a bubble to check yourself
A,B,D Correct answer
Explanation

In PL/SQL, procedures with DEFAULT parameters can be called using those defaults. Option A uses both defaults. Option B provides the first parameter positionally, second uses default. Option C is invalid - you cannot skip a positional parameter with a comma (must use named notation). Option D uses named notation for the second parameter, first uses default. Named notation allows specifying parameters out of order or skipping earlier ones.

Multiple choice technology databases
  1. SELECT CALC_PLAYER_AVG(PLAYER_ID) FROM PLAYER_BAT_STAT;

  2. EXECUTE CALC_PLAYER_AVG (31);

  3. CALC_PLAYER (.RUTH.);

  4. CALC_PLAYER_AVG(31);

  5. START CALC_PLAYER_AVG(31)

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

The function CALC_PLAYER_AVG returns a value and can be successfully invoked inside a standard SQL query by passing a column name as an argument.

Multiple choice technology databases
  1. When the procedure contains no SQL statements.

  2. When the procedure contains no PL/SQL commands.

  3. When the procedure needs to be used by many client applications accessing several remote databases.

  4. When the procedure needs to be used by many users accessing the same schema objects on a local database.

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

Server-side procedures are stored in the database and execute on the database server. They're ideal when many users need to perform the same operations on the same data (same schema objects). This reduces network traffic and ensures consistency. Option C is wrong because that describes distributed scenarios needing client-side logic. Options A and B are nonsensical - a procedure without PL/SQL or SQL isn't a procedure.

Multiple choice technology databases
  1. When declaring arguments length is not allowed.

  2. When declaring arguments each argument must have a mode specified.

  3. When declaring arguments each argument must have a length specified.

  4. When declaring a VARCHAR2 argument it must be specified.

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

In PL/SQL stored procedure declarations, formal parameters must specify only the data type (e.g., VARCHAR2), and defining a specific length (like VARCHAR2(30)) is syntactically illegal.

Multiple choice technology databases
  1. a) GRANT SELECT ON ADD_PLAYER TO PUBLIC;

  2. b) GRANT EXECUTE ON ADD_PLAYER TO PUBLIC;

  3. c) GRANT INSERT ON PLAYER TO PUBLIC;

  4. d) GRANT EXECUTE, INSERT ON ADD_PLAYER TO PUBLIC;

  5. e) REVOKE INSERT ON PLAYER FROM PUBLIC;

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

To control INSERT access via a procedure: (1) GRANT EXECUTE on the procedure to PUBLIC so users can call it, and (2) REVOKE INSERT on the table from PUBLIC to prevent direct inserts. The procedure then becomes the only insertion path. Options A and C grant wrong privileges. Option D grants INSERT on the procedure (incorrect - procedures aren't inserted into).

Multiple choice technology databases
  1. SQL> set sqlprompt “Qwest > “

  2. SQL> set prompt “Qwest > “

  3. SQL> sqlprompt set “Qwest > “

  4. SQL> prompt “Qwest > “

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

In SQL*Plus, the command set sqlprompt "Qwest > " is the correct syntax to change the default SQL command prompt display name.