Take This Oracle PL/SQL Test

Reviewed by Editorial Team
The ProProfs editorial team is comprised of experienced subject matter experts. They've collectively created over 10,000 quizzes and lessons, serving over 100 million users. Our team includes in-house content moderators and subject matter experts, as well as a global network of rigorously trained contributors. All adhere to our comprehensive editorial guidelines, ensuring the delivery of high-quality content.
Learn about Our Editorial Process
| By Sudha_test
S
Sudha_test
Community Contributor
Quizzes Created: 12 | Total Attempts: 38,126
| Attempts: 4,636 | Questions: 40
Please wait...
Question 1 / 40
0 %
0/100
Score 0/100
1. IF in_val > 2000 THEN out_val = in_val + 1;       ELSIF in_val > 3000 THEN          out_val = in_val + 2;       ELSIF in_val > 4000 THEN out_val = in_val + 3; ELSE out_val = in_val + 4; END IF;     What is the out_val value, if the in_val is 2500?

Explanation

The value of out_val will be 2501 because the first condition (in_val > 2000) is true for the given input of 2500. Therefore, the code will execute the corresponding statement (out_val = in_val + 1) and assign the value of 2501 to out_val.

Submit
Please wait...
About This Quiz
Take This Oracle PL/SQL Test - Quiz

Are you familiar with PL/SQL in Oracle? Take this Oracle PL/SQL test and test your knowledge. If you learned Oracle, this quiz would be an easy one for... see moreyou. We have got a set of questions for your practice and knowledge-testing on PL/SQL in Oracle. Just go for it, and find out your results. Even if you are not sure about any of your answers, we will help you with the correct answer. All the best! Don't forget to share the quiz with other Oracle users. see less

2. How will u delete a trigger emp_trig permanently?

Explanation

The correct answer is "drop trigger emp_trig;". This is because the DROP TRIGGER statement is used to permanently delete a trigger from the database. In this case, it is specifically deleting the trigger named "emp_trig".

Submit
3. FOR I IN 1..6        LOOP INSERT INTO val_table(vcol)  VALUES(I); COMMIT; END LOOP; ROLLBACK; How many rows will be inserted after the execution of above PL/SQL?

Explanation

The given PL/SQL code uses a loop to insert values into the "val_table" table. The loop iterates from 1 to 6, so it will insert 6 rows into the table. After the loop, a COMMIT statement is executed, which saves the changes made by the INSERT statements. However, immediately after the COMMIT, a ROLLBACK statement is executed, which undoes all the changes made since the last COMMIT. Therefore, even though 6 rows were inserted, they will be rolled back and no rows will be permanently inserted into the table.

Submit
4. While attempting to create a package specification in SQL*Plus, you receive this error: Warning: Package created with compilation errors. Which command should you execute to see a more detailed error message?

Explanation

To see a more detailed error message when creating a package specification in SQL*Plus, you should execute the "show errors" command. This command will display the compilation errors that occurred during the creation of the package specification, allowing you to identify and address the specific issues causing the error.

Submit
5. What will be the value of a uninitialised but declared variable when it is first used in the executable section

Explanation

When an uninitialized but declared variable is first used in the executable section, its value will be NULL. This means that the variable does not have a specific value assigned to it yet. NULL is a special value in programming that represents the absence of a value or a null pointer. Therefore, when a variable is used without being assigned a value, it is considered NULL.

Submit
6. Declare           V_lower := 4;           V_upper := 4;        Begin             for i in V_lower .. V_upper loop                     ---------            End loop; end;    How many times does the loop execute?

Explanation

The loop executes only once because the lower and upper bounds of the loop (V_lower and V_upper) are both set to 4. Since the lower and upper bounds are the same, the loop will only iterate once.

Submit
7. How many min number of times a simple loop will execute?

Explanation

A simple loop will always execute at least once because the loop condition is checked at the end of each iteration. If the condition is not met initially, the loop will still execute once before terminating. Therefore, the minimum number of times a simple loop will execute is 1.

Submit
8. When handler can handel only system defined exceptions

Explanation

