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

Which two program declarations are correct for a stored program unit? (Choose two)

  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

AI Explanation

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

Option A) a) CREATE OR REPLACE FUNCTION tax_amt (p_id NUMBER) RETURN NUMBER - This option is correct because it declares a stored function named "tax_amt" that takes a parameter "p_id" of type NUMBER and returns a value of type NUMBER.

Option B) b) CREATE OR REPLACE PROCEDURE tax_amt (p_id NUMBER) RETURN NUMBER - This option is incorrect because it declares a stored procedure, not a function. The keyword "RETURN NUMBER" is not applicable for a procedure declaration.

Option C) c) CREATE OR REPLACE PROCEDURE tax_amt (p_id NUMBER, p_amount OUT NUMBER) - This option is correct because it declares a stored procedure named "tax_amt" that takes two parameters "p_id" and "p_amount". The "p_amount" parameter is an OUT parameter, which means it will be used to return a value.

Option D) d) CREATE OR REPLACE FUNCTION tax_amt (p_id NUMBER) RETURN NUMBER(10,2) - This option is incorrect because it declares a stored function with a return type of NUMBER(10,2), which is not valid syntax. The return type should be just NUMBER without any precision or scale specified.

Option E) e) CREATE OR REPLACE PROCEDURE tax_amt (p_id NUMBER, p_amount OUT NUMBER(10, 2)) - This option is incorrect because it declares a stored procedure with an OUT parameter "p_amount" of type NUMBER(10, 2), which is not valid syntax. The parameter type should be just NUMBER without any precision or scale specified.

The correct answers are A) CREATE OR REPLACE FUNCTION tax_amt (p_id NUMBER) RETURN NUMBER and C) CREATE OR REPLACE PROCEDURE tax_amt (p_id NUMBER, p_amount OUT NUMBER). These options correctly declare a stored function and a stored procedure, respectively.

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.

  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

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.

  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

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.

When creating store procedures and functions which construct allows you to transfer values to and from the calling environment?

  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.

Under which situation do you create a server side procedure?

  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

AI Explanation

To answer this question, you need to understand the concept of server-side procedures. Let's go through each option to understand why it is correct or incorrect:

Option A) When the procedure contains no SQL statements. This option is incorrect because server-side procedures often contain SQL statements to interact with the database.

Option B) When the procedure contains no PL/SQL commands. This option is incorrect because PL/SQL is a programming language used for writing server-side procedures. Therefore, a server-side procedure would typically contain PL/SQL commands.

Option C) When the procedure needs to be used by many client applications accessing several remote databases. This option is incorrect because the situation described here relates to a distributed database environment, where multiple remote databases are accessed by client applications. In this case, you would create a distributed database architecture, not necessarily a server-side procedure.

Option D) When the procedure needs to be used by many users accessing the same schema objects on a local database. This option is correct because a server-side procedure is typically created when multiple users need to access the same schema objects on a local database. In this scenario, a server-side procedure provides a centralized and efficient way to manage and execute common tasks or operations.

The correct answer is Option D. This option is correct because it accurately describes the situation where you would create a server-side procedure.

The PROCEDURE_ADD_PRODUCT is defined within a package specifications as follows: PROCEDURE_ADD_PRODUCT (P_PRODNO NUMBER,P_PRODNAME VARCHER2); Which procedure declaration can’t be added to package specifications?

  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

AI Explanation

To determine which procedure declaration can't be added to the package specifications, let's go through each option:

Option A) PROCEDURE add_product (p_order_date DATE); This option is a valid procedure declaration. It takes a parameter "p_order_date" of type DATE.

Option B) PROCEDURE add_product (p_name VARCHER2, P_ORDERED DATE); This option is a valid procedure declaration. It takes two parameters: "p_name" of type VARCHAR2 and "p_ordered" of type DATE.

Option C) PROCEDURE add_product (p_prodname VARCHER2, P_PRISE NUMBER); This option is a valid procedure declaration. It takes two parameters: "p_prodname" of type VARCHAR2 and "p_prise" of type NUMBER.

Option D) PROCEDURE add_product (p_prize NUMBER, P_DESCRIPTION VARCHER2); This option is not a valid procedure declaration. There is a typo in the parameter declaration. Instead of "VARCHAR2", it is written as "VARCHER2".

Therefore, the correct answer is D) PROCEDURE add_product (p_prize NUMBER, P_DESCRIPTION VARCHER2), as it contains an incorrect parameter declaration.

  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

The ADD_PLAYER, UPD_PLAYER_STAT and UPD_PITCHER_STAT procedures are grouped together in a package. A variable must be shared among only these procedures. Where should you declare this variable?

  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

AI Explanation

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

Option A) In the package body - This option is correct because declaring the variable in the package body ensures that it is shared among only the procedures contained within the package. The package body is where the implementation details of the package are defined, and any variables declared in the package body are accessible to all the procedures within the package.

Option B) In the database triggers - This option is incorrect because database triggers are not within the scope of the package. Triggers are separate database objects that are used to automatically execute code in response to specific events, such as insert, update, or delete operations on a table. Variables declared in triggers are not accessible within the package procedures.

Option C) In the package specification - This option is incorrect because the package specification defines the interface of the package, including the public procedures, functions, and types that can be accessed from outside the package. Variables declared in the package specification are accessible to other programs or packages that use the package, but not specifically to the procedures within the package.

Option D) In the procedures declare section using the exact name in each - This option is incorrect because declaring the same variable with the exact name in each procedure would create separate and independent variables within each procedure. These variables would not be shared among the procedures and would not serve the purpose of having a variable shared among only these procedures.

The correct answer is A) In the package body. This option is correct because declaring the variable in the package body ensures that it is shared among only the procedures contained within the package.

  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

All users currently have the INSERT privileges on the PLAYER table. You want only your users to insert into this table using the ADD_PLAYER procedure. Which two actions must you take? (Choose two)

  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

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