bc0050(oracle)

12
1 February2010 Bachelor of Computer Application (BCA) – Semester 4 BC0050 – Oracle & Distributed Databases – 4 Credits (Book ID: B0894) Assignment Set – 1 (40 Marks) Answer all Questions 1. What are the different methods used to recognize user defined exceptions? [10 Marks] Answer – User defined exceptions – User can write a set of code, which is to be executed while error occurs when executing a PL/SQL block of code. These set of code are called user – defined exceptions, and these are placed in the last sections of PL/SQL block called exceptions. The method used to recognize user – defined exceptions is as follows – Declare a user defined exception in the declaration section of PL/SQOL block. In the main program block for the conditions that needs special attention, execute a RAISE statement. Reference the declared exception with an error handling routine in EXCEPTION section of PL/SQL block. RAISE statement acts like CALL statement of high level languages. It has general format: RAISE<name of exception> When RAISE statement is executed, it stops the normal processing of PL/SQL block of code and control passes to an error handler block of the code at the end of PL/SQL program block, which is the EXCEPTION section. An exception declaration declares a name for user defined error conditions that the PL/SQL code block recognizes. It can only

Upload: sandeep-sheoran

Post on 02-Jan-2016

128 views

Category:

Documents


0 download

DESCRIPTION

BC0050(Oracle)

TRANSCRIPT

Page 1: BC0050(Oracle)

1

February2010

Bachelor of Computer Application (BCA) – Semester 4

BC0050 – Oracle & Distributed Databases – 4 Credits

(Book ID: B0894)

Assignment Set – 1 (40 Marks)

Answer all Questions

1. What are the different methods used to recognize user defined exceptions? [10 Marks]Answer –

User defined exceptions – User can write a set of code, which is to be executed while error occurs when executing a PL/SQL block of code. These set of code are called user – defined exceptions, and these are placed in the last sections of PL/SQL block called exceptions.

The method used to recognize user – defined exceptions is as follows – Declare a user defined exception in the declaration section of PL/SQOL block. In the main program block for the conditions that needs special attention, execute a

RAISE statement. Reference the declared exception with an error handling routine in EXCEPTION

section of PL/SQL block.

RAISE statement acts like CALL statement of high level languages. It has general format:RAISE<name of exception>

When RAISE statement is executed, it stops the normal processing of PL/SQL block of code and control passes to an error handler block of the code at the end of PL/SQL program block, which is the EXCEPTION section.An exception declaration declares a name for user defined error conditions that the PL/SQL code block recognizes. It can only appear in the DECLARE section of the PL/SQL code which precedes the key word BEGIN.EXCEPTION HANDLER (error handler block) is written between the key words EXCEPTION and END. The exception handling part of a PL/SQL code is optional. This block of code specifies what action has to be taken when the named exception condition occurs.The naming convention for exception name is exactly the same as those for variables or constants. All the rules for accessing an exception from PL/SQL blocks are same as those for variables and constants. However, it should be noted that exceptions cannot be passed as arguments to functions or procedures like variables or constants.

2. Explain the WHILE Loop statement and FOR loop statement in PL/SQL. [10 Marks]

Page 2: BC0050(Oracle)

2

Answer – A loop repeats a sequence of statements. The format is:LOOP

StatementsEND LOOP;

One or more PL/SQL statements can be written between the key words LOOP and END LOOP. Once a LOOP begins to run, it will go on forever. Hence loops are always accomplished by a conditional statement that keeps control on the number of times it is executed.

1. While loop – this loop enables as to evaluate a condition before a sequence of statements would be executed. If the condition is TRUE then sequence of statements are executed. This is different from the FOR loop where we must execute the loop at least once. The syntax for the WHILE loop is as follows :Syntax: WHILE <condition is TRUE> loop

<Statements> END LOOP; DECLARECount NUMBER (2):=0;BEGIN WHILE count<=10 LOOPCount: =count+1;Message (‘while loop executes’);END LOOP;END;

Exit and exit when statement-these statements enable us to escape out of the control of a loop. The format of exit loop is as follows: EXIT;

Exit when statements have the following syntax: EXIT WHEN<condition is true>;

2. FOR loop – this loop will allow us to execute a block of code repeatedly until some conditions occur. The syntax:FOR loop_index IN [REVERSE] low_value...high_value LOOPStatements to execute END LOOP;

The loop_index is defined by oracle as a local variable of integer type. REVERSE allows us to execute the loop in reverse order. The low_value..high_value is the range to execute the loop. These can be constants or variables. The line must be terminated with loop with no semicolon at the end of this line. We can list the statements to be executed until the loop is executed is evaluated to false.Example: - FOR v_count IN 1... 5 LOOP Message (‘for loop executes’);END LOOP;

Page 3: BC0050(Oracle)

3

In this case the for loop executes is displayed 5 times. Termination of the for loop can be done permanently by using EXIT statement based on some Boolean condition. Nesting of for loop can also be allowed in PL/SQL. The outer loop is executed once and then the inner loop is executed as many times as the range indicates and then the control is returned to the outer loop until this range expires.Example: - FOR out_count IN 1 ...2 LOOP FOR in_count IN 1...2 LOOP

