Tuesday, March 4, 2008

PL/SQL Interview Questions

Sponsored links

SQL / PL SQL Questions
How do you convert a date to a string?What is an aggregate function?What is the dual table?What are cursors? Distinguish between implicit and explict cursors?Explain how cursors are used by Oracle?What is PL/SQL? Describe the block structure of PL/SQL?What is a nested subquery?What are the various types of queries ?Which of the following is not a schema object : Index, table, public synonym, trigger and package ?What is dynamic sql in oracle?What is the difference between a package, procedure and functionWhat is the difference between delete, drop and truncating a tableHow many triggers are supported in OracleAre you aware of FLASHBACK concept ? What is it?Describe oracle’s logical and physical structure?What is data dictionaryWhat is the use of control filesHow would store XML data in table ? What data type would be used for the columns?Difference between post and commit?Difference between commit and rollback?What are savepoints?Difference between a View and SynonymHow would you fetch system date from oracleWhat is the difference between primary key, unique key, foreign key?What is the difference between NO DATA FOUND and %NOTFOUNDWhat is cursor for loopWhat are cursor attributesWhat will you use in Query : IN or EXISTS? WhyExplain the difference between a data block, an extent and a segment.What's the difference between logical and physical I/O?What is an anonymous block?What is a PL/SQL collection?How can you tell if an UPDATE updated no rowsHow can you tell if a SELECT returned no rowsDB concepts:Physical Database Structure1. Datafiles2. Redo log files3. Control files.Logical Structures1. TableSpaces2. DB Schema Objects.Segments,Extents and Data BlocksOracle background processes1. PMON2.SMON3.DBWR4.LGWR5.ARCH6.RECOA synonym is an alias for a table, view, sequence, create public synonyms that make the base schema object available for general, system-wide use by any database user.Indexes are created to increase the performance of data retrieval