The given answer is False. This means that the statement "When handler can handle only system defined exceptions" is not true. In programming, a handler can handle both system-defined exceptions and user-defined exceptions. A handler is a block of code that is executed when an exception occurs, and it can be designed to handle any type of exception, regardless of whether it is a system-defined exception or a custom exception created by the programmer. Therefore, the statement is incorrect.

Submit
9. Create or replace procedure p1(a number default 12) as begin dbms_output.put_line('hi'); end; How does you execute the above procedure.

Explanation

To execute the above procedure, you can use the "exec p1" command. This command will execute the procedure and display the output "hi" using the dbms_output.put_line statement inside the procedure. The other option ":x := p1(10)" is not valid because it is attempting to assign a value to a variable, which is not necessary in this case. Therefore, the correct way to execute the procedure is by using the "exec p1" command.

Submit
10. WhT does the %rowcount return when no rows are returned by a select statement?

Explanation

When no rows are returned by a select statement, the %rowcount returns 0. This means that the select statement did not find any matching rows in the database.

Submit
11. . BEGIN FOR I in 1..10 LOOP If I=2 or I=4 Null; ELSE INSERT into easn(record) values (I); End if; Commit; END LOOP; ROLLBACK: END: How many values will have been inserted into easn table?

Explanation

The loop iterates from 1 to 10. If the value of I is 2 or 4, the loop will skip the insertion statement and move to the next iteration. For all other values of I, the INSERT statement will be executed, inserting the value of I into the easn table. Since the values 2 and 4 are skipped, there will be 8 values (1, 3, 5, 6, 7, 8, 9, 10) inserted into the easn table.

Submit
12. What type of cursor will u use when you use the cursor many times in the PL/SQL block with some different datas to be fetched depending upon differrent values

Explanation

When you need to use the cursor multiple times in a PL/SQL block with different data to be fetched depending on different values, you can use cursors with parameters. This allows you to pass different values to the cursor each time it is used, ensuring that the correct data is fetched based on the specified parameters. By using cursors with parameters, you can dynamically control the data retrieval process in your PL/SQL block.

Submit
13. In which situation you use make use of explicit cursor?

Explanation

When the select statement returns more than one row, it is necessary to use an explicit cursor. An explicit cursor allows the programmer to retrieve and manipulate multiple rows returned by a select statement. By using an explicit cursor, the programmer can fetch each row one by one and perform necessary operations on them. This is especially useful when dealing with complex queries that return multiple rows of data.

Submit
14. Trigger timing refers how many times trigger should fire

Explanation

The statement is incorrect. Trigger timing does not refer to how many times a trigger should fire. Instead, trigger timing refers to when a trigger should fire, such as before, after, or instead of a specific event or action.

Submit
15. Which of the following passes a value from the procedure to the calling environment?

Explanation

The keyword "out" is used in programming languages to pass a value from a procedure to the calling environment. When a parameter is defined as "out" in a procedure, it means that the procedure can modify the value of that parameter and the modified value will be reflected in the calling environment. This allows the procedure to pass back a value to the calling code. Therefore, "out" is the correct answer as it specifically deals with passing a value from the procedure to the calling environment.

Submit
16. Begin       ------      exception        when no_data_found           ----------        when value_error            ---------        when others            -----------      end;      if you encounter an error while dividing a number by zero, which exception handler will be executed?

Explanation

The "others" exception handler will be executed if an error occurs while dividing a number by zero. This handler is used to catch any exceptions that are not specifically handled by the other exception handlers in the code. Since there is no specific handler for the division by zero error (value_error) or any other specific error (no_data_found), the "others" handler will be executed in this case.

Submit
17. You need to create a PL/SQL program to insert records into employee table. Which block of code successfully uses the insert command?

Explanation

The block of code successfully uses the insert command because it declares a variable v_hiredate of type DATE and initializes it with the current date using the SYSDATE function. It then uses the INSERT INTO statement to insert a record into the emp table. It specifies the columns empnp, ename, and hiredate in the target table and provides values for these columns using the empno_sequence.nextval (to generate a unique empno), the variable name, and the variable v_hiredate. The code is enclosed within a BEGIN-END block, indicating the start and end of the PL/SQL program.

Submit
18. You need to create a trigger on the EMP table that monitors every row that is changed and places this information into the AUDIT_TABLE. What type of trigger do you create?

Explanation

