Sunday, August 12, 2012

PL/SQL



 PL/SQL (PROCEDURAL LANGUAGE/STRUCTURED QUERY LANGUAGE)

PL/SQL is a language that enables developers to create procedures, functions that combine sql with procedural statements.
PL/SQL block has three parts in it.
1. Declaration       All objects of the block are declared.
2. Execution          The objects are defined to manipulate data.
3. Exception          Error handling logic.
==>Declaration part is optional when we do not declare any objects
==>Exception part is also optional if we are not handling any exceptions.
==>But the Execution part is must in a PL/SQL Program and it starts with BEGIN and ends with END.
Execution:
========
To Execute the PL/SQL Program follow the syntax as
@<file_name>
or
start<file_name>
==>To Display the Result, give the command as follows
set serveroutput on
------------------------------------------------------------------------------
begin
                dbms_output.put_line('Welcome');
end;
/
------------------------------------------------------------------------------
declare
                city varchar2(10):='Hyderabad';
                dt date:='24/APR/2012';


begin
                dbms_output.put_line('welcome to '||city);
                dbms_output.put_line('todays date is '||dt);
end;
/
------------------------------------------------------------------------------
declare
                n1 number(10):=100;
                n2 number(10):=200;
begin
                dbms_output.put_line('Sum is: '||n1+n2);
end;
/
------------------------------------------------------------------------------
DECLARE
                name1 varchar2(20):='&name1';
                name2 varchar2(20);
BEGIN
                name2:='&name2';
if name1=name2 then
                    dbms_output.put_line('Both are equal');
                else
                    dbms_output.put_line('Not Equal');
                end if;
END;
/
------------------------------------------------------------------------------
declare
                n1 real:=10.50;
                n2 real:=20.35;
                n3 real;
begin
                n3:=n1+n2;
dbms_output.put_line ('The N1 value is => '||n1);
dbms_output.put_line ('The N2 value is => '||n2);
dbms_output.put_line ('The N3 value is => '||n3);
end;
/
------------------------------------------------------------------------------
DECLARE
   bv boolean:=true;
BEGIN
   If (bv=true) Then
       dbms_output.put_line('True');
   Else
       dbms_output.put_line('False');
   End If;
END;


No comments:

Post a Comment

Thank you :
- kareem