Message (‘nested for loop’);END LOOP;END LOOP;Message ‘nested for loop’ is displayed four times.

3. Explain the different types of physical files in the Oracle9i? [10 Marks]Answer –The physical files of database –Oracle server is made up of the oracle database and oracle instance. The oracle database has a physical and logical structure. The physical structure of the database is made up of operating system files that comprise the database. All the data of the database is stored in the physical files. In oracle9i database there are three types of files:

1) Data files – these files contain the data of the database. All objects created in the database by users have their data physically stored in the data files. Data files contain the data dictionary and user created data. In order to access the data that is physically stored in the data files and reduce the overhead of disk I/O, blocks from the data files are read into the database buffer cache in memory. Once they are modified or are no longer needed they are written back to the data files.

2) Control files – this is a very important file that is required for the oracle database to function. If any one of the control files is unavailable the database is shutdown. Hence it is recommended that multiple copies of the control file should be maintained in the database on separate disks. The control file keeps a record of the names, size and locations of different physical files of the database. It also holds other control information necessary to keep the database functioning.

3) Redo log files – these files contain a record of all changes made in the database. These changes are referred to as redo entries. Redo entries can be used to recover the database in the event of an instance failure. Instance failure can occur when the contents of the SGA are lost such as in the event of a power outage or an abnormal shutdown of the database. Any change made in the database is 1st recorded in the online redo log buffer before it is actually implemented. Hence, even if modified blocks were not written in the event of an instance failure, the changes can be recovered by using the online redo log files.In Oracle9i, a minimum of two redo logs should be available. These redo logs files are known as redo groups. Since the redo log files are very important for recovery purposes, Oracle recommends that redo logs be multiplexed. Multiplexing is

Page 4: BC0050(Oracle)

4

maintaining multiple copies or additional members, which also mean each group, should have more than one member. Members of the redo log files should be of the same size and placed on separate disks. This will prevent loss of redo data in the event of the loss of a disk.

4) The password files – this file is used tom hold the names of privileged users who have been granted the SYSDBA and SYSOPER roles. These roles contain the privileges needed to perform actions such as a startup shutdown or recovering the database. The password is used only when we use database authentication i.e. the database is responsible for validating user credentials.

5) The parameter files – it is a file which contains a number of parameters that can be used to configure the Oracle9i instance. There are two kinds of parameters files available. The 1st one is called the server parameter file, which allows us to specify the values to parameters that can be enforced without bouncing the database as well as after re-starting the database. These are called persistent parameters. The 2nd kind of file is called parameter file which has been around for a while now. It holds parameters and their values however any change to a parameter’s values requires us to bounce or restart the database.

6) The archive file – these are files that can be created by a process known as archiving. When a database operates in archive log mode, the content of the redo log file are transferred to an offline file known as the archive file. This file is very useful in the event of a failure and is used for recovery purposes. Usually complete recovery up to the point of failure is possible if all archive files are available. Archive files can be created on disk and transferred to tape to create space for new archive files.

4. Give the various features of Object Oriented Oracle? [10 Marks]

Answer:

Features of object oriented Oracle –In oracle, an object type combines attributes (data structures) and methods (functions and procedures) into a single programming construct. The object type construct allows programmers to define their own reusable data types for use in PL/SQL programs and table and column definitions. An object type must be created in a database before it can be used in a PL/SQL program.

Object types – an object type has two parts: the specification and the body. The specification is required and contains the attributes and method specification the syntax for creating the object type specification is:CREATE [OR REPLACE] TYPE obj_type_name[AUTHID {CURRENT-USER | DEFINER}]{{IS | AS} OBJECT | UNDER parent_type_name}(

Page 5: BC0050(Oracle)

5

attribute_name_datatype,[[[NOT] OVERRIDING] [{NOT] FINAL] [{NOT} INSTANTIABLE] method_spec...][PRAGMA RESTRICT_REFEREBCES(program_name, purities)])[[NOT] FINAL][[NOT] INSTANTIABLE];Where method_spec is one of the following: MEMBER {PROCEDURE|FUNCTION} program_specOr: STATIC {PROCEDURE|FUNCTION} program_spec

Attribute specifications must appear before method specifications. Object attributes, like table columns are defined with a name and a data type. The name can be any legal identifier and the datatype can be almost any datatype known to SQL other than LONG, LONG RAW, ROWIO and UROWID. Attributes can be declared on other programmer – defined object types or collection types, but not on the Oracle9i types ANY TYPE, ANY DATA or ANY DATA SET. Attributes cannot be of datatypes unique to PL/SQL, such as BOOLEAN.Methods headers appear in the object type specification in a comma – delimited list. Unlike in a package specification, commas (not semicolons) terminate the object type program specifications. To support object comparison and sorting, the type can optionally include one comparison method-either ORDER or MAP. Member methods can be overloaded in object types following the same rules as function and procedure overloading in packages.

