Thursday 31 January 2013

Differentiate between pl/sql functions and procedures

The following are the major differences between PL/SQL procedure and function:

1. Procedure can performs one or more tasks where as function performs a specific task.
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. We can call Stored Procedure within function but we can not call function within stored procedure.
5.A FUNCTION must be part of an executable statement, as it cannot be executed independently where as procedure represents an independent executable statement.
6. Function can be called form SQL statement where as procedure can not be called from the SQL statement.
7. Function are normally used for computation where as procedure are normally used for executing business logic.
8. Stored procedure supports deferred name resolution where as function wont support.
9. Stored procedure returns always integer value by default zero. whrer as function returns type could be scalar or table or table value.
10.Stored procedure is precompiled execution plan where as function are not.

write a pl/sql code for find sum of n numbers using while loop


DECLARE
    num NUMBER:='&Input_Number';
    res NUMBER:=0;
BEGIN
    WHILE(num>0)LOOP
        res:=res+num;
        num:=num-1;
    EXIT WHEN num=0;
    END LOOP;
    DBMS_OUTPUT.PUT_LINE(res||' Is Total !');
END;
/
Enter value for input_number: 5
 
15 Is Total !
 
PL/SQL procedure successfully completed.

Monday 28 January 2013

Advantages and disadvantages of layered architecture in a network

The following are the advantages of a layered architecture:

Layered architecture increases flexibility, maintainability, and scalability. In a Layered architecture we separate the user interface from the business logic, and the business logic from the data access logic. Separation of concerns among these logical layers and components is easily achieved with the help of layered architecture.


Multiple applications can reuse the components. For example if we want a windows user interface rather than a web browser interface, this can be done in an easy and fast way by just replacing the UI component. All the other components like business logic, data access and the database remains the same. Layered architecture allows to swap and reuse components at will.

Layered architecture enables teams to work on different parts of the application parallely with minimal dependencies on other teams.

Layered architecture enables develop loosely coupled systems.

Different components of the application can be independently deployed, maintained, and updated, on different time schedules.

Layered architecture also makes it possible to configure different levels of security to different components deployed on different boxes. sO Layered architecture, enables you to secure portions of the application behind the firewall and make other components accessible from the Internet.

Layered architecture also helps you to test the components independently of each other.

The following are the disadvantages of a layered architecture:                 

There might be a negative impact on the performance as we have the extra overhead of passing through layers instead of calling a component directly. 

Development of user-intensive applications can sometime take longer if the layering prevents the use of user interface components that directly interact with the database.

The use of layers helps to control and encapsulate the complexity of large applications, but adds complexity to simple applications.

Changes to lower level interfaces tend to percolate to higher levels, especially if the relaxed layered approach is used.