Interview questions for Oracle database administrator

Technical assistance & information for projects
Post Reply
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Interview questions for Oracle database administrator

Post by Neo » Mon Mar 22, 2010 7:56 pm

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.

Code: Select all

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) select num,(t0_char(to_date(num,’j'),’jsp’)from dual;

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.

Q) What is difference between Rename and Alias?
A) 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.

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.

Q) What is the difference between procedure and function?
A) 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.

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

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 “

Q) What is a view ?
A) view is a logical representation of a table or more then one table. View doesn’t create any memory and it is faster to access complex data
Post Reply

Return to “Project Assistance”