What is the Difference between PL/SQL And SQL?

By | May 21, 2014

SQL is a structured query language thats used to perform operations such as retrieval, updations,i nsertions etc. on database. It is used in MS SQL Server and Oracle and other databases.

PL/SQL is a Programming language which is an extension for SQL with control structures added to them. Number of SQL statements can be written together in PL/SQL. PL/SQL is used by Oracle.  T-SQL which is similar to PL/SQL is used by MS SQL Server.

 

 

 

PL/SQL versus T-SQL

  1. In T-SQL there are significant extensions to the ANSI SQL-92 standard which means converting applications to a different database later will be a code challenge re-write. The INNER JOIN, LEFT OUTER, RIGHT OUTER JOIN syntax differs from the classic JOIN.
  2. No Java database engine as in Oracle.
  3. Stored procedures in SQL Server are not compiled until executed (which means overhead, late binding and finding errors at execution time only!).
  4. No ability to read/write from external files from a stored procedure.
  5. PL/SQL has many DBMS system packages, where T-SQL relies only on a limited number of extended and system stored procedures in the master database.
  6. PL/SQL is better in error exception handling, and there is no such thing as exceptions in T-SQL (T-SQL uses @@error — not elegant!).
  7. T-SQL does not have the MINUS operator, that makes finding schema differences more difficult in SQL Server.
  8. In SQL Server there is no “dead connection detection”. Clients who lose their connection may still hold locks until a DBA is notified to kill their server side processes.
  9. In SQL Server there is no such thing as SQL*NET aliases/service names! This means applications have to hard code the actual server name into their apps, making it difficult to move databases later to load balance across servers.

Nice Articles for Further Reference

Wikipedia Definition:

polymorphism is a programming language feature that allows values of different data types to be handled using a uniform interface. The concept of parametric polymorphism applies to both data types and functions. A function that can evaluate to or be applied to values of different types is known as a polymorphic function. A data type that can appear to be of a generalized type (e.g., a list with elements of arbitrary type) is designated polymorphic data type like the generalized type from which such specializations are made.

MSDN Definition:
Polymorphism refers to the ability to define multiple classes with functionally different, yet identically named methods or properties that can be used interchangeably by client code at run time.

Polymorphism is .Net

Inheritance-Based Polymorphism

Most object-oriented programming systems provide polymorphism through inheritance. Inheritance-based polymorphism involves defining methods in a base class and overriding them with new implementations in derived classes.

For example, you could define a class, BaseTax, that provides baseline functionality for computing sales tax in a state. Classes derived from BaseTax, such as CountyTax or CityTax, could implement methods such as CalculateTax as appropriate.

Polymorphism comes from the fact that you could call the CalculateTax method of an object belonging to any class that derived from BaseTax, without knowing which class the object belonged to.

Example:

Const StateRate As Double = 0.053 ‘ %5.3 State tax
Const CityRate As Double = 0.028  ‘ %2.8 City tax
Public Class BaseTax
Overridable Function CalculateTax(ByVal Amount As Double) As Double
Return Amount * StateRate ‘ Calculate state tax.
End Function
End Class

Public Class CityTax
‘ This method calls a method in the base class
‘ and modifies the returned value.
Inherits BaseTax
Private BaseAmount As Double
Overrides Function CalculateTax(ByVal Amount As Double) As Double
‘ Some cities apply a tax to the total cost of purchases,
‘ including other taxes.
BaseAmount = MyBase.CalculateTax(Amount)
Return CityRate * (BaseAmount + Amount) + BaseAmount
End Function
End Class

Sub TestPoly()
Dim Item1 As New BaseTax()
Dim Item2 As New CityTax()
ShowTax(Item1, 22.74) ‘ $22.74 normal purchase.
ShowTax(Item2, 22.74) ‘ $22.74 city purchase.
End Sub

Sub ShowTax(ByVal Item As BaseTax, ByVal SaleAmount As Double)
‘ Item is declared as BaseTax, but you can
‘ pass an item of type CityTax instead.
Dim TaxAmount As Double
TaxAmount = Item.CalculateTax(SaleAmount)
MsgBox(“The tax is: ” & Format(TaxAmount, “C”))
End Sub

In this example, the ShowTax procedure accepts a parameter named Item of type BaseTax, but you can also pass any of the classes derived from the shape class, such as CityTax. The advantage of this design is that you can add new classes derived from the BaseTax class without changing the client code in the ShowTax procedure

Interface-Based Polymorphism

To achieve polymorphism with interfaces, you implement an interface in different ways in several classes. Client applications can use either the old or the new implementations in exactly the same way. The advantage to interface based polymorphism is that you do not need to re-compile existing client applications to get them to work with new interface implementations.

The following example defines an interface named Shape2 that is implemented in a class named RightTriangleClass2 and RectangleClass2. A procedure named ProcessShape2 calls the CalculateArea method of instances of RightTriangleClass2 or RectangleClass2

Sub TestInterface()
Dim RectangleObject2 As New RectangleClass2()
Dim RightTriangleObject2 As New RightTriangleClass2()
ProcessShape2(RightTriangleObject2, 3, 14)
ProcessShape2(RectangleObject2, 3, 5)
End Sub