The correct answer is "FOR EACH ROW trigger on the EMP table" because the question specifically mentions that the trigger should monitor every row that is changed in the EMP table and place that information into the AUDIT_TABLE. A FOR EACH ROW trigger is used to perform an action for each row affected by the triggering event, which in this case is a row being changed in the EMP table.

Submit
19. Which clause has to be used in the explicit cursor to lock the rows first?

Explanation

The FOR UPDATE OF clause has to be used in the explicit cursor to lock the rows first. This clause allows the cursor to lock the selected rows in a table, preventing other transactions from modifying them until the transaction is complete. It specifies the columns that will be updated in the locked rows. By using this clause, the cursor ensures that the rows it fetches are locked for exclusive use by the current transaction.

Submit
20. Which statement is true when writing a cursor FORloop?

Explanation

In a cursor FOR loop, you do not need to explicitly open, fetch, or close a cursor. The loop automatically opens the cursor, fetches the rows, and closes the cursor when all the rows have been processed. Therefore, the correct answer is that you do not explicitly open, fetch, or close a cursor within a cursor FOR loop.

Submit
21. Which statement about implicit cursors is true?

Explanation

Implicit cursors are automatically declared for all DML (Data Manipulation Language) and SELECT statements in PL/SQL. Programmers do not need to explicitly declare them using the cursor type in the declaration section. Additionally, programmers do not need to close implicit cursors before the end of the PL/SQL program.

Submit
22. DECLARE             V_NAME CONSTANT NUMBER(9);         What is the error with the above statment ?

Explanation

The correct answer is "Should initialize with value." In PL/SQL, when declaring a constant, it is mandatory to initialize it with a value. Therefore, the declaration of V_NAME constant without assigning a value to it is incorrect.

Submit
23. Which SQL  function can not be used in PL/SQL?

Explanation

The decode function is a SQL function that cannot be used in PL/SQL. PL/SQL is a procedural language used for writing Oracle database triggers, stored procedures, and functions. It has its own set of functions and syntax, and the decode function is not part of it. Therefore, the correct answer is decode.

Submit
24. Examine this code: CREATE OR REPLACE PACKAGE bonus IS g_max_bonus NUMBER := .99; FUNCTION calc_bonus (p_emp_id NUMBER) RETURN NUMBER; FUNCTION calc_salary (p_emp_id NUMBER) RETURN NUMBER; END; / CREATE OR REPLACE PACKAGE BODY bonus IS v_salary employees.salary%TYPE; v_bonus employees.commission_pct%TYPE; FUNCTION calc_bonus (p_emp_id NUMBER) RETURN NUMBER IS BEGIN SELECT salary, commission_pct INTO v_salary, v_bonus FROM employees WHERE employee_id = p_emp_id; RETURN v_bonus * v_salary; END calc_bonus FUNCTION calc_salary (p_emp_id NUMBER) RETURN NUMBER IS BEGIN SELECT salary, commission_pct INTO v_salary, v_bonus FROM employees WHERE employees RETURN v_bonus * v_salary + v_salary; END cacl_salary; END bonus; /   Which statement is true?

Explanation

The BONUS.CALC_SALARY packaged function can be called from a SELECT command against the EMPLOYEES table. This is because the function retrieves the salary and commission_pct values from the employees table and calculates the salary by multiplying the bonus and salary values. Therefore, it can be used in a SELECT statement to calculate and display the salary for a specific employee.

Submit
25. .which clause has to be used to reference the current row from an explicit cursor

Explanation

The "where current of" clause is used to reference the current row from an explicit cursor. This clause is used in conjunction with the UPDATE statement to specify that the update should be performed on the current row pointed to by the cursor. It is a way to uniquely identify and update the current row without having to specify any additional conditions or criteria.

Submit
26. Create or replace trigger emp_trig after update on emp begin insert into audit values(user,sysdate); end; an update statement on emp affects 100 rows. How many rows will be inserted into audit table after this trigger fires?

Explanation

The trigger is set to fire after an update on the "emp" table. Therefore, for each update statement on the "emp" table, only one row will be inserted into the "audit" table.

