Interview questions for Oracle database administrator

  1. Differentiate between TRUNCATE and DELETE
  2. What is the maximum buffer size that can be specified using the DBMS_OUTPUT.ENABLE function?
  3. Can you use a commit statement within a database trigger?
  4. What is an UTL_FILE.What are different procedures and functions associated with it?
  5. Difference between database triggers and form triggers?
  6. What is OCI. What are its uses?
  7. What are ORACLE PRECOMPILERS?
  8. What is syntax for dropping a procedure and a function? Are these operations possible?
  9. Can a function take OUT parameters. If not why?
  10. Can the default values be assigned to actual parameters?
  11. What is difference between a formal and an actual parameter?
  12. What are different modes of parameters used in functions and procedures?
  13. Difference between procedure and function.
  14. Can cursor variables be stored in PL/SQL tables.If yes how. If not why?
  15. How do you pass cursor variables in PL/SQL?
  16. How do you open and close a cursor variable.Why it is required?
  17. What should be the return type for a cursor variable.Can we use a scalar data type as return type?
  18. What is use of a cursor variable? How it is defined?
  19. What WHERE CURRENT OF clause does in a cursor?
  20. Difference between NO DATA FOUND and %NOTFOUND
  21. What is a cursor for loop?
  22. What are cursor attributes?
  23. Difference between an implicit & an explicit cursor.
  24. What is a cursor?
  25. What is the purpose of a cluster?
  26. How do you find the numbert of rows in a Table ?
  27. Display the number value in Words?
  28. What is a pseudo column. Give some examples?
  29. How you will avoid your query from using indexes?
  30. What is a OUTER JOIN?
  31. Which is more faster - IN or EXISTS?
  32. When do you use WHERE clause and when do you use HAVING clause?
  33. There is a % sign in one field of a column. What will be the query to find it?
  34. What is difference between SUBSTR and INSTR?
  35. Which datatype is used for storing graphics and images?
  36. What is difference between SQL and SQL*PLUS?
  37. What is difference between UNIQUE and PRIMARY KEY constraints?
  38. What is difference between Rename and Alias?
  39. What are various joins used while writing SUBQUERIES?
This entry was posted in Database. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

