Oracle PL-SQL Interview Questions And Answers
What is difference between stored procedures and application procedures, stored function and application function ?
- Stored procedures are sub programmes stored in the database and can be called &executee multiple times wherein an application procedure is the one being used for a particular application same is the way for function.
- Both can be executed any number of times. Only difference is that stored procedures/ functions are stored in database in complied format while the application procedures/functions are not in precomplied format and at run time has to be compiled.
Explian rowid, rownum?what are the psoducolumns we have ?
- ROWID - Hexa decimal number each and every row having unique.Used in searching.
- ROWNUM - It is a integer number also unique for sorting Normally TOP N Analysys.
- Other Psudo Column are NEXTVAL,CURRVAL Of sequence are some exampls psudo columns are default columns provided by oracle
What is the starting oracle error number ? what is meant by forward declaration in functions ?
One must declare an identifier before referencing it. Once it is declared it can be referred even before defining it in the PL/SQL. This rule applies to function and procedures also.
State the difference between implict and explict cursors?
Implicit Cursor are declared and used by the oracle internally. whereas the explicit cursors are declared and used by the user. more over implicitly cursors are no need to declare oracle creates and process and closes automatically. the explicit cursor should be declared and closed by the user.Implicit cursors are used for single row query whereas explicit cursor is used for multiple row query
How to know the last executed procedure ?
Execute procedure name (parameter1,parameter2) Select timestamps, owner, obj_name, action_name from dba_audit_trail;this statement gives last executed time for procedure , function & package.
If the application is running very slow? At what points you need to go about the database in order to improve the performance ?
For improving performance, we need to check the sql statement blocks , because for every sql satement execution transfer to sql engine and come back to pl/sql engine that process takes more time to process the plsql block.
What is the basic structure of PL/SQL?
PL/SQL uses block structure as its basic structure. Anonymous blocks or nested blocks can be used in PL/SQL.
What are the components of a PL/SQL block ?
A set of related declarations and procedural statements is called block.DECLARE -- declaration section BEGIN -- executable statements -- main section EXCEPTION -- handling possible exceptions -- occurring in the main section END;
What are the data types a available in PL/SQL ?
Some scalar data types such as NUMBER, VARCHAR2, DATE, CHAR, LONG, BOOLEAN. Some composite data types such as RECORD & TABLE.
What are % TYPE and % ROW TYPE ? What are the advantages of using these over data types ?
- % TYPE provides the data type of a variable or a database column to that variable.
- % ROWTYPE provides the record type that represents a entire row of a table or view or columns selected in the cursor.
- The advantages are : I. Need not know about variable's data type
- ii. If the database definition of a column in a table changes, the data type of a variable changes accordingly.
What is difference between % ROWTYPE and TYPE RECORD ?
- % ROWTYPE is to be used whenever query returns a entire row of a table or view.
- TYPE rec RECORD is to be used whenever query returns columns of different table or views and variables.
- E.g. TYPE r_emp is RECORD (eno emp.empno% type,ename emp ename %type);e_rec emp% ROWTYPE cursor c1 is select empno,deptno from emp;e_rec c1 %ROWTYPE.
What is a database trigger ? Name some usages of database trigger ?
Database trigger is stored PL/SQL program unit associated with a specific database table. Usages are Audit data modifications, Log events transparently, Enforce complex business rules Derive column values automatically, Implement complex security authorizations. Maintain replicate tables.
How many types of database triggers can be specified on a table? What are they ?
- Insert Update Delete
- Before Row .....
- After Row ......
- Before Statement ........
- After Statement .........
- If FOR EACH ROW clause is specified, then the trigger for each Row affected by the statement.
- If WHEN clause is specified, the trigger fires according to the returned Boolean value.
Is it possible to use Transaction control Statements such a ROLLBACK or COMMIT in Database Trigger ? Why ?
- It is not possible. As triggers are defined for each table, if you use COMMIT of ROLLBACK in a trigger, it affects logical transaction processing.
- WE can use COMMIT and ROLLBACK triggers, but by using PRAGAMA AUTONAMOUS_TRANSATIONS. Now the transaction treated as a autonomous transaction.
- What are two virtual tables available during database trigger execution?
- The table columns are referred as OLD.column_name and NEW.column_name.
- For triggers related to INSERT only NEW.column_name values only available.
- For triggers related to UPDATE only OLD.column_name NEW.column_name values only available.
- For triggers related to DELETE only OLD.column_name values only available.
What happens if a procedure that updates a column of table X is called in a database trigger of the same table ?
Mutation of table occurs.
What is an Exception? What are types of Exception ?
Exception is the error handling part of PL/SQL block. The types are Predefined and user defined. Some of Predefined exceptions are.
- CURSOR_ALREADY_OPEN
- DUP_VAL_ON_INDEX
- NO_DATA_FOUND
- TOO_MANY_ROWS
- INVALID_CURSOR
- INVALID_NUMBER
- LOGON_DENIED
- NOT_LOGGED_ON
- PROGRAM-ERROR
- STORAGE_ERROR
- TIMEOUT_ON_RESOURCE
- VALUE_ERROR
- ZERO_DIVIDE
- OTHERS.exception is an identifier and error handling part of pl/sql types := 1)predifined and 2) user defined.
What is Pragma EXECPTION_INIT ? Explain the usage ?
- The PRAGMA EXECPTION_INIT tells the compiler to associate an exception with an oracle error. To get an error message of a specific oracle error.
- e.g. PRAGMA EXCEPTION_INIT (exception name, oracle error number)
What is Raise_application_error ?
Raise_application_error is a procedure of package DBMS_STANDARD which allows to issue an user_defined error messages from stored sub-program or database trigger.
What is an oracle stored procedure ?
A stored procedure is a sequence of statements that perform specific function.
What is a cursor for loop ?
- Cursor for loop implicitly declares %ROWTYPE as loop index,opens a cursor, fetches rows of values from active set into fields in the record and closes when all the records have been processed.
- eg. FOR emp_rec IN C1 LOOP
- salary_total := salary_total +emp_rec sal;
- END LOOP;
What are the cursor attributes used in PL/SQL ?
%ISOPEN - To check whether cursor is open or not
% ROWCOUNT - Number of rows fetched/updated/deleted.
% FOUND - To check whether cursor has fetched any row. True if rows are fetched.
% NOT FOUND - To check whether cursor has fetched any row. True if no rows are fetched.
These attributes are proceeded with SQL for Implicit Cursors and with Cursor name for Explicit Cursors.
What are the PL/SQL Statements used in cursor processing ?
DECLARE CURSOR cursor name, OPEN cursor name, FETCH cursor name INTO or Record types, CLOSE cursor name.
Explain the two type of Cursors ?
- There are two types of cursors, Implicit Cursor and Explicit Cursor.
- PL/SQL uses Implicit Cursors for queries. User defined cursors are called Explicit Cursors. They can be declared and used.
brillant piece of information, I had come to know about your web-page from my friend hardkik, chennai,i have read atleast 9 posts of yours by now, and let me tell you, your webpage gives the best and the most interesting information. This is just the kind of information that i had been looking for, i'm already your rss reader now and i would regularly watch out for the new posts, once again hats off to you! Thanx a million once again, Regards, sql and plsql difference
ReplyDelete