Top Banner

of 22

PlSql Technical Stuff

Jun 23, 2015

ReportDownload

Documents

ravikumar

1.What is Autonomous Transaction.. A transaction which is independent of other transaction is called Autonomous Transaction. Explain him with an Example ........ 2.What is Pragma Autonomous_Transaction. The pragma instructs the PL/SQL compiler to establish a PL/SQL block as autonomous or independent. both are one and the same.. 3.cursor attributes.... %found,%notfound,%rowcount,%isopen in addition to that they will ask for %bulk_rowcount 4.what is procedure and function .diiferences between them....... 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.A 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 wont support deferred name resolution.

7.Stored procedure returns always integer value by default zero. where as 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.

5.In how many ways that procedure parameters can be referenced... postional anad named parameters can be passed

6.briefly about IN,OUT AND INOUT parameters

7.advantage of packages A. Modularity - Encapsulate related constructs.

B. Easier Application Design - Code and compile specification and body separately.

C. Hiding Information - Only the declarations in the pacakge specification are visible and accessible to application. - Private constructs in the package body are hidden and inaccesible.

- All coding is hidden in the package body.

D. Added Functionality - Persistency of variables and coursors.

E. Better Performance - The entire package is loaded into memory when the package is first referenced. - There is only one copy in memory for all users. - The dependency hierarchy is simplified.

F. Overloading - Multiple subprograms of the same name. U can explain them each with an example....

8.why Pl/sql is Advantageous than pro*c.

y

y y y

Block Structures: PL SQL consists of blocks of code, which can be nested within each other. Each block forms a unit of a task or a logical module. PL/SQL Blocks can be stored in the database and reused. Procedural Language Capability: PL SQL consists of procedural language constructs such as conditional statements (if else statements) and loops like (FOR loops). Better Performance: PL SQL engine processes multiple SQL statements simultaneously as a single block, thereby reducing network traffic. Error Handling: PL/SQL handles errors or exceptions effectively during the execution of a PL/SQL program. Once an exception is caught, specific actions can be taken depending upon the type of the exception or it can be displayed to the user with a message.

9.Advantages of procedures and triggers .Advsntsge of Stored Procedures:

================================ Stored Procedures are precompiled one. it is the group of sql statements. stored procedure like a application programming. stored procedure is a fast one because it is already precompiled. stored procedure is the one is easy to maintain. 2.Advantage of Triggers: ======================== Triggers is a special kind of procedure. the Main advantage of the trigger is automatic. whenever the table affected by insert update or delete query that time the triggers will implicitely call. 10.Disadvantages of procedures,packages and triggers Disadvantages of Triggers It is easy to view table relationships , constraints, indexes, stored procedure in database but triggers are difficult to view. Triggers execute invisible to client-application. They are not visible or can be traced in debugging code. It is hard to follow their logic as it they can be fired before or after the database insert/update happens. It is easy to forget about triggers and if there is no documentation it will be difficult to figure out for new developers for their existence. Triggers run every time when the database fields are updated and it is overhead on system. It makes system run slower. Disadvantage of packages: Unnecessary module loading. Unable to load large packages into memory. Unable to compile large packages. Lack of synonym support. No version control.

11.What is Pragma EXECPTION_INIT ? Explain the usage ? The PRAGMA EXECPTION_INIT tells the complier 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) 12. What is Global temporary table? and what are the benefits of it? GLOBAL TEMPORARY TABLE statement defines a temporary table for the current session. The declared temporary table description does not appear in the system catalog. It is not persistent and cannot be

shared with other sessions. Each session that defines a declared global temporary table of the same name has its own unique description of the temporary table. When the session terminates, the rows of the table are deleted, and the description of the temporary table is dropped.

13. what are purity rules for functions? why they use ? what effects if not follow these rules?

The purity level defines what structure the function reads or modifies. the types of purity level: 1)wnds--write no database stage I.e the function does not modify any database or tables. 2)rnds--reads no database state. i.e function does not read any database tables. 3)wnps--write no package state i.efunction does not modify any packaged variables. 4)rnps-read no package state i.e function does not read any package variables.

To be callable from SQL statements a stored function (and any subprograms called by that function) must obey certain purity rules which are meant to control side effects:y

When called from a SELECT statement or a parallelized INSERT UPDATE or DELETE statement the function cannot modify any database tables.

y

When called from an INSERT UPDATE or DELETE statement the function cannot query or modify any database tables modified by that statement.

y

When called from a SELECT INSERT UPDATE or DELETE statement the function cannot execute SQL transaction control statements (such as COMMIT) session control statements (such as SET ROLE) or system control statements (such as ALTER SYSTEM). Also it cannot execute DDL statements (such as CREATE) because they are followed by an automatic commit.

If any SQL statement inside the function body violates a rule you get an error at run time (when the statement is parsed). To check for violations of the rules you can use the pragma (compiler directive) RESTRICT_REFERENCES. The pragma asserts that a function does not read or write database tables or package variables. For example the following pragma asserts that packaged function credit_ok writes no database state (WNDS) and reads no package state (RNPS): 14. What is mutating trigger? How do you resolve it? If a trigger body is trying to update dependent tables, will it get a mutating error?

To avoid Mutating trigger there are many ways. One of the best approach is to make use of the after trigger which clearly takes care of concurrency problems associated with mutating triggers .When after trigger is used only after the process of current updating is finished the next process gets processed. if the trigger attempts to select or modify the table while the trigger has not completed (ie. table is in transition). then mutating trigger error occurs. because the table is in middle of a transaction so it causes the trigger to mutate.you can change the trigger to statement level and apply the logic there. 15. Types of Triggers in Oracle there are mainily 3 types of triggers 1> dml trigger 2>instead of trigger written on only view 3>system trigger dml trigger written on table that gets fired on dml events like insert or delete or update operation that trigger may fire 1>after dml event 2> before dml event these are timings for trigger firing instead of trigger written only on view that view is not modifiable that also gets fired when dml event occurs system trigger gets fired on system event like before log off or after log on or before shutdown this trigger may be written on database level schema level 16. Difference between Varray and Nested Table They are Oracle data types those who knoww any language like C and java then it is easy to understand the concept of Varray as it is related to ARRAY structure of C or java language. where as Nested Table concept is related to Struct data type of C or java langauge. 17. What is the difference between REF Cursor & Normal Cursor? In case of an normal explict cursor, the SQL query has to be defined at the time of declaring the cursor itself. In case of REF Cursor, the cursor declartion is not associated with any SQL query, it is associated with a query at a later stage this brings in a lot of flexibility as different SQL queries can be associated with the cursor (one at a time, offcourse) programatically. REF Cursors also provide t