29 Comments on Interview questions for Oracle database administrator

  1. Renjith
    Posted 12/17/2004 at 6:01 am | Permalink

    Implicit cursors are created for every SQL Query by the DBMS without user interaction.
    Explicit cursos are explicitly declared, opened, fetched and closed by the user explicitly. The user has complete control over the explicit cursor.

  2. Renjith
    Posted 12/17/2004 at 6:02 am | Permalink

    Implicit cursors are created for every SQL Query by the DBMS without user interaction.
    Explicit cursors are explicitly declared, opened, fetched and closed by the user explicitly. The user has complete control over the explicit cursor.

  3. Renjith
    Posted 12/17/2004 at 6:04 am | Permalink

    What is difference between UNIQUE and PRIMARY KEY constraints?
    Both are Constraints and both creates an index on the specified columns.
    UNIQUE is a constraint which enforces distinct column values on a table column and can contain a NULL record also.
    PRIMARY KEY is a constraint similar to UNIQUE, however it cannot have a Null value for the column. Moreover a PRIMARY KEY can be the parent column for a Parent - Child relationship(Foreign Key).

  4. Elias B. Assefa(eLiMAn)
    Posted 3/18/2005 at 12:37 pm | Permalink

    The Oracle Call Interface (OCI) is a set of low-level APIs (Application Programming Interface Calls) used to interact with Oracle databases. It allows one to use operations like logon, execute, parse, fetch, etc. OCI programs are normally written in C or C++, although they can be written in almost any programing language.

    Unlike with the Oracle Precompilers (like Pro*C and Pro*COBOL), OCI programs are not precompiled. For more information about the other language precompilers

  5. Elias B. Assefa(eLiMAn)
    Posted 3/18/2005 at 12:40 pm | Permalink

    …………continued
    What is a precompiler
    A precompiler is a tool that allows programmers to embed SQL statements in high-level source programs like C, C++, COBOL, etc. The precompiler accepts the source program as input, translates the embedded SQL statements into standard Oracle runtime library calls, and generates a modified source program that one can compile, link, and execute in the usual way. Examples are the Pro*C Precompiler for C, Pro*Cobol for Cobol, SQLJ for Java etc. (Good luck)

  6. Jyoti
    Posted 3/22/2005 at 2:23 am | Permalink

    There is a % sign in one field of a column. What will be the query to find it?
    To find out the % sign we should use a Escape in where clause. Using Escape we can find out the exact match of the wild card charasters.
    e.g. select percentage from commission
    where percentage like ‘0.99\%’ escape ”;

  7. Ravi Prakash
    Posted 4/11/2005 at 1:01 am | Permalink

    Hi I am looking for Interview questions for DBA…i Will be grateful if you please send me questions as well as answers for these.

    Regards
    Ravi Prakash

  8. Himali Vaid
    Posted 4/24/2005 at 10:46 pm | Permalink

    What is an UTL_FILE.What are different procedures and functions associated with it?
    UTL_FILE is a package you use for reading/writing a file located on an Oracle server. It cannot be used to access files locally, that is on the computer where the client is running.

  9. Pallavi Chube
    Posted 4/29/2005 at 5:16 am | Permalink

    Q) Differentiate between TRUNCATE and DELETE.
    A) The Delete command will log the data changes in the log file where as the truncate will simply remove the data without it. Hence Data removed by Delete command can be rolled back but not the data removed by TRUNCATE. Truncate is a DDL statement whereas DELETE is a DML statement.

    Q) What is the maximum buffer size that can be specified using the DBMS_OUTPUT.ENABLE function?
    A) 1000000

    Q) Can you use a commit statement within a database trigger?
    A) Yes, if you are using autonomous transactions in the Database triggers.

    Q)What is an UTL_FILE? What are different procedures and functions associated with it?
    A)The UTL_FILE package lets your PL/SQL programs read and write operating system (OS) text files. It provides a restricted version of standard OS stream file input/output (I/O).
    Subprogram -Description
    FOPEN function-Opens a file for input or output with the default line size.
    IS_OPEN function -Determines if a file handle refers to an open file.
    FCLOSE procedure -Closes a file.
    FCLOSE_ALL procedure -Closes all open file handles.
    GET_LINE procedure -Reads a line of text from an open file.
    PUT procedure-Writes a line to a file. This does not append a line terminator.
    NEW_LINE procedure-Writes one or more OS-specific line terminators to a file.
    PUT_LINE procedure -Writes a line to a file. This appends an OS-specific line terminator.
    PUTF procedure -A PUT procedure with formatting.
    FFLUSH procedure-Physically writes all pending output to a file.
    FOPEN function -Opens a file with the maximum line size specified.

    Q) Difference between database triggers and form triggers?
    A) Database triggers are fired whenever any database action like INSERT, UPATE, DELETE, LOGON LOGOFF etc occurs. Form triggers on the other hand are fired in response to any event that takes place while working with the forms, say like navigating from one field to another or one block to another and so on.

    Q) What is OCI. What are its uses?
    A) OCI is Oracle Call Interface. When applications developers demand the most powerful interface to the Oracle Database Server, they call upon the Oracle Call Interface (OCI). OCI provides the most comprehensive access to all of the Oracle Database functionality. The newest performance, scalability, and security features appear first in the OCI API. If you write applications for the Oracle Database, you likely already depend on OCI. Some types of applications that depend upon OCI are:

    · PL/SQL applications executing SQL
    · C++ applications using OCCI
    · Java applications using the OCI-based JDBC driver
    · C applications using the ODBC driver
    · VB applications using the OLEDB driver
    · Pro*C applications
    · Distributed SQL

    Q) What are ORACLE PRECOMPILERS?
    A) A precompiler is a tool that allows programmers to embed SQL statements in high-level source programs like C, C++, COBOL, etc. The precompiler accepts the source program as input, translates the embedded SQL statements into standard Oracle runtime library calls, and generates a modified source program that one can compile, link, and execute in the usual way. Examples are the Pro*C Precompiler for C, Pro*Cobol for Cobol, SQLJ for Java etc.

    Q) What is syntax for dropping a procedure and a function? Are these operations possible?
    A) Drop Procedure/Function ; yes, if they are standalone procedures or functions. If they are a part of a package then one have to remove it from the package definition and body and recompile the package.

    Q) Can a function take OUT parameters. If not why?
    A) yes, IN, OUT or IN OUT.

    Q) Can the default values be assigned to actual parameters?
    A) Yes. In such case you don’t need to specify any value and the actual parameter will take the default value provided in the function definition.

    Q) What is difference between a formal and an actual parameter?
    A) The formal parameters are the names that are declared in the parameter list of the header of a module. The actual parameters are the values or expressions placed in the parameter list of the actual call to the module.

    Q) What are different modes of parameters used in functions and procedures?
    A) There are three different modes of parameters: IN, OUT, and IN OUT.
    IN - The IN parameter allows you to pass values in to the module, but will not pass anything out of the module and back to the calling PL/SQL block. In other words, for the purposes of the program, its IN parameters function like constants. Just like constants, the value of the formal IN parameter cannot be changed within the program. You cannot assign values to the IN parameter or in any other way modify its value.
    IN is the default mode for parameters. IN parameters can be given default values in the program header.
    OUT - An OUT parameter is the opposite of the IN parameter. Use the OUT parameter to pass a value back from the program to the calling PL/SQL block. An OUT parameter is like the return value for a function, but it appears in the parameter list and you can, of course, have as many OUT parameters as you like.
    Inside the program, an OUT parameter acts like a variable that has not been initialised. In fact, the OUT parameter has no value at all until the program terminates successfully (without raising an exception, that is). During the execution of the program, any assignments to an OUT parameter are actually made to an internal copy of the OUT parameter. When the program terminates successfully and returns control to the calling block, the value in that local copy is then transferred to the actual OUT parameter. That value is then available in the calling PL/SQL block.
    IN OUT - With an IN OUT parameter, you can pass values into the program and return a value back to the calling program (either the original, unchanged value or a new value set within the program). The IN OUT parameter shares two restrictions with the OUT parameter:
    An IN OUT parameter cannot have a default value.
    An IN OUT actual parameter or argument must be a variable. It cannot be a constant, literal, or expression, since these formats do not provide a receptacle in which PL/SQL can place the outgoing value.

    Q) Difference between procedure and function.
    A) A function always returns a value, while a procedure does not. When you call a function you must always assign its value to a variable.

    Q) Can cursor variables be stored in PL/SQL tables. If yes how. If not why?
    A) Yes. Create a cursor type - REF CURSOR and declare a cursor variable of that type.
    DECLARE
    /* Create the cursor type. */
    TYPE company_curtype IS REF CURSOR RETURN company%ROWTYPE;

    /* Declare a cursor variable of that type. */
    company_curvar company_curtype;

    /* Declare a record with same structure as cursor variable. */
    company_rec company%ROWTYPE;
    BEGIN
    /* Open the cursor variable, associating with it a SQL statement. */
    OPEN company_curvar FOR SELECT * FROM company;

    /* Fetch from the cursor variable. */
    FETCH company_curvar INTO company_rec;

    /* Close the cursor object associated with variable. */
    CLOSE company_curvar;
    END;

    Q) How do you pass cursor variables in PL/SQL?
    A) Pass a cursor variable as an argument to a procedure or function. You can, in essence, share the results of a cursor by passing the reference to that result set.

    Q) How do you open and close a cursor variable. Why it is required?
    A) Using OPEN cursor_name and CLOSE cursor_name commands. The cursor must be opened before using it in order to fetch the result set of the query it is associated with. The cursor needs to be closed so as to release resources earlier than end of transaction, or to free up the cursor variable to be opened again.

    Q) What should be the return type for a cursor variable. Can we use a scalar data type as return type?
    A) The return type of a cursor variable can be %ROWTYPE or record_name%TYPE or a record type or a ref cursor type. A scalar data type like number or varchar can’t be used but a record type may evaluate to a scalar value.

    Q) What is use of a cursor variable? How it is defined?
    A) Cursor variable is used to mark a work area where Oracle stores a multi-row query output for processing. It is like a pointer in C or Pascal. Because it is a TYPE, it is defined as TYPE REF CURSOR RETURN ;

    Q) What WHERE CURRENT OF clause does in a cursor?
    A) The Where Current Of statement allows you to update or delete the record that was last fetched by the cursor.

    Q) Difference between NO DATA FOUND and %NOTFOUND
    A) NO DATA FOUND is an exception which is raised when either an implicit query returns no data, or you attempt to reference a row in the PL/SQL table which is not yet defined. SQL%NOTFOUND, is a BOOLEAN attribute indicating whether the recent SQL statement does not match to any row.

    Q) What is a cursor for loop?
    A) A cursor FOR loop is a loop that is associated with (actually defined by) an explicit cursor or a SELECT statement incorporated directly within the loop boundary. Use the cursor FOR loop whenever (and only if) you need to fetch and process each and every record from a cursor, which is a high percentage of the time with cursors.

    Q) What are cursor attributes?
    A) Cursor attributes are used to get the information about the current status of your cursor. Both explicit and implicit cursors have four attributes, as shown:
    Name Description
    %FOUND Returns TRUE if record was fetched successfully, FALSE otherwise.
    %NOTFOUND Returns TRUE if record was not fetched successfully, FALSE otherwise.
    %ROWCOUNT Returns number of records fetched from cursor at that point in time.
    %ISOPEN Returns TRUE if cursor is open, FALSE otherwise.

    Q) Difference between an implicit & an explicit cursor.
    A) The implicit cursor is used by Oracle server to test and parse the SQL statements and the explicit cursors are declared by the programmers.

    Q) What is a cursor?
    A) A cursor is a mechanism by which you can assign a name to a “select statement” and manipulate the information within that SQL statement.

    Q) What is the purpose of a cluster?
    A) A cluster provides an optional method of storing table data. A cluster is comprised of a group of tables that share the same data blocks, which are grouped together because they share common columns and are often used together. For example, the EMP and DEPT table share the DEPTNO column. When you cluster the EMP and DEPT, Oracle physically stores all rows for each department from both the EMP and DEPT tables in the same data blocks. You should not use clusters for tables that are frequently accessed individually.

    Q) How do you find the number of rows in a Table ?
    A) select count(*) from table, or from NUM_ROWS column of user_tables if the table statistics has been collected.

    Q) Display the number value in Words?
    A)

    Q) What is a pseudo column. Give some examples?
    A) Information such as row numbers and row descriptions are automatically stored by Oracle and is directly accessible, ie. not through tables. This information is contained within pseudo columns. These pseudo columns can be retrieved in queries. These pseudo columns can be included in queries which select data from tables.
    Available Pseudo Columns
    · ROWNUM - row number. Order number in which a row value is retrieved.
    · ROWID - physical row (memory or disk address) location, ie. unique row identification.
    · SYSDATE - system or today’s date.
    · UID - user identification number indicating the current user.
    · USER - name of currently logged in user.

    Q) How you will avoid your query from using indexes?
    A) By changing the order of the columns that are used in the index, in the Where condition, or by concatenating the columns with some constant values.

    Q) What is a OUTER JOIN?
    A) An OUTER JOIN returns all rows that satisfy the join condition and also returns some or all of those rows from one table for which no rows from the other satisfy the join condition.

    Q) Which is more faster - IN or EXISTS?
    A) Well, the two are processed very differently.
    Select * from T1 where x in ( select y from T2 )
    is typically processed as:
    select *
    from t1, ( select distinct y from t2 ) t2
    where t1.x = t2.y;
    The sub query is evaluated, distinct’ed, indexed (or hashed or sorted) and then joined to the original table — typically. As opposed to
    select * from t1 where exists ( select null from t2 where y = x )
    That is processed more like:
    for x in ( select * from t1 )
    loop
    if ( exists ( select null from t2 where y = x.x )
    then
    OUTPUT THE RECORD
    end if
    end loop
    It always results in a full scan of T1 whereas the first query can make use of an index on T1(x). So, when is where exists appropriate and in appropriate? Lets say the result of the sub query ( select y from T2 ) is “huge” and takes a long time. But the table T1 is relatively small and executing ( select null from t2 where y = x.x ) is very fast (nice index on t2(y)). Then the exists will be faster as the time to full scan T1 and do the index probe into T2 could be less then the time to simply full scan T2 to build the sub query we need to distinct on.
    Lets say the result of the sub query is small — then IN is typically more appropriate. If both the sub query and the outer table are huge — either might work as well as the other — depends on the indexes and other factors.

    Q) When do you use WHERE clause and when do you use HAVING clause?
    A) The WHERE condition lets you restrict the rows selected to those that satisfy one or more conditions. Use the HAVING clause to restrict the groups of returned rows to those groups for which the specified condition is TRUE.

    Q) There is a % sign in one field of a column. What will be the query to find it?
    A) SELECT column_name FROM table_name WHERE column_name LIKE ‘%\%%’ ESCAPE ‘\’;

    Q) What is difference between SUBSTR and INSTR?
    A) INSTR function search string for sub-string and returns an integer indicating the position of the character in string that is the first character of this occurrence. SUBSTR function return a portion of string, beginning at character position, substring_length characters long. SUBSTR calculates lengths using characters as defined by the input character set.

    Q) Which data type is used for storing graphics and images?
    A) Raw, Long Raw, and BLOB.

    Q) What is difference between SQL and SQL*PLUS?
    A) SQL is the query language to manipulate the data from the database. SQL*PLUS is the tool that lets to use SQL to fetch and display the data.

    Q) What is difference between UNIQUE and PRIMARY KEY constraints?
    A) An UNIQUE key can have NULL whereas PRIMARY key is always not NOT NULL. Both bears unique values.

    Q) What is difference between Rename and Alias?
    A) Rename is actually changing the name of an object whereas Alias is giving another name (additional name) to an existing object.

    Q) What are various joins used while writing SUBQUERIES?
    A) =, , IN, NOT IN, IN ANY, IN ALL, EXISTS, NOT EXISTS.

  10. santosh punde
    Posted 6/17/2005 at 9:55 am | Permalink

    Q. What is difference between Rename and Alias?
    >>Rename is a permanent name given to a table or column whereas Alias is a temporary name given to a table or column which do not exist once the SQL statement is executed.

  11. Esther Vasa
    Posted 7/30/2005 at 9:42 am | Permalink

    On delete and truncate I would like to add a point about storage space.

    Delete does not free storage space. But, truncate does. In fact truncate moves the “high water mark” to the initial state. Beware… truncate cannot be rolled back!

    -Esther

  12. sudha
    Posted 8/25/2005 at 10:52 pm | Permalink

    Q) Display the number value in Words?
    A)select sal,(to_char(to_date(sal,’j'),’jsp’)) from emp;
    J means Julian day, the number of days since January 1, 4712 BC
    and sp means to spell out.

  13. Posted 9/12/2005 at 4:04 am | Permalink

    What is the difference between Hot Backup and Cold Backup?

  14. Posted 10/13/2006 at 2:11 am | Permalink

    I would like to know what is the difference between oracle & sql?

    As far as my concern, oracle is a database s/w, in which we have implementing a subtool called SQL. kindly confirm whether it is right or wrong. Please mail me the answers.

  15. swarup
    Posted 12/11/2006 at 3:54 am | Permalink

    Oracle is a RDBMS which follows maximum Codd rules(E.F.Codd) where as SQL is a tool but not a subtool of ORACLE.
    It is a standard tool to query all RDBMS like Mysql,Sybase, Ingress etc.

    It is basically an ANSI standard tool as per my knowledge.

  16. Rajesh
    Posted 1/22/2007 at 5:56 am | Permalink

    Q)What is the difference between Hot Backup and Cold Backup?
    A) Backup means, to store the data in some other location, so can be retrieved, during an outage or whenever necessary. Hotback can be done, without shutting down Oracle instance and will include all the datafiles as well as all the archive logs files (generated during the Oracle operation).

    Whereas during Coldback, we need to shutdown Oracle instance and then need to take backup of oracle data files.

  17. MANIVANNAN
    Posted 2/15/2007 at 4:21 am | Permalink

    what is the different between the database triger and schema trigger?

  18. Pradeep Reddy
    Posted 3/21/2007 at 12:55 am | Permalink

    Difference between procedure and function

    A FUNCTION always returns a value using the return statement.A PROCEDURE may return one or more values through parameters or may not return at all.
    A FUNCTION can be used in the Sql Queries while a PROCEDURE can not be used in sql queries .that cause a major difference b/w function and procedures .

  19. Tushar
    Posted 6/17/2007 at 10:11 pm | Permalink

    How many Codd rules do Oracle database follows?
    What is the 13th Codd Rule which was later introduced to the list?
    What is 4NF and 5NF (Normalised form) in oracle?

  20. saleem
    Posted 7/9/2007 at 4:24 am | Permalink

    Q) Display the number value in Words?

    A)select num,(t0_char(to_date(num,’j'),’jsp’)from dual;

  21. saleem
    Posted 7/9/2007 at 4:29 am | Permalink

    Q) There is a % sign in one field of a column. What will be the query to find it?

    A)select from where like ‘ value \%’; “\ = escape “

  22. saleem
    Posted 7/9/2007 at 4:32 am | Permalink

    Q) What is a OUTER JOIN?

    A) used to retrieve all rows from table1 even if join condition is not satisfied.But only matching rows from table2

  23. krishna pal singh
    Posted 8/28/2007 at 2:41 am | Permalink

    Q- what is view ?
    A- view is a logical representation of a table or more then one table
    view does’t create any memory and it is faster to access complex data

  24. Shakoor Jamshedi
    Posted 10/1/2007 at 5:44 am | Permalink

    what is the role of SQLplus in Oracle?

    what is differect between UNION and JOIN ?

    what is the function of distict Sql query ?

  25. sujit
    Posted 10/24/2007 at 1:04 am | Permalink

    what is the difference between procedure and function ?

    function should return a value but procedure may or may not return a value.we can use a function in select statement but we can not use a procedure and another difference is that when ever we are have to compute a value in that case we are going for function and when ever we to perform any action we are going for procedure.

  26. Ekalabya
    Posted 1/10/2008 at 3:13 am | Permalink

    What is the difference between redolog and undo?

  27. Gambler
    Posted 2/22/2008 at 5:56 am | Permalink

    what is the role of SQLplus in Oracle?
    SQL*PLUS is the tool that lets to use SQL to fetch and display the data.

    what is differect between UNION and JOIN ?
    Union is used to merge the data from 1 or more tables provided same column name and data type.
    A Join is used to fetch the conditional data from 1 or more table.

  28. Meenakshi
    Posted 4/8/2008 at 10:14 pm | Permalink

    What is the difference between rowID and rownum?

  29. Disha Khode
    Posted 1/12/2009 at 6:29 am | Permalink

    TRUNCATE is a DDL command which cannot be rolled back. All of the memory space is released back to the server.Here there is no need to mention where clause.
    DELETE is a DML command which can be rolled back.In Delete here we haave to mention “Where” clause in the query.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*