Type inheritance – beginning with Oracle9i, we can define subtypes of object types following a single – inheritance model. Oracle does not have a master root – level object type of the kind that we might find in other object programming model. Instead each type is “stand alone” unless declared otherwise.The UNDER keyword specifies that the type exits as a subtype in a hierarchy. When we are using UNDER, the parent type must be marked NOT FINAL. By default, types are FINAL, meaning that we cannot declare as subtype of that type. A subtype contains all of the attributes and methods of its parent (super type) and may contain additional attributes and methods. Methods can override corresponding methods from the parent. Changes to the super type – such as the addition of attributes or methods – are automatically reflected in the subtypes. By default, object types are INSTANTIABLE – that is, an invoking program may create an object of that type. The phrase NOT INSTANTIBALE tells Oracle that we don’t want any objects of the type, in which case Oracle will not create constructor for it. This variation generally makes sense only with types that will serve as parent other types.

Methods – there are 4 kinds of methods: 1) Member methods – it is a producer or function designated with the keyword MENBER. Calling program may invoke such a method only on objects that have been instantiated.

Page 6: BC0050(Oracle)

6

2) Static methods – it has no access to the current (SELF) object. Such a method is declared using the keyword STATIC and can be invoked at any time using type.method syntax: 3) Constructor methods – even if we don’t declare any methods, every instantiable object has been default constructor method which allows a calling program to create new objects of that type. This built – in method: - has the same name as the object type. - is a function that returns an object of that type. - accepts attributes in named or positional notion. - must be called with a value for every attribute – there is no DEAFULT clause for object attributes. - cannot be modified. 4) Comparison methods – the comparison methods – ORDER and MAP, establish ordinal positions of objects for comparisons such as “<” or “between” and for sorting (ORDER BY, GROUP BY, DISTINCT). Oracle invokes a comparison method automatically whenever it needs to perform such as operation.

Changing object types – we can add methods, but not attributes, to an object type stores=d in the database using ALTER TYPE statement. There are several forms of this statement: ALTER TYPE typename{ADD|MODIFY|DROP}ATTRIBUTE attribute_spec{INVALIDATE|CASCADE{[NOT]INCLUDING TABLE DATA|CONVERRT TO SUBSTITUTE TABLE}[FORCE]};

ALTER TYPE typename[NOT] {INSTANTIABLE|FINAL}{INVALIDATE|CASCADE {[NOT]INCLUDING TABLE DATA| CONVERT TO SUBSTITUTE TABLE} [FORCE]};

ALTER TYPE typenameCOMPIE [DEBUG][SPECIFICATION|BODY][REUSE SETTING];

Page 7: BC0050(Oracle)

7

February2010Bachelor of Computer Application (BCA) – Semester 4

BC0050 – Oracle & Distributed Databases – 4 Credits

(Book ID: B0894)

Assignment Set – 2 (40 Marks)

Answer all Questions

1. What are the characteristics of distributed query processor? Explain. [10 Marks]

Answer:

Characteristics of distributed query processor –It is very difficult to give the characteristics, which differentiates centralized and distributed query processors. The different types of characteristic are –

Languages – the input language to the query processor can be based on relational calculus or relational algebra. In distributed context, the output language is generally some from relational algebra augmented with communication primitives.

Types of optimization – conceptually, query optimization is to choose a bets point of solution space that leads to the minimum cost. A popular approach called exhaustive search is used. This is a method where heuristic techniques are used. In both centralized and distributed systems a common heuristic is to minimize the size of intermediate relations. Performing unary operations 1st and ordering the binary operations by the increasing size of their intermediate relation can do this.

Optimization timing – a query may be optimized at different times relative to the actual time of query execution. Optimization can be done statically before executing the query of dynamically as the query is executed. The main advantage of the later method is that the actual sizes of the intermediate relations are available to the query processor, thereby minimizing the probability of a bad choice.

Statistics – the effectiveness of the query optimization is based on statistics of the database. Dynamic query optimization requires statistics in order to choose the operation that has to be done first. Static query optimization requires statistics to estimate the size of intermediate relations. The accuracy of the statistics can be improved by periodical updating.

Decision sites – most of the systems use centralized decision approach in which a single site generates the strategy. The centralized approach is similar but requires the knowledge of the complete distributed database where as the distributed approach requires only local information.

Page 8: BC0050(Oracle)

8

Exploitation of the network topology – the distributed query processor exploits the network topology. This issue reduce the work of distributed query optimization, which can be dealt as two separate problems: selection of the global execution strategy, based on the inter – site communication and selection of each local execution strategy, based on a centralized query processing algorithms. With local area networks, communication costs are comparable to I/O costs.

Exploitation of replicated fragments – for reliability purpose it is useful to have fragments replicated at different sites. Query processors have to exploit the information either statically or dynamically for processing the query efficiently.

Use of semi – joins – the semi – joins operation reduce the size of the data that ar4e exchanged between the sites so that the communication costs can be reduced.

2. Discuss the issues of Federated Distributed DBMS. [10 Marks]

3. What are the different Troubleshooting problems in distributed transaction? [10 Marks]

4. How the traditional backup system is different from distributed backup system? Explain. [10 Marks]