You are on page 1of 6

http://groups.yahoo.

com/group/jiny JINY
1. What is the advantage of using a PreparedStatement?
For SQL statements that are executed repeatedly, using a PreparedStatement object would almost always be faster
than using a Statement object. This is because creating a PreparedStatement object by explicitly giving the SQL
statement causes the statement to be precompiled within the database immediately. Thus, when the
PreparedStatement is later executed, the DBMS does not have to recompile the SQL statement and prepared an
execution plan - it simply runs the statement. Typically, PreparedStatement objects are used for SQL statements that
take parameters. However, they can also be used with repeatedly executed SQL statements that do not accept
parameters

2. What is a database URL?

A database URL (or JDBC URL) is a platform independent way of adressing a database. A database/JDBC URL is of
the form jdbc:[subprotocol]:[node]/[databaseName]
jdbc:odbc:jiny

3. ResultSet?

Resultset donot contain the data ie the rows returned by executing a query.It Contains a cursor through which we can
retrieve the data. Initally it points to a position immediately preceeding the first row.Every time we call its next() method
the cursor move to the next row.Thus we retrieve a single row by calling resultset's next()
method.Generally the application Server will try its maximum to handle any abnormal exceptions that might crash the
server.But i never faced such a problem practically.Can you please explain me the circumstances when a server might
carsh and when a System can crash?

4. two types of sub query: correlated and non-correlated


Correlated Sub query is a sub query that is evaluated once for each row processed by the parent statement. Parent
statements can be Select, Update or Delete. Non-correlated sub queries are executed once for the whole
statement

this one is to find 6th highest salary in emp table.


SELECT * FROM emp A WHERE 5 = ( SELECT COUNT(DISTINCT B.sal) FROM emp B
WHERE A.sal > B.sal )

5. Which one of the following cannnot be Rollbacked in Oracle

1.INSERT
2.DELETE
3.TRUNCATE
4.UPDATE
TRUNCATE Cannot be Rollbacked !

6. When i want to get the values from a vector and put in a database which statement is optimized one ?
Statement
Prepared Statement
Callable Stmt
ALL of the Above

Prepared statement is the ans. Callable statements are used for stored procedure invocations. If you use callable
statements, it will obviously be fast, but all the processing logic will be shifted on to the database. Your java code or
statement will as such do nothing. So first of all, callable statements cannot be compared with other statements in this
context.
7. What is thin driver ,how do u identify it ?
Oracle has Thin Driver and OCI Driver. Those are 2 different drivers. Those are the names of the drivers.

http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
8. while connecting to database via JDBC,is bridge is always needed?

One need not use JDBC-ODBC bridge Driver to connect to database.In fact this type of driver should be avoided for
performance reasons. Use type 2 or type 4
driver.If the database id MS access u have no option but to go for this bridge.

9. Which method in the sql package is used for all opertions (only one method should be used) Which
perfoms ... Viz ., INSERT,UPDATE,DELETE,SELECT Etc.,
What is the disadvantage of that method

suppose statement.execute() will take any DDL or DML statements. but this method is primarily used to execute
statements that could be created on the fly i mea n dynamically

10. What is the difference between a trigger and a stored procedure?


Trigger is executed implicity when an event occurs such as row inserted, updated or deleted. Stored procedure on the
other hand has to be called explicitly.

11.What type of situations we go for Statement instead of Preapared Statement


Where we can use Statement

Prepared Statements are not always fast !

Lets go back to the roots. Lets call Statement as S and Prepared statement as PS. How is a query executed in java ?
establish a connection, create statement, execute query. First step, getting a connection is same for both S and PL.
Second step is similar to S and PS, if not same. Only difference, different objects are instantiated. Third and the most
important + deciding step, Execute.

In case of S,
1 query is passed on to the database
2 database will now parse the query
3 database prepares a execution plan
4 database executes execution plan and creates a cursor
5 database throws back a cursor pointer, pointing to the first row.

In case of PS
1 query is passed on to the database
1A Database will search for execution plan for this query
2 If execution plan doesnot exist, database will now parse the query
3 If execution plan doesnot exist, database prepares a execution plan
3B Database stores execution plan for future reference.
4 database executes execution plan and creates a cursor
5 database throws back a cursor pointer, pointing to the first row.

In case of S, there will always be 5 steps.


In case of SP, there will be 2 extra steps, the very first time. Also, some server (resources) memory will be consumed
to keep the plan active. This "may" make the server heavy. So finally it is Speed over Memory. There should be a
compromise in between.

This is the compromise. In case of "simple" queries(insert and updates are generally simple), execution plans are
preety straight forward.. Also in case of simple select.

Prepared statements makes sense only when we have repititive and/or complex database queries! For rest, simple
queries should do the work. Remember, Server resources are costly. Because a small increase in server time, will be

http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
propogeted to all connected users. So if we use all Prepared statements, we simply make the server heavy, and in turn
decrease the response time. So finally PS didnt made sense.

This is the reason why, S, PS and SP's should be used smartly. For usual database operations, S are ok..

12. Surrogate Key?


When business-related columns are used as primary keys they are often called intelligent or natural keys.

An alternative is to use system-generated artificial primary key values. These are often called surrogate keys because
they are replacements for the intelligent keys, or blind keys because the user doesn't see them.

13. The difference between VARCHAR and VARCHAR2?


VARCHAR was the earlier datatype and which was obseleted by VARCHAR2.VARCHAR2 allocates the memory
dynamically as opposed to VARCHAR. I believe VARCHAR2 started from Oracle 8i, but not sure if it was in earlier
versions too.

14. Oracle DB is known as ORDBMS? Why?


Oracle 8i onwards supports Object types.

15. Whats Client side cursor and server side cursor?


Client side cursors are place holders for the query results returned to the client program. E.g. all select queries returns
client side cursor to the program like ResultSet in java. May be Server side cursor deals with stored procedures on the
database side.. not sure.

16. Difference between Delete/truncate/drop table.


Delete actually deletes the individual row in the table. In this process it copies data into roll back segements for the
transaction purpose.

Delete needs commit, truncate does not need a commit


Delete dml, truncate is ddl statement
Delete does not reset the water mark, truncate resets the water mark
Delete u can use WHERE clause ,where in Truncate u can not,
Truncate is faster and consumes less memory ..
A transaction Log is entered when , Delete is used for Truncate no Transaction Log
Truncate cannot activate a Trigger , since it is not logged in the transaction
Truncate cannot be used by a table where refernced by foreign key constratint
Truncate cannot be used in table involving indexed view.

Drop with totally delete the table itself.

17. What is a view?


It is a logical grouping of relational tables. The advantage of view is that the query is precompiled and provides an
abstraction to the client program. ORACLE 8i onwards support object views.

18. What are the different types of joins?


---> Self-Join, Outer Join, Inner Join

19. What cursor type do you use to retrieve multiple recordsets?


--> Explicit Cursor.
Note : To retrieve Singe record we use Implicit Cursor

20. Diffrence between a "where" clause and a "having" clause


--> 'Where & having' clauses Filter the record based on some condition, but having clause can be used only with a
Group by Clause.

http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY

21. What is the difference between "procedure" and "function"?


--> There is no return statement in Procedure hence it doesn't return any value thro' return but Function does.
--> Functions can be used in Expressions where as Procedures cannot be used.

22. How will you copy the structure of a table without copying the data?
create table <new_tname> as select * from <existing_tname> where 1 = 0; (or any invaid condition)

23. How to find out the database name from SQL*PLUS command prompt?
select name from v$database;

24. Tradeoffs with having indexes


--> Select will be faster but the tradeoff is Insertion & Updation will be slower.
no of indexes are inversely propotional to the execution time of insert & update statements.

25. What is the difference between "translate" and "replace"?


--> replace replaces every occurance of a "set of characters" with the "new set of characters".
replace(String, match_set [, replacement_set]) if 3rd parameter is omitted NULL will be taken.
eg : replace('abcabccab', 'abc', 'def') = defdefcab

--> translate translates "single character at a time" like nth character in the match set(second parameter) with nth
character in the replacement set (third parameter)
translate(String, match_set, replacement_set)
eg : translate('abcabccab', 'abc', 'def') = defdeffde

26. What is DYNAMIC SQL method 4?


--> method 4 is used when we don't know the number of items in the select statement list & number of input
parameters used in the query.

