0

databases Online Quiz - 233

Description: databases Online Quiz - 233
Number of Questions: 20
Created by:
Tags: databases
Attempted 0/20 Correct 0 Score 0

The following statement will raise an exception on which line? select dept_name, avg(all salary) ,count() “number of employees” from emp , dept where deptno = dept_no and count() > 5 group by dept_name order by 2 desc;

  1. select dept_name, avg(all salary), count(*) “number of employees"

  2. where deptno = dept_no

  3. and count(*) > 5

  4. group by dept_name

  5. order by 2 desc;


Correct Option: C
  1. a) CREATE OR REPLACE FUNCTION tax_amt (p_id NUMBER) RETURN NUMBER

  2. b) CREATE OR REPLACE PROCEDURE tax_amt (p_id NUMBER) RETURN NUMBER

  3. c) CREATE OR REPLACE PROCEDURE tax_amt (p_id NUMBER, p_amount OUT NUMBER)

  4. d) CREATE OR REPLACE FUNCTION tax_amt (p_id NUMBER) RETURN NUMBER(10,2)

  5. e) CREATE OR REPLACE PROCEDURE tax_amt (p_id NUMBER, p_amount OUT NUMBER(10, 2))


Correct Option: A,C

Examine this procedure: CREATE OR REPLACE PROCEDURE UPD_BAT_STAT (V_ID IN NUMBER DEFAULT 10, V_AB IN NUMBER DEFAULT 4) IS BEGIN UPDATE PLAYER_BAT_STAT SET AT_BATS = AT_BATS + V_AB WHERE PLAYER_ID = V_ID; COMMIT; END; Which two statements will successfully invoke this procedure in SQL *Plus? (Choose two)

  1. a) EXECUTE UPD_BAT_STAT;

  2. b) EXECUTE UPD_BAT_STAT(V_AB=>10, V_ID=>31);

  3. c) EXECUTE UPD_BAT_STAT(31, 'FOUR', 'TWO');

  4. d) UPD_BAT_STAT(V_AB=>10, V_ID=>31);

  5. e) RUN UPD_BAT_STAT;


Correct Option: A,B
  1. Examine this code: CREATE OR REPLACE PACKAGE comm_package IS g_comm NUMBER := 10; PROCEDURE reset_comm(p_comm IN NUMBER); END comm_package; / User Jones executes the following code at 9:01am: EXECUTE comm_package.g_comm := 15 User Smith executes the following code at 9:05am: EXECUTE comm_paclage.g_comm := 20 Which statement is true?
  1. a) g_comm has a value of 15 at 9:06am for Smith.

  2. b) g_comm has a value of 15 at 9:06am for Jones.

  3. c) g_comm has a value of 20 at 9:06am for both Jones and Smith.

  4. d) g_comm has a value of 15 at 9:03 am for both Jones and Smith.

  5. e) g_comm has a value of 10 at 9:06am for both Jones and Smith.


Correct Option: B

AI Explanation

To answer this question, let's analyze the provided code and the sequence of events:

The code defines a package named "comm_package" with a global variable "g_comm" initialized to 10 and a procedure "reset_comm" that takes a parameter "p_comm" of type NUMBER.

User Jones executes the following code at 9:01am:

EXECUTE comm_package.g_comm := 15;

This code attempts to assign a new value of 15 to the global variable "g_comm".

User Smith executes the following code at 9:05am:

EXECUTE comm_package.g_comm := 20;

This code also attempts to assign a new value of 20 to the global variable "g_comm".

Now let's evaluate each option to determine which one is true:

Option A) g_comm has a value of 15 at 9:06am for Smith. This option is incorrect because Smith's code executed at 9:05am, not 9:06am.

Option B) g_comm has a value of 15 at 9:06am for Jones. This option is correct. Since Jones executed the code at 9:01am to assign a value of 15 to g_comm, the value of g_comm will be 15 at 9:06am for Jones.

Option C) g_comm has a value of 20 at 9:06am for both Jones and Smith. This option is incorrect. Since Smith executed the code at 9:05am to assign a value of 20 to g_comm, the value of g_comm will be 20 at 9:06am for Smith, but Jones assigned a value of 15 to g_comm earlier, so it will not be 20 for Jones at 9:06am.