PL/SQL interview qiuestions
Which of the following statements is true about implicit cursors?
Implicit cursors are used for SQL statements that are not named.
Developers should use implicit cursors with great care.
Implicit cursors are used in cursor for loops to handle data processing.
Implicit cursors are no longer a feature in Oracle.
Which of the following is not a feature of a cursor FOR loop?
Record type declaration.
Opening and parsing of SQL statements.
Fetches records from cursor.
Requires exit condition to be defined.
A developer would like to use referential datatype declaration on a variable. The variable name is EMPLOYEE_LASTNAME, and the corresponding table and column is EMPLOYEE, and LNAME, respectively. How would the developer define this variable using referential datatypes?
Use employee.lname%type.
Use employee.lname%rowtype.
Look up datatype for EMPLOYEE column on LASTNAME table and use that.
Declare it to be type LONG.
Which three of the following are implicit cursor attributes?
%found
%too_many_rows
%notfound
%rowcount
%rowtype
If left out, which of the following would cause an infinite loop to occur in a simple loop?
LOOP
END LOOP
IF-THEN
EXIT
Which line in the following statement will produce an error?
cursor action_cursor is
select name, rate, action
into action_record
from action_table;
There are no errors in this statement.
The command used to open a CURSOR FOR loop is
open
fetch
parse
None, cursor for loops handle cursor opening implicitly.
What happens when rows are found using a FETCH statement
It causes the cursor to close
It causes the cursor to open
It loads the current row values into variables
It creates the variables to hold the current row values
Read the following code:10. CREATE OR REPLACE PROCEDURE find_cpt11. (v_movie_id {Argument Mode} NUMBER, v_cost_per_ticket {argument mode} NUMBER)12. IS13. BEGIN14. IF v_cost_per_ticket > 8.5 THEN15. SELECT cost_per_ticket16. INTO v_cost_per_ticket17. FROM gross_receipt18. WHERE movie_id = v_movie_id;19. END IF;20. END;
Which mode should be used for V_COST_PER_TICKET?
IN
OUT
RETURN
IN OUT
Read the following code:22. CREATE OR REPLACE TRIGGER update_show_gross23. {trigger information}24. BEGIN25. {additional code}26. END;
The trigger code should only execute when the column, COST_PER_TICKET, is greater than $3. Which trigger information will you add?
WHEN (new.cost_per_ticket > 3.75)
WHEN (:new.cost_per_ticket > 3.75
WHERE (new.cost_per_ticket > 3.75)
WHERE (:new.cost_per_ticket > 3.75)
What is the maximum number of handlers processed before the PL/SQL block is exited when an exception occurs?
Only one
All that apply
All referenced
None
For which trigger timing can you reference the NEW and OLD qualifiers?
Statement and Row
Statement only
Row only
Oracle Forms trigger
Read the following code:30. CREATE OR REPLACE FUNCTION get_budget(v_studio_id IN NUMBER)31. RETURN number IS32. 33. v_yearly_budget NUMBER;34. 35. BEGIN36. SELECT yearly_budget37. INTO v_yearly_budget38. FROM studio39. WHERE id = v_studio_id;40. 41. RETURN v_yearly_budget;42. END;
Which set of statements will successfully invoke this function within SQL*Plus?
VARIABLE g_yearly_budget NUMBEREXECUTE g_yearly_budget := GET_BUDGET(11);
VARIABLE g_yearly_budget NUMBEREXECUTE :g_yearly_budget := GET_BUDGET(11);
VARIABLE :g_yearly_budget NUMBEREXECUTE :g_yearly_budget := GET_BUDGET(11);
VARIABLE g_yearly_budget NUMBER:g_yearly_budget := GET_BUDGET(11); 43. CREATE OR REPLACE PROCEDURE update_theater44. (v_name IN VARCHAR v_theater_id IN NUMBER) IS45. BEGIN46. UPDATE theater47. SET name = v_name48. WHERE id = v_theater_id;49. END update_theater;
50. When invoking this procedure, you encounter the error:ORA-000: Unique constraint(SCOTT.THEATER_NAME_UK) violated.
How should you modify the function to handle this error?
An user defined exception must be declared and associated with the error code and handled in the EXCEPTION section.
Handle the error in EXCEPTION section by referencing the error code directly.
Handle the error in the EXCEPTION section by referencing the UNIQUE_ERROR predefined exception.
Check for success by checking the value of SQL%FOUND immediately after the UPDATE statement.
Read the following code:52. CREATE OR REPLACE PROCEDURE calculate_budget IS53. v_budget studio.yearly_budget%TYPE;54. BEGIN55. v_budget := get_budget(11);56. IF v_budget < 3000057. THEN58. set_budget(11,30000000);59. END IF;60. END;
You are about to add an argument to CALCULATE_BUDGET. What effect will this have?
The GET_BUDGET function will be marked invalid and must be recompiled before the next execution.
The SET_BUDGET function will be marked invalid and must be recompiled before the next execution.
Only the CALCULATE_BUDGET procedure needs to be recompiled.
All three procedures are marked invalid and must be recompiled.
Which procedure can be used to create a customized error message?
RAISE_ERROR
SQLERRM
RAISE_APPLICATION_ERROR
RAISE_SERVER_ERROR
The CHECK_THEATER trigger of the THEATER table has been disabled. Which command can you issue to enable this trigger?
ALTER TRIGGER check_theater ENABLE;
ENABLE TRIGGER check_theater;
ALTER TABLE check_theater ENABLE check_theater;
ENABLE check_theater;
Examine this database trigger64. CREATE OR REPLACE TRIGGER prevent_gross_modification65. {additional trigger information}66. BEGIN67. IF TO_CHAR(sysdate, DY) = MON68. THEN69. RAISE_APPLICATION_ERROR(-20000,Gross receipts cannot be deleted on Monday);70. END IF;71. END;
This trigger must fire before each DELETE of the GROSS_RECEIPT table. It should fire only once for the entire DELETE statement. What additional information must you add?
BEFORE DELETE ON gross_receipt
AFTER DELETE ON gross_receipt
BEFORE (gross_receipt DELETE)
FOR EACH ROW DELETED FROM gross_receipt
Examine this function:73. CREATE OR REPLACE FUNCTION set_budget74. (v_studio_id IN NUMBER, v_new_budget IN NUMBER) IS75. BEGIN76. UPDATE studio77. SET yearly_budget = v_new_budget78. WHERE id = v_studio_id;79. 80. IF SQL%FOUND THEN81. RETURN TRUEl;82. ELSE83. RETURN FALSE;84. END IF;85. 86. COMMIT;87. END;
Which code must be added to successfully compile this function?
Add RETURN right before the IS keyword.
Add RETURN number right before the IS keyword.
Add RETURN boolean right after the IS keyword.
Add RETURN boolean right before the IS keyword.
Under which circumstance must you recompile the package body after recompiling the package specification?
Altering the argument list of one of the package constructs
Any change made to one of the package constructs
Any SQL statement change made to one of the package constructs
Removing a local variable from the DECLARE section of one of the package constructs
Procedure and Functions are explicitly executed. This is different from a database trigger. When is a database trigger executed?
When the transaction is committed
During the data manipulation statement
When an Oracle supplied package references the trigger
During a data manipulation statement and when the transaction is committed
Which Oracle supplied package can you use to output values and messages from database triggers, stored procedures and functions within SQL*Plus?
DBMS_DISPLAY
DBMS_OUTPUT
DBMS_LIST
DBMS_DESCRIBE
What occurs if a procedure or function terminates with failure without being handled?
Any DML statements issued by the construct are still pending and can be committed or rolled back.
Any DML statements issued by the construct are committed
Unless a GOTO statement is used to continue processing within the BEGIN section, the construct terminates.
The construct rolls back any DML statements issued and returns the unhandled exception to the calling environment.
Examine this code93. BEGIN94. theater_pck.v_total_seats_sold_overall := theater_pck.get_total_for_year;95. END;
For this code to be successful, what must be true?
Both the V_TOTAL_SEATS_SOLD_OVERALL variable and the GET_TOTAL_FOR_YEAR function must exist only in the body of the THEATER_PCK package.
Only the GET_TOTAL_FOR_YEAR variable must exist in the specification of the THEATER_PCK package.
Only the V_TOTAL_SEATS_SOLD_OVERALL variable must exist in the specification of the THEATER_PCK package.
Both the V_TOTAL_SEATS_SOLD_OVERALL variable and the GET_TOTAL_FOR_YEAR function must exist in the specification of the THEATER_PCK package.
A stored function must return a value based on conditions that are determined at runtime. Therefore, the SELECT statement cannot be hard-coded and must be created dynamically when the function is executed. Which Oracle supplied package will enable this feature?
DBMS_DDL
DBMS_DML
DBMS_SYN
DBMS_SQL

0 comments: