Вы находитесь на странице: 1из 3

SQL QUESTIONS AND ANSWERS

What packages (if any) has Oracle provided for use by developers?
Oracle provides the DBMS_ series of packages. There are many which developers should be aware of such as
DBMS_SQL, DBMS_PIPE, DBMS_TRANSACTION, DBMS_LOCK, BMS_ALERT, DBMS_OUTPUT, DBMS_JOB,
DBMS_UTILITY, DBMS_DDL, UTL_FILE. If they can mention a few of these and describe how they used them, even
better. If they include the SQL routines provided by Oracle, great, but not really what was asked.
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.
Describe the difference between a procedure, function and anonymous pl/sql block.
1. Function is mainly used in the case where it must return a value. Where as a procedure may or may not return a
value or may return more than one value using the OUT parameter.
2. Function can be called from SQL statements where as procedure can not be called from the sql statements
3. Functions are normally used for computations where as procedures are normally used for executing business logic.
4. You can have DML (insert, update, delete) statements in a function. But, you cannot call such a function in a SQL
query.
5. Function returns 1 value only. Procedure can return multiple values (max 1024).
6. Stored Procedure: supports deferred name resolution. Example while writing a stored procedure that uses table
named tabl1 and tabl2 etc...But actually not exists in database is allowed only in during creation but runtime throws
error Function won’t support deferred name resolution.
7. Stored procedure returns always integer value by default zero. whereas function return type could be scalar or
table or table values
8. Stored procedure is precompiled execution plan where as functions are not.
9. A procedure may modify an object where a function can only return a value The RETURN statement immediately
completes the execution of a subprogram and returns control to the caller.
What are SQLCODE and SQLERRM and why are they important for PL/SQL developers?
SQLCODE returns the value of the error number for the last error encountered.
The SQLERRM returns the actual error message for the last error encountered.
SQLERRM takes SQLCODE as the input. when the control is inside the exception block, then the value of sqlcode is
negative. For user defined exceptions, the value of sqlcode is 1 and the value of sqlerrm is 'user defined exception'.
What is a mutating table error and how can you get around it?
This happens with triggers. It occurs because the trigger is trying to update a row it is currently using. The usual fix
involves either use of views or temporary tables so the database is selecting from one while updating the other.
What are the types of triggers?
There are three types of triggers-
1)dml trigger.-insert,update,delete
2)system-event trigger.startup,shutdown database
3)instead of trigger. create or alter table
What is the maximum number of handlers processed before the PL/SQL block is excited when an
exception occurs?
1. Only one 2. All that apply
3. All referenced 4. None
only one because the instant oracle faces an exception, the control stops there and it exits the block.
In what order should a open/fetch/loop set of commands in a PL/SQL block be implemented if you use
the NOTFOUND cursor variable in the exit when statement? Why?
OPEN then FETCH then LOOP followed by the exit when. If not specified in this order will result in the final return
being done twice because of the way the %NOTFOUND is handled by PL/SQL.
How can you generate debugging output from PL/SQL?
Use the DBMS_OUTPUT package. Another possible method is to just use the SHOW ERROR command, but this only
shows errors. The DBMS_OUTPUT package can be used to show intermediate results from loops and the status of
variables as the procedure is executed. The new package UTL_FILE can also be used.
What is a mutating table error and how can you get around it?
This happens with triggers. It occurs because the trigger is trying to update a row it is currently using. The usual fix
involves either use of views or temporary tables so the database is selecting from one while updating the other.
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.
cursor for-loop require declaration of cursor and the remaining 3 steps open, fetch,close are automatically declared
by cusor for-loop itself.
Describe the use of %ROWTYPE and %TYPE in PL/SQL
%ROWTYPE allows you to associate a variable with an entire table row. The %TYPE associates a variable with a
single column type.
When is a declare statement needed ?
The DECLARE statement is used in PL/SQL anonymous blocks such as with stand alone, non-stored PL/SQL
procedures. It must come first in a PL/SQL stand alone file if it is used.
Describe the use of PL/SQL tables
PL/SQL tables are scalar arrays that can be referenced by a binary integer. They can be used to hold values for use
in later queries or calculations. In Oracle 8 they will be able to be of the %ROWTYPE designation, or RECORD.
How can you generate debugging output from PL/SQL?
Use the DBMS_OUTPUT package. Another possible method is to just use the SHOW ERROR command, but this only
shows errors. The DBMS_OUTPUT package can be used to show intermediate results from loops and the status of
variables as the procedure is executed. The new package UTL_FILE can also be used.
What is the difference between an explicit cursor and select into statement?
Explicit cursors are those user defined cursors in order to retrieve more than one row from a table. Select into
statement helps in invoking parameters into the formal parameters.
How can you find within a PL/SQL block, if a cursor is open?
Use the %ISOPEN cursor status variable.
In what order should a open/fetch/loop set of commands in a PL/SQL block be implemented if you use
the NOTFOUND cursor variable in the exit when statement? Why?
First OPEN then LOOP then FETCH should appear in the code. Reason is after OPENing the cursor first we need to go
into the LOOP then we only we can FETCH the values.After FETCHing, EXIT condition comes where we mention
%NOTFOUND condition.
PL/SQL offers which collection types?
1.Index-by tables, 2.Nested tables 3.Varrays 4.records
Which Oracle supplied package can you use to output values and messages from database triggers,
stored procedures and functions within SQL*Plus?
1. DBMS_DISPLAY 2. DBMS_OUTPUT -----------Ans
3. DBMS_LIST 4. DBMS_DESCRIBE
Which set of statements will successfully invoke this function within SQL*Plus?
1. VARIABLE g_yearly_budget NUMBER--------EXECUTE g_yearly_budget := GET_BUDGET(11);
2. VARIABLE g_yearly_budget NUMBER--------EXECUTE :g_yearly_budget := GET_BUDGET(11);
3.VARIABLE :g_yearly_budget NUMBER-------EXECUTE :g_yearly_budget := GET_BUDGET(11);
4. VARIABLE g_yearly_budget NUMBER--------:g_yearly_budget := GET_BUDGET(11);