Option D) g_comm has a value of 15 at 9:03am for both Jones and Smith. This option is incorrect. Jones executed the code at 9:01am, not 9:03am.

Option E) g_comm has a value of 10 at 9:06am for both Jones and Smith. This option is incorrect. Both Jones and Smith executed code to assign different values to g_comm, so the value will not be 10 for either of them at 9:06am.

Therefore, the correct answer is: B) g_comm has a value of 15 at 9:06am for Jones.

Which two describe a stored procedure? (Choose two)

  1. a) A stored procedure is typically written in SQL.

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

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

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

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


Correct Option: B,C

AI Explanation

To answer this question, you need to understand what a stored procedure is. Let's go through each option to understand why it is correct or incorrect:

Option A) A stored procedure is typically written in SQL - This option is incorrect because a stored procedure can be written in various programming languages, not just SQL.

Option B) A stored procedure is a named PL/SQL block that can accept parameters - This option is correct. A stored procedure is a named block of code that can be executed in a database. It can accept parameters, which allows for flexibility and reusability.

Option C) A stored procedure is a type of PL/SQL subprogram that performs an action - This option is correct. A stored procedure is a type of subprogram in a database that performs a specific action or set of actions.

Option D) A stored procedure has three parts: the specification, the body, and the exception handler part - This option is incorrect. While a stored procedure can have multiple parts, such as a specification, body, and exception handler, it is not limited to just these three parts.

Option E) The executable section of a stored procedure contains statements that assigns values, control execution, and return values to the calling environment - This option is incorrect. While the executable section of a stored procedure can contain statements that assign values, control execution, and return values, it is not the only section of a stored procedure.

The correct answers are B) A stored procedure is a named PL/SQL block that can accept parameters and C) A stored procedure is a type of PL/SQL subprogram that performs an action. These options accurately describe the characteristics of a stored procedure.

Which type of argument passes a value from a procedure to the calling environment?

  1. a) VARCHAR2

  2. b) BOOLEAN

  3. c) OUT

  4. d) IN


Correct Option: C
Explanation:

To solve this question, the user needs to be familiar with the different types of arguments that can be passed between a procedure and the calling environment.

A. VARCHAR2 is a data type used to store character strings in Oracle.

B. BOOLEAN is a data type used to store logical values (TRUE or FALSE) in Oracle.

C. OUT is a parameter mode that is used to pass values from a procedure to the calling environment.

D. IN is a parameter mode that is used to pass values from the calling environment to a procedure.

Therefore, the correct answer is:

The Answer is: C

When creating a function in SQL *Plus, you receive this message: .Warning: Function created with compilation errors.. Which command can you issue to see the actual error message?

  1. a) SHOW FUNCTION_ERROR

  2. b) SHOW USER_ERRORS

  3. c) SHOW ERRORS

  4. d) SHOW ALL_ERRORS


Correct Option: C
Explanation:

To solve this question, the user needs to know how to check for the errors in an SQL function.

The correct answer is:

C. SHOW ERRORS

Explanation:

When a function is created with compilation errors, the SHOW ERRORS command can be issued to see the actual error message. This command displays the compilation errors of the last CREATE or REPLACE FUNCTION or PACKAGE statement that was executed in the current session. Using this command can help identify and fix any syntax errors or other issues with the function code.

Option A is incorrect because there is no SHOW FUNCTION_ERROR command in SQL *Plus.

Option B is incorrect because SHOW USER_ERRORS is not a valid command in SQL *Plus.

Option D is incorrect because SHOW ALL_ERRORS is not a valid command in SQL *Plus.

Given a function CALCTAX : CREATE OR REPLACE FUNCTION calc tax (sal NUMBER) RETURN NUMBER IS BEGIN RETURN (sal * 0.05); END; If you want to run the above function from the SQL *Plus prompt, which statement is true?

  1. a) You need to execute the command CALCTAX(1000); .

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

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

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

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


Correct Option: E