Submit
27. . What is the value of v_price if the following block is executed with v_value=250 declare v_value number(6,2); v_price number(6,2); begin if v_value>150 then v_price=2500; elsif v_value>200 then v_price=3500; elsif v_value>300 then v_price=4500; else v_price=null; end if;

Explanation

The value of v_price would be 2500 if the block is executed with v_value=250. This is because the condition v_value>150 is true, so the first branch of the if-else statement is executed and v_price is assigned the value of 2500.

Submit
28. Declare X NUMBER; V_SAL NUMBER; V_found VARCHAR2(10) := 'TRUE' Begin X:=1; V_SAL :=1000; Declare V_found VARCHAR2(10); Y NUMBER; Begin IF (V_sal>500) THEN V_found := 'YES'; END IF; DBMS_OUTPUT.PUT_LINE('value f V_found is' || V_found); DBMS_OUTPUT.PUT_LINE ('value f V_found is' || V_found); Y:20; END; DBMS_OUTPUT.PUT_LINE ('value f V_found is' || V_found); DBMS_OUTPUT.PUT_LINE ('value f Y is' || TO_CHAR (Y); END; Why does this code produce an error when executed?

Explanation

The code produces an error because variable Y is declared in the inner block and referenced in the outer block. In PL/SQL, variables declared in a block are only accessible within that block and any nested blocks within it. So, when the code tries to reference the variable Y in the outer block, it results in an error because Y is not declared in the outer block.

Submit
29. You want to create a cursor that can be used several times in a block. Selecting a different active set each time that it is opened. Which type of cursor do you create?

Explanation

A cursor that uses parameters allows for the creation of a cursor that can be used multiple times in a block, with the ability to select a different active set each time it is opened. By using parameters, the cursor can be dynamically modified to retrieve different data sets based on the specified parameters, providing flexibility and reusability in the code.

Submit
30. Given the executable section of a PL/SQL block FOR employee_record IN Salary_Cursor Loop employee_id_table (employee_id):=employee_record.last_name; END Loop;  Close Salary_Cursor; END; Why does this section cause an error?

Explanation

The section causes an error because the cursor does not need to be explicitly closed. In PL/SQL, cursors are automatically closed when the block ends. Therefore, attempting to close the cursor explicitly will result in an error.

Submit
31. In which section of a PL/SQL block is a user defined exception raised?

Explanation

In a PL/SQL block, a user-defined exception is raised in the executable section. This section contains the actual code and logic of the program where the exception can be raised. The executable section is where the program performs its tasks and executes statements, and it is within this section that the user-defined exception can be triggered based on certain conditions or events.

Submit
32. Examine this function:   CREATE OR REPLACE FUNCTION CALC_PLAYER_AVG (V_ID in PLAYER_BAT_STAT.PLAYER_ID%TYPE) RETURN NUMBER IS V_AVG NUMBER; BEGIN SELECT HITS / AT_BATS INTO V_AVG FROM PLAYER_BAT_STAT WHERE PLAYER_ID = V_ID; RETURN (V_AVG); END;   Which statement will successfully invoke this function in SQL *Plus?

Explanation

The correct statement to successfully invoke this function in SQL *Plus is "SELECT CALC_PLAYER_AVG(PLAYER_ID) FROM PLAYER_BAT_STAT;". This statement calls the function CALC_PLAYER_AVG and passes the PLAYER_ID column from the table PLAYER_BAT_STAT as the argument. It will return the average calculated by the function for each player in the table.

Submit
33. Explict cursor has to fectch at least one row

Explanation

An explicit cursor does not have to fetch at least one row. It can be used to fetch multiple rows or no rows at all, depending on the conditions specified in the cursor query. The explicit cursor allows the programmer to have more control over the fetching process and can be used to fetch specific rows based on certain criteria. Therefore, the statement "explicit cursor has to fetch at least one row" is false.

Submit
34. Begin declare    a number:=56;    b number:=0;    c number; begin   c:=a/b; dbms_output.put_line('hi'); exception when zero_divide then dbms_output.put_line('error'); raise; end; exception when others then dbms_output.put_line('error2'); end; what is the output

Explanation

The code snippet declares three variables, "a" with a value of 56, "b" with a value of 0, and "c" without an initial value. It then attempts to divide "a" by "b", which is a division by zero error. This error is caught in the first exception block, where it prints "error" and raises the exception again. After that, the code falls into the second exception block and prints "error2". Therefore, the output of this code would be "errorerror2".

Submit
35. 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)