=============================
If we have procedures A and B in a package. procedure B is reffered in other subprogram.
Updates to procedure A in a package, will do recompilation does this affect the other procedure B reffered in other
subprogram. please let me know the details about the packages. Ans: xxxxxxxxxxxxxxxxxxxxxxxx
How can you generate debugging output from PL/SQL?
Use the DBMS_OUTPUT package. The DBMS_OUTPUT package can be used to show intermediate results from loops
and the status of variables as the procedure is executed, however output only occurs after processing is finished,
which might not be useful if processing takes a long time. The package UTL_FILE can be used to write to a file, but
one must have write access to the output directory. A third possibility is to create a log table and have the procedure
write to the table. This will give you debugging information in real time.
What are SQLCODE and SQLERRM and why are they important for PL/SQL developers?
QLCODE returns the value of the error number for the last error encountered. The SQLERRM returns the actual error
message for the last error encountered. They can be used in exception handling to report, or, store in an error log
table, the error that occurred in the code. These are especially useful for the WHEN OTHERS exception.
When is a declare statement needed ?
The DECLARE statement is used in PL/SQL anonymous blocks such as with stand alone, non-stored PL/SQL
procedures. It must come first in a PL/SQL stand alone file if it is used. N
Can we assign value to IN parameter inside a pl sql procedure?
IN parameter is a read only parameter. We can assign the value of IN type parameter to a variable or use it in a
query, but we cannot change its value inside the procedure.
Can i use select statement on 2 tables which don't have PK and FK relationship. QUR):- like select *
from t1,t1;
Yes, we can select 2 tables by using select statement as follows: Select * from table1, table2 (Will show t1*t2
records)
Why PL/SQL does not support retriving multiple records?
Multiple records at a time could be retreved in PL/SQL using BULK COLLECT. To do that you define PL/SQL table
and load it using SELECT ... BULK COLLECT INTO <pl/sql table> FROM .. Optionaly could be used LIMIT - to limit the
number of records retreved at a time like SELECT ... BULK COLLECT INTO <pl/sql table> FROM .. LIMIT 1000
What is a mutating table error and how can you get around it?
This happens with triggers. It occurs because the trigger is trying to update a row it is currently using. The usual fix
involves either use of views or temporary tables so the database is selecting from one while updating the other.
Describe the difference between a procedure, function and anonymous pl/sql block.
A function must return a value while a procedure doesn't have to. and A function can implement into SELECT Query
whereas Procedure cannot be.
What are advantages of trigger in PL/SQL?
Trigger is like a stored procedure that are ran automatically by the database whenever an event occurs. It may be
BEFORE or AFTER.
How can you find within a PL/SQL block, if a cursor is open?
By using %ISOPEN attrubute. if cursor_nam%ISOPEN then statement else open cursor_name; statements end if)

What is the default return value for a function in pl/sql ?

Вам также может понравиться