AI Explanation

To run the given function CALCTAX from the SQL *Plus prompt, you need to create a SQL *Plus environment variable X and issue the command EXECUTE :X := CALCTAX(1000);.

Let's go through each option to understand why it is correct or incorrect:

Option A) You need to execute the command CALCTAX(1000); - This option is incorrect because executing the function directly without assigning the result to a variable will not give you the desired output.

Option B) You need to execute the command EXECUTE FUNCTION calc tax; - This option is incorrect because the syntax of the EXECUTE command is incorrect. It should be EXECUTE ();.

Option C) You need to create a SQL *Plus environment variable X and issue the command :X := CALCTAX(1000); - This option is incorrect because the syntax of assigning a value to the variable X is incorrect. It should be X := ; instead of :X := ;.

Option D) You need to create a SQL *Plus environment variable X and issue the command EXECUTE :X := CALCTAX; - This option is incorrect because the function CALCTAX requires an input argument sal, which is missing in the EXECUTE command.

Option E) You need to create a SQL *Plus environment variable X and issue the command EXECUTE :X := CALCTAX(1000); - This option is correct because it correctly creates a SQL *Plus environment variable X and assigns the result of the function CALCTAX(1000) to X using the EXECUTE command.

The correct answer is option E.

  1. a) Local variables.

  2. b) Arguments.

  3. c) Boolean variables.

  4. d) Substitution variables.


Correct Option: B
Explanation:

When creating stored procedures and functions, the option that allows you to transfer values to and from the calling environment is:

B. Arguments.

Arguments, also known as parameters, are variables that are defined within a stored procedure or function and can be used to receive values from the calling environment. These values can be passed to the procedure or function when it is executed, and the procedure or function can also return values back to the calling environment using these arguments.

Option A, local variables, are variables defined within the scope of the procedure or function and are not used for transferring values to and from the calling environment.

Option C, boolean variables, are variables that can hold a true or false value and are not specifically designed for transferring values to and from the calling environment.

Option D, substitution variables, are variables used in SQL*Plus and Oracle SQL Developer tools and are not used for passing values to and from the calling environment in stored procedures or functions.

So, the correct answer is B. Arguments.

  1. a) When the procedure contains no SQL statements.

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

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

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


Correct Option: D
  1. a) PROCEDURE add_product (p_order_date DATE);

  2. b) PROCEDURE add_product (p_name VARCHER2, P_ORDERED DATE);

  3. c) PROCEDURE add_product (p_prodname VARCHER2, P_PRISE NUMBER);

  4. d) PROCEDURE add_product (p_prize NUMBER, P_DESCRIPTION VARCHER2);


Correct Option: D
  1. a) When declaring arguments length is not allowed.

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

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

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


Correct Option: A
  1. a) In the package body.

  2. b) In the data base triggers.

  3. c) In the package specification.

  4. d) In the procedures declare section using the exact name in each.


Correct Option: A

When using a packaged function in a query, what is true?

  1. a) The COMMIT and ROLLBACK commands are allowed in the packaged function.

  2. b) You can not use packaged functions in a query statement.

  3. c) The packaged function cannot execute an INSERT, UPDATE, or DELETE statement against the table that is being queried.

  4. d) The packaged function can execute and INSERT, UPDATE, or DELETE statement against the table that is being queried if it is used in a subquery.

  5. e) The packaged function can execute an INSERT, UPDATEM or DELETE statement against the table that is being queried if the pragma RESTRICT REFERENCE is used.


Correct Option: C

AI Explanation

To answer this question, you need to understand the concept of using packaged functions in a query.

Option A) The COMMIT and ROLLBACK commands are allowed in the packaged function - This option is incorrect. The COMMIT and ROLLBACK commands are not allowed in a packaged function. These commands are used to control transactional behavior, and they should be executed outside the packaged function.

Option B) You cannot use packaged functions in a query statement - This option is incorrect. Packaged functions can be used in a query statement.

Option C) The packaged function cannot execute an INSERT, UPDATE, or DELETE statement against the table that is being queried - This option is correct. Packaged functions are not allowed to execute INSERT, UPDATE, or DELETE statements against the table that is being queried. They are typically used for data retrieval or computation purposes.