27. How to remove duplicate records from a table?


delete from tname where rowid not in (select min(rowid) from tname group by column1, column2, column3, ...);

28. What is the use of ANALYZing the tables?


Analyzing tables --> to find unused blocks, fragmentation details.

29. How to run SQL script from a Unix Shell?


@filename.sql

30. What is a "transaction"? Why are they necessary?


--> a process (usually between two consecutive COMMITS is a single transaction) involving DML statements like
INSERT,
DELETE, UPDATE etc to enter/delete/modify data in the database.

31. When do you get contraint violtaion? What are the types of constraints?
Primary Key Constraint, Refererntial Constraint, Unique Constraint, not null constraint, Check.

32. How to convert RAW datatype into TEXT?


--> RAWTOHEX(R in RAW) returns a VARCHAR2

33. Difference - Primary Key and Aggregate Key


Aggregate Key ???

34. How functional dependency is related to database table design?

http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY
---> refer normaliztion materials

35. What is a "trigger"?


A stored procedure getting invoked automatically as a result of some modification in a table or view.

36. Why can a "group by" or "order by" clause be expensive to process?
--> Involves I/O operation i.e, Makes use of memory from Temporary segment. Other I/O related processes are made
to wait.

37. What are "HINTS"? What is "index covering" of a query?


--> Hints are clues that tells(some times forces) Oracle to proceed with the execution based on the hint.
--> index covering means if a query can be answered by accessing only INDEX & with out accessing the table.

38. What is a VIEW? How to get script for a view?


--> User-defined representation of data from one or more tables. Note : Only the Query is stored not the DATA.
--> select text from all_views where owner = ? and view_name = ?

39 What are the Large object types suported by Oracle?


BLOB, CLOB

40. What is SQL*Loader?


used to Load data from Operating system flat files into Oracle Database.

41. Difference between "VARCHAR" and "VARCHAR2" datatypes.


--> No Difference except VARCHAR2 is the latest. Varchar is provided in the current versions just for compatibility.

42. What is the difference among "dropping a table", "truncating a table" and "deleting all records" from a
table.
Drop --> deletes the entire table & all views, synonyms created become INVALID; grants given also become
invalid;
Truncate --> deletes the contents of the table; Commits automatically. highwater mark is reset.
delete all records --> deletes the contents of the table; Doesn't commit automatically. highwater mark is remains at
the same place.

43.Difference between "ORACLE" and "MICROSOFT ACCESS" databases.


Oracle can handle thousands of concurrent users; Access about 40-50
* Oracle's locking structure is years ahead of Access. The database will not
lock up as easily as Access when people update data.
* Oracle has online backups and better export capabilities
* Oracle can recover a database to a point-in-time ; Access cannot.
* Oracle8 has things like bit-mapped indexes, reverse-key indexes, table and
index statistics, partitioned tables, advanced security (password management),
multi-threaded server, and replication, to name a few.
* On the plus-side, I like Access's easy forms and report wizards. In fact, I
often use Oracle databases as a back-end and generate data-entry forms quickly
with Access (using ODBC to link from Access to Oracle).

44. How to create a database link ?


Mainly used to access remote database.

CREATE [SHARED][PUBLIC] DATABASE LINK <link_name>


[CONNECT TO CURRENT_USER]
[USING <connect_string>]

http://groups.yahoo.com/group/jiny JINY
http://groups.yahoo.com/group/jiny JINY

OR
CREATE [SHARED][PUBLIC] DATABASE LINK <link_name>
[CONNECT TO <user> IDENTIFIED BY <password>]
[AUTHENTICATED BY <user> IDENTIFIED BY <password>]
[USING <connect_string>]

45. whts the diff betn char and varchar in any database?

46. What are the differences types of JDBC drivers?


47. Differentiate between Type 3 and Type 4
48. Differentiate between Type 2 and Type 4
49. Can a SP_ Stored Prcodeure can be deployed seprately !
50. Explain Normalizationa dn Denormalization with examples.
51. Talk about "Exception Handling" in PL/SQL?
52. What is the diference between "NULL in C" and "NULL in Oracle?"
53. What is Pro*C? What is OCI?
54. Give some examples of Analytical functions.

http://groups.yahoo.com/group/jiny JINY

You might also like