Professional Documents
Culture Documents
Oracle PLSQL
Oracle PLSQL
Oracle PLSQL
Question: When we give SELECT * FROM EMP; How does oracle respond:
Answer: When u give SELECT * FROM EMP;
the server check all the data in the EMP file and it displays the data of the EMP file
Question: There are 2 tables, Employee and Department. There are few records in employee table, for
which, the department is not assigned. The output of the query should contain all th employees names
and their corresponding departments, if the department is assigned otherwise employee names and null
value in the place department name. What is the query?
Answer: What you want to use here is called a left outer join with Employee table on the left side. A left
outer join as the name says picks up all the records from the left table and based on the joint column
picks the matching records from the right table and in case there are no matching records in the right
table, it shows null for the selected columns of the right table. E.g. in this query which uses the key-word
LEFT OUTER JOIN. Syntax though varies across databases. In DB2/UDB it uses the key word LEFT
OUTER JOIN, in case of Oracle the connector is Employee_table.Dept_id *= Dept_table.Dept_id
SQL Server/Sybase :
Employee_table.Dept_id(+) = Dept_table.Dept_id
Question: on index
why u need indexing? Where that is stored
and what u mean by schema object?
For what purpose we are using view
Answer: We can?t create an Index on Index. Index is stored in user_index table. Every object that has
been created on Schema is Schema Object like Table, View etc. If we want to share the particular data to
various users we have to use the virtual table for the Base table...So that is a view.
Question: Which command displays the SQL command in the SQL buffer, and then executes it
Answer: You set the LIST or L command to get the recent one from SQL Buffer
Question: Which system table contains information on constraints on all the tables created?
Answer: USER_CONSTRAINTS.
Question: How do I write a program which will run a SQL query and mail the results to a group?
Answer: Use DBMS_JOB for scheduling a program job and DBMS_MAIL to send the results through
email.
Question: There is an Eno. & gender in a table. Eno. has primary key and gender has a check constraints
for the values 'M' and 'F'.
While inserting the data into the table M was misspelled as F and F as M.
What is the update?
Answer: update <TableName> set gender=
Question: How can we backup the sql files & what is SAP?
Answer: You can backup the sql files through backup utilities or some backup command in sql. SAP is
ERP software for the organization to integrate the software.
Question: State true or false. !=, <>, ^= all denote the same operation.
Answer: True.
Question: State true or false. EXISTS, SOME, ANY are operators in SQL.
Answer: True.
- Suppose we need to validate a DML statement (insert/Update/Delete) that modifies a table then we can
write a trigger on the table that gets fired implicitly whenever DML statement is executed on that table.
- Another reason of using triggers can be for automatic updation of one or more tables whenever a
DML/DDL statement is executed for the table on which the trigger is created.
- Triggers can be used to enforce constraints. For eg: Any insert/update/ Delete statements should not be
allowed on a particular table after office hours. For enforcing this constraint Triggers should be used.
- Triggers can be used to publish information about database events to subscribers. Database event can
be a system event like Database startup or shutdown or it can be a user even like User login in or user
logoff.
Question: How write a SQL statement to query the result set and display row as columns and columns as
row?
Answer: TRANSFORM Count (Roll_no) AS Count of Roll_no
SELECT Academic_Status
FROM tbl_enr_status
GROUP BY Academic_Status
PIVOT Curnt_status;
Question: How to write a sql statement to find the first occurrence of a non zero value?
Answer: There is a slight chance the column "a" has a value of 0 which is not null. In that case, you?ll
loose the information. There is another way of searching the first not null value of a column:
select column_name from table_name where column_name is not null and rownum<2;
Question: What is normalazation, types with e.g.\'s. _ with queries of all types
Answer: There are 5 normal forms. It is necessary for any database to be in the third normal form to
maintain referential integrity and non-redundancy.
First Normal Form: Every field of a table (row, col) must contain an atomic value
Second Normal Form: All columns of a table must depend entirely on the primary key column.
Third Normal Form: All columns of a table must depend on all columns of a composite primary key.
Fourth Normal Form: A table must not contain two or more independent multi-valued facts. This normal
form is often avoided for maintenance reasons.
Fifth Normal Form: is about symmetric dependencies.
Each normal form assumes that the table is already in the earlier normal form.
Question: What is the advantage of specifying WITH GRANT OPTION in the GRANT command?
Answer: The privilege receiver can further grant the privileges he/she has obtained from the owner to any
other user.
Question: What is the main difference between the IN and EXISTS clause in sub queries??
Answer: The main difference between the IN and EXISTS predicate in sub query is the way in which the
query gets executed.
IN -- The inner query is executed first and the list of values obtained as its result is used by the outer
query. The inner query is executed for only once.
EXISTS -- The first row from the outer query is selected, then the inner query is executed and, the outer
query output uses this result for checking. This process of inner query execution repeats as many no .of
times as there are outer query rows. That is, if there are ten rows that can result from outer query, the
inner query is executed that many no. of times.
Question: How to find out the 10th highest salary in SQL query?
Answer: Table - Tbl_Test_Salary
Column - int_salary
select max (int_salary)
from Tbl_Test_Salary
where int_salary in
(select top 10 int_Salary from Tbl_Test_Salary order by int_salary)
Question: What is the difference between Single row sub-Query and Scalar Sub-Query?
Answer: SINGLE ROW SUBQUERY RETURNS A VALUE WHICH IS USED BY WHERE CLAUSE,
WHEREAS SCALAR SUBQUERY IS A SELECT STATEMENT USED IN COLUMN LIST CAN BE
THOUGHT OF AS AN INLINE FUNCTION IN SELECT COLUMN LIST.
It gives the added value of sal and comm for each employee in the emp table.
Question: I have a table with duplicate names in it. Write me a query which returns only duplicate rows
with number of times they are repeated.
Answer: SELECT COL1 FROM TAB1
WHERE COL1 IN
(SELECT MAX (COL1) FROM TAB1
GROUP BY COL1
HAVING COUNT (COL1) > 1)
Question: How to find out the database name from SQL*PLUS command prompt?
Answer: Select * from global_name;
This will give the data base name which u r currently connected to.....
group by (empid)
By James Koopmann
This is the second part of the two part series on helping you answer those tough questions
that you might experience in your quest for an Oracle DBA position.
The Oracle Technical Interview can be quite daunting. You never quite know what to study
for and how to prepare. I am fully aware of this, as I have received many emails since my
original article on interview questions was released. While these questions are only
guidelines as to what should and more than likely will be asked, I hope that you find some
comfort in the review of them. As always, do not just memorize the answers, as there are
jewels to be found in the quest of figuring out the answer from the question. As always,
remember that as you go through the article, it is not enough to know the answer to a
particular question; you must try to put yourself in an interview situation and experience
answering the question for yourself. Therefore, after you have gone through the questions
and answers read the question again and then answer it with your own words. As always,
good luck, and cheers.
Technical - Oracle
Last time, we answered questions 1 thru 20 of the technical part of the interview. Here are
the next 30 in this section. Depending on the mood of the interview and your ability to
elaborate on the answer, try to give some insight that you know more than just the simple
answer to some of these questions. Also, be sensitive to the interviewer getting tired of you
talking too much. Well here they are.
21. How would you determine the time zone under which a database was
operating?
WRAP
A function and procedure are the same in that they are intended to be a collection of
PL/SQL code that carries a single task. While a procedure does not have to return any
values to the calling application, a function will return a single value. A package on the other
hand is a collection of functions and procedures that are grouped together based on their
commonality to a business function or application.
Table functions are designed to return a set of rows through PL/SQL logic but are intended
to be used as a normal table or view in a SQL statement. They are also used to pipeline
information in an ETL process.
27. Where in the Oracle directory tree structure are audit traces placed?
Materialized views are objects that are reduced sets of information that have been
summarized, grouped, or aggregated from base tables. They are typically used in data
warehouse or decision support systems.
29. When a user process fails, what background process cleans up after it?
PMON
31. How would you determine what sessions are connected and what resources
they are waiting for?
34. Give two methods you could use to determine what DDL changes have been
made.
A temporary tablespace is used for temporary objects such as sort structures while
permanent tablespaces are used to store those objects meant to be used as the true objects
of the database.
38. When creating a user, what permissions must you grant to allow them to
connect to the database?
41. What view would you use to look at the size of a data file?
DBA_DATA_FILES
42. What view would you use to determine free space in a tablespace?
DBA_FREE_SPACE
43. How would you determine who has added a row to a table?
Turn on fine grain auditing for the table.
Partitioning is a method of taking large tables and indexes and splitting them into smaller,
more manageable pieces.
46. You have just compiled a PL/SQL package but got errors, how would you view
the errors?
SHOW ERRORS
49. What is the difference between the SQL*Loader and IMPORT utilities?
These two Oracle utilities are used for loading data into the database. The difference is that
the import utility relies on the data being produced by another Oracle utility EXPORT while
the SQL*Loader utility allows data to be loaded that has been produced by other utilities
from different data sources just so long as it conforms to ASCII formatted or delimited files.
Technical - UNIX
Every DBA should know something about the operating system that the database will be
running on. The questions here are related to UNIX but you should equally be able to
answer questions related to common Windows environments.
1. How do you list the files in an UNIX directory while also showing hidden files?
ls -ltra
3. What UNIX command will control the default file permissions when files are
created?
Umask
4. Explain the read, write, and execute permissions on a UNIX directory.
Write allows you to create, edit and delete files and subdirectories in the directory.
Execute gives you the previous read/write permissions plus allows you to change into the
directory and execute programs or shells from the directory.
A symbolic (soft) linked file and the targeted file can be located on the same or different file
system while for a hard link they must be located on the same file system.
6. Give the command to display space usage on the UNIX file system.
df -lk
Vmstat reports on virtual memory statistics for processes, disk, tape and CPU activity.
8. How would you change all occurrences of a value using VI?
Use :%s/<old>/<new>/g
9. Give two UNIX kernel parameters that effect an Oracle install
I hope that these interview questions were not too hard. Remember these are "core" DBA
questions and not necessarily related to the Oracle options that you may encounter in some
interviews. Take a close look at the requirements for any job and try to extract questions
that interviewers may ask from manuals and real life experiences. For instance, if they are
looking for a DBA to run their databases in RAC environments, you should try to determine
what hardware and software they are using BEFORE you get to the interview. This would
allow you to brush up on particular environments and not be caught off-guard. Good luck!