Explanation

The first valid call to the add_dept procedure is add_dept; which uses the default values for both parameters. The second valid call is add_dept('Accounting'); which specifies a value for the p_dept_name parameter and uses the default value for the p_location parameter. The third valid call is add_dept(p_location=>'New York); which specifies a value for the p_location parameter using named notation.

Submit
36. Which determines the no of times a trigger is fired?

Explanation

The correct answer is "trigger type." The trigger type determines the number of times a trigger is fired. Different trigger types have different firing behaviors, such as firing once per record or firing multiple times per record. The trigger type is an important factor in controlling the execution and timing of triggers in a system.

Submit
37. For loop counter variable can be referenced in inside as assignment target

Explanation

The statement is false because in a for loop, the counter variable is only accessible within the loop itself and cannot be referenced outside of it. Once the loop is completed, the counter variable is no longer accessible or usable.

Submit
38. What are the  common oracle predefined exceptions that occur while executing select statements?

Explanation

The common Oracle predefined exceptions that occur while executing select statements are "no_data_found" and "too_many_rows". The "no_data_found" exception is raised when a select statement does not return any rows. The "too_many_rows" exception is raised when a select statement returns more than one row.

Submit
39. Declare   r1 Exception; begin   raise r1; exception  when r1 then  raise_application_error(-22221,'error1') ; end; What is the output?

Explanation

The given code snippet raises a syntax error. In the "raise" statement, the variable "r1" is being raised, but it has not been declared or assigned a value. Therefore, the code is not valid and will throw a syntax error.

Submit
40. In a pl/sql loop,you need to find whether a sql statement has  fetched rows successfully.Which cursor attibute will you use?

Explanation

In a PL/SQL loop, you can use the cursor attribute sql%rowcount to determine whether a SQL statement has fetched rows successfully. The sql%rowcount attribute returns the number of rows affected by the most recent SQL statement. If it returns a value greater than zero, it means that rows have been fetched successfully. Another cursor attribute sql%found can also be used to check if any rows have been fetched. However, the other options sql%isopen and "you cannot use cursor attributes for PL/SQL loops" are incorrect explanations.

Submit
View My Results

Quiz Review Timeline (Updated): Aug 22, 2023 +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Aug 22, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Dec 23, 2010
    Quiz Created by
    Sudha_test
Cancel
  • All
    All (40)
  • Unanswered
    Unanswered ()
  • Answered
    Answered ()
IF in_val > 2000 THEN...
How will u delete a trigger emp_trig permanently?
FOR I IN 1..6 ...
While attempting to create a package specification in SQL*Plus, you...
What will be the value of a uninitialised but declared variable when...
Declare ...
How many min number of times a simple loop will execute?
When handler can handel only system defined exceptions
Create or replace procedure p1(a number default 12) ...
WhT does the %rowcount return when no rows are returned by a select...
. BEGIN...
What type of cursor will u use when you use the cursor many times in...
In which situation you use make use of explicit cursor?
Trigger timing refers how many times trigger should fire
Which of the following passes a value from the procedure to the...
Begin ...
You need to create a PL/SQL program to insert records into employee...
You need to create a trigger on the EMP table that monitors every row...
Which clause has to be used in the explicit cursor to lock the rows...
Which statement is true when writing a cursor FORloop?
Which statement about implicit cursors is true?
DECLARE ...
Which SQL  function can not be used in PL/SQL?
Examine this code:...
.which clause has to be used to reference the current row from an...
Create or replace trigger emp_trig after update on emp...
. What is the value of v_price if the following block is executed with...
Declare...
You want to create a cursor that can be used several times in a block....
Given the executable section of a PL/SQL block...
In which section of a PL/SQL block is a user defined exception raised?
Examine this function: ...
Explict cursor has to fectch at least one row
Begin ...
Examine this code:...
Which determines the no of times a trigger is fired?
For loop counter variable can be referenced in inside as assignment...
What are the  common oracle predefined exceptions that occur ...
Declare ...
In a pl/sql loop,you need to find whether a sql statement has ...
Alert!

Advertisement