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
  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.

Examine this code: CREATE OR REPLACE PRODECURE add_dept (p_dept_name VARCHAR2 DEFAULT 'placeholder', p_location VARCHAR2 DEFAULT 'Boston') IS BEGIN INSERT INTO departments VALUES (dept_id_seq.NEXTVAL, p_dept_name, p_location); END add_dept; / Which three are valid calls to the add_dep procedure ? (Choose three)

  1. a) add_dept;

  2. b) add_dept( .Accounting .);

  3. c) add_dept(, .New York .);

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


Correct Option: A,B,D

AI Explanation

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

Option A) add_dept; - This option is a valid call to the add_dept procedure. It does not provide any arguments, so the procedure will use the default values for p_dept_name and p_location.

Option B) add_dept( .Accounting .); - This option is a valid call to the add_dept procedure. It provides the argument p_dept_name with the value "Accounting" and uses the default value for p_location.

Option C) add_dept(, .New York .); - This option is an invalid call to the add_dept procedure. It is missing the p_dept_name argument and includes an extra comma. The correct syntax should be add_dept('New York').

Option D) add_dept(p_location=> .New York .); - This option is a valid call to the add_dept procedure. It provides the argument p_location with the value "New York" and uses the default value for p_dept_name.

Therefore, the three valid calls to the add_dept procedure are:

A) add_dept; B) add_dept('Accounting'); D) add_dept(p_location=>'New York');

The correct answer is options A, B, and D.

  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

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 examine each option to understand why it is correct or incorrect:

Option A) When declaring arguments length is not allowed - This option is incorrect because the length is allowed when declaring arguments in a procedure.

Option B) When declaring arguments each argument must have a mode specified - This option is incorrect because it is a valid requirement to specify the mode (IN, OUT, or IN OUT) for each argument when declaring a procedure. However, the given procedure does not specify the mode for the arguments, but this is not the reason why the command fails.

Option C) When declaring arguments each argument must have a length specified - This option is incorrect because it is not necessary to specify the length for every argument when declaring a procedure. The length is only required for certain data types, such as VARCHAR2 or RAW.

Option D) When declaring a VARCHAR2 argument it must be specified - This option is incorrect because it is not necessary to specify the VARCHAR2 data type when declaring a procedure. The data type can be specified as VARCHAR2 or VARCHAR, and both are valid.

The correct answer is A) When declaring arguments length is not allowed. This option is correct because in the given procedure, the V_LAST_NAME parameter is missing the length specification for the VARCHAR2 data type. The correct declaration should be V_LAST_NAME VARCHAR2(30) to specify the length.

Therefore, the command fails because the declaration of the V_LAST_NAME parameter is missing the length specification.

  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
  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
  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
  1. Examine this package body: CREATE OR REPLACE PACKAGE BODY forward_pack IS V_sum NUMBER; - 44 - PROCEDURE calc_ord(. . . ); PROCEDURE generate_summary(. . . ) IS BEGIN Calc_ord(. . . ); . . . END calc_ord; END forward_pack; / Which construct has a forward declaration?
  1. a) V_SUM

  2. b) CALC_ORD.

  3. c) FORWARD_PACK

  4. d) GENERATE_SUMMARY.


Correct Option: B

AI Explanation

To answer this question, let's go through each option to understand which construct has a forward declaration:

Option A) V_SUM - This option does not have a forward declaration. V_SUM is a variable declaration and does not require a forward declaration.

Option B) CALC_ORD - This option has a forward declaration. The PROCEDURE calc_ord is declared in the package body, but its full implementation is not provided in the given code. This indicates that there is a forward declaration for the calc_ord procedure.

Option C) FORWARD_PACK - This option does not have a forward declaration. FORWARD_PACK is the name of the package body itself and does not require a forward declaration.

Option D) GENERATE_SUMMARY - This option does not have a forward declaration. GENERATE_SUMMARY is a procedure declared and implemented within the package body, so it does not need a forward declaration.

The correct answer is Option B) CALC_ORD. This option has a forward declaration because the PROCEDURE calc_ord is declared without its full implementation in the given code.

  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) 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