You are on page 1of 13

PL/SQL interview questions

1. Which of the following statements is true about implicit
cursors?
1. Implicit cursors are used for SQL statements that are not
named.
2. Developers should use implicit cursors with great care.
3. Implicit cursors are used in cursor for loops to handle data
processing.
4. Implicit cursors are no longer a feature in Oracle.

2. Which of the following is not a feature of a cursor FOR loop?
1. Record type declaration.
2. Opening and parsing of SQL statements.
3. Fetches records from cursor.
4. Requires exit condition to be defined.

3. 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?
1. Use employee.lname%type.
2. Use employee.lname%rowtype.
3. Look up datatype for EMPLOYEE column on LASTNAME table and
use that.
4. Declare it to be type LONG.

4. Which three of the following are implicit cursor attributes?
1. %found
2. %too_many_rows
3. %notfound
4. %rowcount
5. %rowtype

5. If left out, which of the following would cause an infinite loop
to occur in a simple loop?
1. LOOP
2. END LOOP
3. IF-THEN
4. EXIT

6. Which line in the following statement will produce an error?
1. cursor action_cursor is
2. select name, rate, action
3. into action_record
4. from action_table;

parse 4. It causes the cursor to open 3. It causes the cursor to close 2. cursor for loops handle cursor opening implicitly. It creates the variables to hold the current row values 9. Read the following code: 10.5 THEN 15. SELECT cost_per_ticket 16. 8. END. 20. CREATE OR REPLACE TRIGGER update_show_gross 23. FROM gross_receipt 18. It loads the current row values into variables 4. IN 2. {trigger information} 24. What happens when rows are found using a FETCH statement 1. v_cost_per_ticket {argument mode} NUMBER) 12. OUT 3. 7. Which mode should be used for V_COST_PER_TICKET? 1. BEGIN 14. BEGIN 25. Which trigger information will you add? . (v_movie_id {Argument Mode} NUMBER. 5. INTO v_cost_per_ticket 17. IS 13. IF v_cost_per_ticket > 8. open 2. Read the following code: 22. RETURN 4. The command used to open a CURSOR FOR loop is 1. 19. is greater than $3. None. WHERE movie_id = v_movie_id. END. The trigger code should only execute when the column. There are no errors in this statement. {additional code} 26. COST_PER_TICKET. CREATE OR REPLACE PROCEDURE find_cpt 11. IN OUT 21. fetch 3. END IF.

For which trigger timing can you reference the NEW and OLD qualifiers? 1. CREATE OR REPLACE FUNCTION get_budget(v_studio_id IN NUMBER) RETURN number IS v_yearly_budget NUMBER.cost_per_ticket > 3. Row only 4. Oracle Forms trigger 29. WHERE (:new. WHEN (:new. VARIABLE g_yearly_budget NUMBER EXECUTE g_yearly_budget := GET_BUDGET(11). Statement and Row 2. None 28. .cost_per_ticket > 3. RETURN v_yearly_budget. BEGIN SELECT yearly_budget INTO v_yearly_budget FROM studio WHERE id = v_studio_id.cost_per_ticket > 3. Read the following code: 30.cost_per_ticket > 3.75) 27. Only one 2. END.75) 2. What is the maximum number of handlers processed before the PL/SQL block is exited when an exception occurs? 1. Which set of statements will successfully invoke this function within SQL*Plus? 1. 1. All referenced 4. Statement only 3.75) 4. WHEN (new. All that apply 3. WHERE (new.75 3.

BEGIN 43. You are about to add an argument to CALCULATE_BUDGET. 47. Read the following code: 40. 37.THEATER_NAME_UK) violated. An user defined exception must be declared and associated with the error code and handled in the EXCEPTION section. v_budget studio. IF v_budget < 30000 45. What effect will this have? 1. VARIABLE g_yearly_budget NUMBER :g_yearly_budget := GET_BUDGET(11). WHERE id = v_theater_id. 3. 44. 39. set_budget(11. CREATE OR REPLACE PROCEDURE calculate_budget IS 41. . 2. 4. How should you modify the function to handle this error? 1. 31. VARIABLE g_yearly_budget NUMBER EXECUTE :g_yearly_budget := GET_BUDGET(11). END. VARIABLE :g_yearly_budget NUMBER EXECUTE :g_yearly_budget := GET_BUDGET(11). Handle the error in the EXCEPTION section by referencing the UNIQUE_ERROR predefined exception. 4. Check for success by checking the value of SQL%FOUND immediately after the UPDATE statement. SET name = v_name 36. The GET_BUDGET function will be marked invalid and must be recompiled before the next execution. THEN 46. v_budget := get_budget(11). you encounter the error: ORA-000: Unique constraint(SCOTT.yearly_budget%TYPE. END IF. 42. BEGIN 34. Handle the error in EXCEPTION section by referencing the error code directly. 2. END update_theater. 38. UPDATE theater 35. 48. (v_name IN VARCHAR v_theater_id IN NUMBER) IS 33.30000000). CREATE OR REPLACE PROCEDURE update_theater 32. When invoking this procedure. 3.

END IF. SQLERRM 3. RAISE_SERVER_ERROR 50. 2. 58. v_new_budget IN NUMBER) IS 63. FOR EACH ROW DELETED FROM gross_receipt 60. RAISE_ERROR 2. CREATE OR REPLACE FUNCTION set_budget 62. 59.Gross receipts cannot be deleted on Monday). The CHECK_THEATER trigger of the THEATER table has been disabled. UPDATE studio 65. 51. 4. ENABLE TRIGGER check_theater. RAISE_APPLICATION_ERROR(-20000. ALTER TABLE check_theater ENABLE check_theater. CREATE OR REPLACE TRIGGER prevent_gross_modification 53. 49. (v_studio_id IN NUMBER. BEFORE DELETE ON gross_receipt 2. What additional information must you add? 1. 3. END. Only the CALCULATE_BUDGET procedure needs to be recompiled. 2. 3. All three procedures are marked invalid and must be recompiled. This trigger must fire before each DELETE of the GROSS_RECEIPT table. RAISE_APPLICATION_ERROR 4. ENABLE check_theater. Which command can you issue to enable this trigger? 1. 4. Examine this database trigger 52. THEN 57. BEFORE (gross_receipt DELETE) 4. The SET_BUDGET function will be marked invalid and must be recompiled before the next execution. {additional trigger information} 54. AFTER DELETE ON gross_receipt 3. BEGIN 55. It should fire only once for the entire DELETE statement. Which procedure can be used to create a customized error message? 1. BEGIN 64. Examine this function: 61. SET yearly_budget = v_new_budget . ALTER TRIGGER check_theater ENABLE. DY) = MON 56. IF TO_CHAR(sysdate.

Any change made to one of the package constructs 3. WHERE id = v_studio_id. COMMIT. When the transaction is committed 2. END IF. Removing a local variable from the DECLARE section of one of the package constructs 67. Under which circumstance must you recompile the package body after recompiling the package specification? 1. This is different from a database trigger. Which code must be added to successfully compile this function? 1. Add RETURN right before the IS keyword. When an Oracle supplied package references the trigger . Add RETURN number right before the IS keyword. Procedure and Functions are explicitly executed. 3. ELSE RETURN FALSE. Add RETURN boolean right before the IS keyword. END. When is a database trigger executed? 1. 4. During the data manipulation statement 3. IF SQL%FOUND THEN RETURN TRUEl. Any SQL statement change made to one of the package constructs 4. 2. Altering the argument list of one of the package constructs 2. Add RETURN boolean right after the IS keyword. 66.

Any DML statements issued by the construct are committed 3. 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. the construct terminates. Any DML statements issued by the construct are still pending and can be committed or rolled back. DBMS_OUTPUT 3. 4. END. A stored function must return a value based on conditions that are determined at runtime. stored procedures and functions within SQL*Plus? 1. 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. 4. The construct rolls back any DML statements issued and returns the unhandled exception to the calling environment. What occurs if a procedure or function terminates with failure without being handled? 1. For this code to be successful. Which Oracle supplied package can you use to output values and messages from database triggers. 4. DBMS_DISPLAY 2. the SELECT statement cannot be hard-coded and must be created dynamically when the function is executed. DBMS_DML .get_total_for_year. 3. 73. what must be true? 1. DBMS_DESCRIBE 69.v_total_seats_sold_overall := theater_pck. Therefore. Which Oracle supplied package will enable this feature? 1. DBMS_LIST 4. theater_pck. 2. Unless a GOTO statement is used to continue processing within the BEGIN section. Examine this code 71. DBMS_DDL 2. Only the V_TOTAL_SEATS_SOLD_OVERALL variable must exist in the specification of the THEATER_PCK package. 2. BEGIN 72. During a data manipulation statement and when the transaction is committed 68. 74. 70.

It is file system now.0 platform wise? SQL Server 6.5 and 7.5 and 7. 3. Client and Server have to in sync.0 runs on Windows NT Server. How are you going to do it? You have to use transfer command.5. 5. Check on Client Configuration utility. What is a default TCP/IP socket assigned for SQL Server? 1433 6. 9. . DBMS_SQL Database admin interview questions 1. SQL Server 7. system tables. DBMS_SYN 4. You have to move it SQL Server 7.5 runs only on Windows NT Server. 2.0.0 doesn’t have Standard Mode. workstation and Windows 95/98. What is a major difference between SQL Server 6. 1. What is a traditional Network Library for SQL Servers? Named Pipes.0. What is the difference in Login Security Modes between v6. Is SQL Server implemented as a service or an application? It is implemented as a service on Windows NT server and workstation and as an application on Windows 95/98.0? There are no devises anymore in SQL Server 7. 3.0? 7. other database objects. 8. only Windows NT Integrated mode and Mixed mode that consists of both Windows NT Integrated and SQL Server authentication modes. 4. What is new philosophy for database devises for SQL Server 7. 7. what you need to look into to solve this problem? [Microsoft][ODBC SQL Server Driver][Named Pipes]Specified SQL Server not found. Let’s assume you have data that resides on SQL Server 6. the other file stores the transaction log. When you create a database how is it stored? It is stored in two separate files: one file contains the data. Check if MS SQL Server service is running on the computer you are trying to log into 2. If you encounter this kind of an error message.

What protocol both networks use? TCP/IP. What is JServer and what is it used for? Oracle JServer Option is a Java Virtual Machine (Java VM) which runs within the Oracle database server’s address space. 13. What is the difference between them? With Ethernet.sql script from SYS AS SYSDBA to install the Oracle JServer Option on a database. Ethernet . Physical). What kind of LAN types do you know? Ethernet networks and token ring networks. attach the ID to this RACF group. Transport. 17. create RACF group with tables attached to this group.ss Java on Oracle interview questions 1.10/100 Mbit/sec. Internet. Ping or ping ip. 16. 15.add. How many bits IP Address consist of?An IP Address is a 32-bit number. 11. 2. Windows 95: WINIPCFG. Token ring speed is 4/16 Mbit/sec . How does one install the Oracle JServer Option?Follow these steps to activate the Oracle JServer/ JVM option: 1. 10.re. 14. data is transmitted in ‘tokens’ from computer to computer in a ring or star configuration. any devices on the network can send data in a packet to any location on the network at any time. Make sure your database is started with large java_pool_size (>20M) and shared_pool_size (>50M) INIT. How do you define testing of network layers? Reviewing with your developers to identify the layers of the Network layered architecture. . How many layers of TCP/IP protocol combined of? Five. Determine the hardware and software configuration dependencies for the application under test. Internet Protocol. 2. your Web client and Web server application interact with. Oracle also provides a JServer Accelerator to compile Java code natively. 12. Run the $ORACLE_HOME/javavm/install/initjvm. (Application. Transmission Control Protocol.ORA parameter values. This speeds up the execution of Java code by eliminating interpreter overhead . With Token Ring. Do you know how to configure DB2 side of the application? Set up an application ID. How do you test proper TCP/IP configuration Windows machine? Windows NT: IPCONFIG/ALL. Data link.

Why does one need to publish Java in the database? Publishing Java classes on the database makes it visible on a SQL and PL/SQL level. What is JDBC and what is it used for? JDBC is a set of classes and interfaces written in Java to allow other Java programs to send SQL statements to a relational database management system. 5. © JDBC KPRB driver (default connection) for Java Stored Procedures and Database JSP’s. 3. and doesn’t require a pre-installed version of the JDBC drivers. It is smaller and faster than the OCI drivers.registerDriver (new oracle. 5. Loaded code can be viewed by selecting from the USER_SOURCE view. public static void main (String args []) throws SQLException 10. ce code into the database? Use the “CREATE OR REPLACE JAVA SOURCE” command or “loadjava” utility. Follow the steps in the Oracle Migrations Guide to upgrade or downgrade the JServer option from one release to another. 4. The rmjvm. 3. Connection conn = DriverManager. userid.jdbc. // @machineName:port:SID. 8. It is important to publish your code before calling it from SQL statements or PL/SQL code. class dbAccess { 9.sql. password . 4. (b) JDBC OCI for writing stand-alone Java applications. Grant JAVAUSERPRIV to users that wants to use Java: SQL> GRANT JAVAUSERPRIV TO SCOTT.getConnection ("jdbc:oracle:thin:@hostname:1526:orcl". How does one connect with the JDBC Thin Driver? The the JDBC thin driver provides the only way to access Oracle from the Web (applets). import java. 7.sql script can be used to deinstall the JServer option from your database.OracleDriver()). 6. “scott". Oracle provides three categories of JDBC drivers: (a) JDBC Thin Driver (No local Net8 installation required/ handy for applets).driver. “tiger"). { DriverManager.*.

sql. userid. 13.createStatement(). Class. } Connection conn = DriverManager. // or oci7 @TNSNames_Entry. { 16.getString(1)). try { 17.executeQuery("select BANNER from SYS.next()) .*. “tiger").executeQuery("select BANNER from SYS.V_$VERSION").out. How does one connect with the JDBC OCI Driver? One must have Net8 (SQL*Net) installed and working before attempting to use one of the OCI drivers.forName ("oracle.createStatement(). } catch (ClassNotFoundException e) { 19. public static void main (String args []) throws SQLException 15. “scott". 18. ResultSet rset = stmt.V_$VERSION"). // Print col 1 stmt.printStackTrace(). 12. ResultSet rset = stmt.next()) System. import java.jdbc. Statement stmt = conn. class dbAccess { 14. } } 11.println (rset. while (rset.OracleDriver").close(). e. password Statement stmt = conn.driver.getConnection ("jdbc:oracle:oci8:@hostname_orcl". while (rset.

System. { Connection conn = (new oracle. Please note that you do not need to specify a database URL. Closing the default connection might throw an exception in future releases of Oracle. It provides a Java precompiler that translates SQLJ call to JDBC calls. ResultSet rset = stmt.println (rset.defaultConenction() method.out.executeQuery("select BANNER from SYS. .close(). 22. } } 25. class dbAccess { 23. What is SQLJ and what is it used for? SQLJ is an ANSI standard way of coding SQL access in Java.V_$VERSION").sql.close().createStatement(). How does one connect with the JDBC KPRB Driver? One can obtain a handle to the default or current connection (KPRB driver) by calling the OracleDriver.getString(1)).*. Statement stmt = conn. while (rset.println (rset. // Print col 1 stmt. // Print col 1 stmt.out. username or password as you are already connected to a database session.jdbc.driver.getString(1)). Remember not to close the default connection.defaultConnection(). 21.next()) System. import java. public static void main (String args []) throws SQLException 24. } } 20.OracleDriver()). The idea is similar to that of other Oracle Precompilers.

jsp files. which is easier to develop than Java Server Pages (JSP). How does a JSP gets executed? The first time you call a JSP. stored procedures.ser files. Obviously your web server need to support JSP pages and must be configured properly to handle them.class files.sqlj files to *. The *. JSP pages are saved to *. PL/SQL procedures are by default executed with defines rights. What is a Java Stored Procedure/ Trigger? A Java Stored Procedure is a procedure coded in Java (as opposed to PL/SQL) and stored in the Oracle database. applets.jsp file from your Web Server like you would call a normal *. Java Stored procedures are executed by the database JVM in database memory space. What is InfoBus DAC and what is it used for? InfoBus DAC (Data Aware Controls) is a standard Java extension used in JDeveloper to create data aware forms. Output produced by the servlet is returned to the web browser. For more information about ASP.class and *. It replaced the JBCL interface that were used in JDeveloper V1 and V2. However ASP is a proprietary technology and is less flexible than JSP. Interfacing between PL/SQL and Java are extremely easy. 28.java and *. What is a JSP and what is it used for? Java Server Pages (JSP) is a platform independent presentation layer technology that comes with SUN’s J2EE platform. 27. 30. Output will typically be HTML or XML code.java files to *. see the Oracle ASP FAQ. 32. JSP’s etc. The class file is then executed on the server. Thereafter one invokes the javac compiler to compile the . A JSP compiler is used in the background to generate a Servlet from the JSP page. Java Stored Procedures can be developed in JDBC or SQLJ. .html file.26. How does one deploy SQLJ programs? Use the sqlj compiler to compile your *.ser files needs to be deployed. How does one invoke a JSP? A JSP gets invoked when you call a *. 31.java) will be created and compiled to a . What is the difference between ASP and JSP? Active Server Pages (ASP) is a Microsoft standard. JSPs are normal HTML pages with Java code pieces embedded in them. a servlet (*. 29. EJB’s. Please note that Java Stored procedures are by default executed with invokers rights.ser files contain vendor specific database code. 33. What is JDeveloper and what is it used for? JDeveloper is the Oracle IDE (Integrated Development Environment) for developing SQLJ and JDBC programs. The *.class file.