Option D) The packaged function can execute an INSERT, UPDATE, or DELETE statement against the table that is being queried if it is used in a subquery - This option is incorrect. The packaged function cannot execute INSERT, UPDATE, or DELETE statements against the table that is being queried, regardless of whether it is used in a subquery or not.

Option E) The packaged function can execute an INSERT, UPDATE, or DELETE statement against the table that is being queried if the pragma RESTRICT REFERENCE is used - This option is incorrect. The pragma RESTRICT REFERENCE is used to restrict the use of certain database objects within a package. It does not allow the packaged function to execute INSERT, UPDATE, or DELETE statements against the table that is being queried.

Therefore, the correct answer is Option C. The packaged function cannot execute an INSERT, UPDATE, or DELETE statement against the table that is being queried.

  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;


Correct Option: B,E

Examine this procedure: CREATE OR REPLACE PROCEDURE ADD_PLAYER (V_ID IN NUMBER, V_LAST_NAME VARCHER2(30)) IS BEGIN INSERT INTO PLAYER(ID, LAST_NAME) VALUES(V_ID, V_LAST_NAME); COMMIT; END; Why does this command fail when executed?

  1. a) When declaring arguments length is not allowed.

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

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

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


Correct Option: A

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) When declaring arguments length is not allowed - This option is incorrect because in the given procedure, the length is specified for the VARCHAR2 argument V_LAST_NAME.

Option B) When declaring arguments each argument must have a mode specified - This option is incorrect because in the given procedure, the mode for each argument is not specified. However, the absence of a mode specification does not cause the command to fail.

Option C) When declaring arguments each argument must have a length specified - This option is incorrect because in the given procedure, the length is specified for the VARCHAR2 argument V_LAST_NAME.

Option D) When declaring a VARCHAR2 argument it must be specified - This option is incorrect because in the given procedure, the VARCHAR2 argument V_LAST_NAME is specified.

The correct answer is A) When declaring arguments length is not allowed. This option is correct because in the given procedure, the length is specified for the VARCHAR2 argument V_LAST_NAME, which is not allowed. The correct syntax for declaring a VARCHAR2 argument should be VARCHAR2(30).

Therefore, the command fails when executed due to the incorrect length specification for the VARCHAR2 argument.

How do you handle an Exception?

  1. a) Trap it with a Handler

  2. b) Propagate it to the Calling Environment

  3. c) a & then b

  4. d) b & then a


Correct Option: C

This statement fails when executed: CREATE OR REPLACE TRI GGER CALC_TEAM_AVG AFTER I NSERT ON PLAYER BEGIN INSERT INTO PLAYER_BATSTAT ( PLAYER_I D, SEASON_YEAR, AT_BATS, HI TS) VALUES ( : NEW. I D, 1 997, 0, 0) ; END; To which type must you convert the trigger to correct the error?

  1. a) Row

  2. b) Statement

  3. c) ORACLE FORM trigger

  4. d) Before


Correct Option: A

AI Explanation

To answer this question, we need to understand the different types of triggers in Oracle.

Option A) Row - This option is correct because the given trigger is an "AFTER INSERT" trigger, which is a row-level trigger. Row-level triggers fire once for each row that is affected by the triggering event. In this case, the trigger is fired after each row is inserted into the PLAYER table.

Option B) Statement - This option is incorrect because statement-level triggers fire once for each triggering event, regardless of the number of rows affected. Statement-level triggers are used with bulk operations or when you want to perform an action based on the entire set of affected rows.

Option C) ORACLE FORM trigger - This option is incorrect because Oracle Form triggers are specific to Oracle Forms, which is a development tool for creating GUI applications. Form triggers are not applicable in this scenario.

Option D) Before - This option is incorrect because "BEFORE INSERT" triggers are executed before the insert operation is performed. The given trigger is an "AFTER INSERT" trigger.

The correct answer is A) Row. This option is correct because the given trigger should be converted to a row-level trigger to fix the error.

- Hide questions