Sub ProcessShape2(ByVal Shape2 As Shape2, ByVal X As Double, _
ByVal Y As Double)
MessageBox.Show(“The area of the object is ” _
& Shape2.CalculateArea(X, Y))
End Sub

Public Interface Shape2
Function CalculateArea(ByVal X As Double, ByVal Y As Double) As Double
End Interface

Public Class RightTriangleClass2
Implements Shape2
Function CalculateArea(ByVal X As Double, _
ByVal Y As Double) As Double Implements Shape2.CalculateArea
' Calculate the area of a right triangle.
Return 0.5 * (X * Y)
End Function
End Class

Public Class RectangleClass2
Implements Shape2
Function CalculateArea(ByVal X As Double, _
ByVal Y As Double) As Double Implements Shape2.CalculateArea
' Calculate the area of a rectangle.
Return X * Y
End Function
End Class

XML stands for  Extensible Markup Language, I know it should have been EML, but no its XML.

XML is a Meta Language used to hold data.

 

Serialization Explained

 

 

Wikipedia Definition

In the context of data storage and transmission, serialization is the process of saving an object onto a storage medium (such as a file, or a memory buffer) or to transmit it across a network connection link in binary form. The series of bytes or the format can be used to re-create an object that is identical in its internal state to the original object (actually, a clone).

This process of serializing an object is also called deflating or marshalling an object. The opposite operation, extracting a data structure from a series of bytes, is deserialization (which is also called inflating or unmarshalling).

MSDN
Serialization is the process of converting the state of an object into a form that can be persisted or transported. The complement of serialization is deserialization, which converts a stream into an object. Together, these processes allow data to be easily stored and transferred.

Serialization of Objects
To serialize a object means to save the state of the object, prequisite is the state has not to be transient i.e. the resource which are O.S. and it is per process.
Serialization of Objects mean to store the value of an object at any given point of time. For example when you use MS Paint to draw certain figures and save them, then you actually serialize the state of the object(figure) when saving.

Uses for serialization

Why would you want to use serialization? The two most important reasons are to persist the state of an object to a storage medium so an exact copy can be re-created at a later stage, and to send the object by value from one application domain to another
Serialization is used in many scenarios, but the main purpose is to save the state of an object in order to have the ability to recreate the same object when required. It is an important to let the user save work and then be able to continue from that point at a later time. This is a common need in various tools and applications. Serialization is also used in creating a clone of an object.

Another important need for serialization arises when the object is required to travel electronically over wire. In such cases the objects are serialized and deserialized. In fact, serialization is one of the fundamental requirements for techniques such as .NET Remoting.

Even the hibernation mode in the Windows Operating system can be considered a form of serialization.

Serialization in .Net

The .NET Framework features two serializing technologies:

  • Binary SerializationDuring Binary Serialization, the public and private fields of the object and the name of the class, including the assembly containing the class, are converted to a stream of bytes, which is then written to a data stream. When the object is subsequently deserialized, an exact clone of the original object is created.
  • XML and SOAP Serialization
    XML serialization converts (serializes) the public fields and properties of an object, or the parameters and return values of methods, into an XML stream that conforms to a specific XML Schema definition language (XSD) document. XML serialization results in strongly typed classes with public properties and fields that are converted to a serial format (in this case, XML) for storage or transport
    The simplest way to make a class serializable in C# is to mark it with the Serializable attribute as shown below.

[Serializable]
public class MyObject {
public int n1 = 0;
public int n2 = 0;
public String str = null;
}

Abstract Method in Java

An abstract method is a method that is declared without an implementation (without braces, and followed by a semicolon), like this:

abstract void moveTo(double deltaX, double deltaY);

If a class includes abstract methods, the class itself must be declared abstract, as in:

public abstract class GraphicObject {     // declare fields     // declare non-abstract methods     abstract void draw();  }
Abstract method is created by labelling it with 
the keyword abstract and must not contain any 
executable statements in its body

Wikipedia Definition
An abstract class, or abstract base class (ABC), is a class that cannot be instantiated. Such a class is only meaningful if the language supports inheritance. An abstract class is designed only as a parent class from which child classes may be derived. Abstract classes are often used to represent abstract concepts or entities. The incomplete features of the abstract class are then shared by a group of subclasses which add different variations of the missing pieces.

Abstract classes are superclasses which contain abstract methods and are defined such that concrete subclasses are to extend them by implementing the methods. The behaviors defined by such a class are “generic” and much of the class will be undefined and unimplemented. Before a class derived from an abstract class can become concrete, i.e. a class that can be instantiated, it must implement particular methods for all the abstract methods of its parent classes.

Purpose of An Abstract Class

  1. One of the  Purpose of using an abstract class is that you can group several related classes together as siblings.
  2. An Abstract class is a way to organize inheritance, sometimes it makes no sense to implement every method in a class, it might implement some methods to be inherited by sub classes, but others cannot be without knowing the function of the sub class. In such scenarios, abstract classes act as Template classes for future classes.

 

Leave a Reply