Sie sind auf Seite 1von 4

Section-A

Q.1. Differentiate between PL/SQL functions and procedures.

The following are the major differences between procedure and function, 1. Procedure is named PL/SQL block which performs one or more tasks. whereas function is named PL/SQL block which performs a specific action. 2. Procedure may or may not return value where as function should return one value. 3. We can call functions in select statement where as procedure we cant. 4. A function can be in-lined into a SQL statement, e.g.
select foo ,fn_bar (foo) from foobar

Which cannot be done with a stored procedure.

Q.2. Draw the diagram of logical structure of oracle database and explain it in brief .

Database System Table Space Table Space1 Table Space2

Blocks

Segment Table Space Extent 1 Segment1 Extent 2 Segment2

Segment3

The oracle database is divided into increasingly smaller logical units to manage, store, and retrieve data efficiently and quickly. Its logical units are: Table spaces Segments Extents Blocks (1) Table space: - Table space is a grouping of database objects, usually to facilitate security, Performance or the availability of database objects such as tables and indexes. A table space is composed of one or more data files on disk. A table space is the highest level of logical objects in the database. A database consists of one or more table spaces. (2) Segment:Segment is a set of extents allocated for a single type of object, such as a table. A table space is further broken down into segments. A database Segment is a type of object that a user typically sees. such as a table. Tables pace 1 in the logical structure.

(3)Extents: - Extent is a contiguous group of blocks allocated for use as part of a table. Index, and so forth. The next lowest logical grouping in a database is the extent. (4) Blocks: - A database Blocks is the smallest unit of allocation in an Oracle database. one Or more database blocks compose a database extent.

Q.3. Discuss the objectives of Query Processing.


Objectives of Query Processing (1) The main objectives of query processing in a distributed environment is to form a high level query on a distributed database, which is seen as a single database by the users, into an efficient execution strategy expressed in a low level language in local databases. (2) An important point of query processing is query optimization. Because many execution strategies are correct transformations of the same high level query the one that optimizes (minimizes) resource consumption should be retained.

(3) The good measure of resource consumption are:(A)The total cost that will be incurred in processing the query It is the dome of all times incurred in processing the operations of the query at various sites and intrinsic communication. (B)The resource time of the query This is the time elapsed for executing the query. Since operations can be executed in parallel at different sited, the response time of a query may be significantly less than its cost. (4)Obviously the total cost should be minimized. (A) In a distributed system, the total cost to be minimized includes CPU, I\O, and communication costs. This cost can be minimized by reducing the number of I\O operation through fast access methods to the data and efficient use of main memory. The communication cost is the time needed for exchanging the data between sited participating in the execution of the query

Q.4. Explain the steps involved in recovery of distributed transactions. For Recovery of Distributed transactions, lets assume that at each site a Local Transaction Manager is available. Each agent can issue begin transaction, commit, and abort primitives to its LTM. After having issued a begin transaction to its LMT. An agent will possess the properties of a local transaction. We will call an agent that has issued a begin transaction primitive to its local transaction manager a Sub-transaction. Also to distinguish the begin transaction, commit, and abort primitives of the distributed transaction from the local primitives issued by each agent to its LTM, we will call the later as local_begin, local_commit, and local_abort. For building a Distributed Transaction Manager (DTM), the following properties are expected from the LTM: (a) Ensuring the atomicity of sub-transaction (b) Writing some records on stable storage on behalf of the distributed transaction manager.

We need the second requirement, as some additional information must also be recorded in such a way that they can be recovered in case of failure. In order to make sure that either all actions of a distributed transaction are performed or none is performed at all, two conditions are necessary: (a) At each site either all actions are performed or none is performed (b) All sites must take the same decision with respect to the commitment or abort of sub transaction. Begin_transaction: When it is issued by the root agent, DTM will have to issue a local_begin primitive to the LTM at the site of origin and all the sites at which there are already active agents of the same application, thus transforming all agents into sub_transaction; from this time on the activation of a new agent by the same distributed transaction requires that the local_begin be issued to the LTM where the agent in activated, so that the new agent is created as a Sub-transaction. The example of FUND TRANSFER is taken for explaining this concept. Abort: When an abort is issued by the root agent, all existing sub-transactions must be aborted. Issuing local_aborts to the LTMs at all sites where there is an active sub transaction performs this. Commit: The implementation of the commit primitive is the most difficult and expensive. The main difficulty originates from the fact that the correct commitment of a distributed transaction requires that al sub-transactions commit locally even if there are failures. In order to implement this primitive for a distributed transaction, the general idea of 2-Phase commit Protocol has been developed.

Section-B(practical section) Q. 5. Create a PL/SQL program to insert data into student table and display the details of the student having Reg.No 1010.
SQL> create table student(name varchar2(20), reg no number(12), session number(10), Cource varchar2(10)); SQL> insert into student Values(ravi,1005,2001_04,bca); SQL> insert into student Values(mohan,1006,2001_04,bba); SQL> insert into student Values(pradeep,1007,2001_04,bsc it); SQL> insert into student Values(rishav,1008,2001_04,mba); SQL> insert into student Values(rani,1009,2001_04,bca); SQL> insert into student Values(kanishk,1010,2001_04,mca); SQL> insert into student Values(deepak,1011,2001_04,bba); SQL>commit; SQL> select name, session, cource from student where reg no=1010;

Q.5.Create a PL/SQL program to generate first 10 natural numbers using loop, while and for .

SQL> set serveroutput on


SQL> declare i number(4); x number(4); begin x:=0; for i in 1..100 loop x:=x+i; end loop; dbms_output.put_line('The Sum is::'||x); end; /

Das könnte Ihnen auch gefallen