In Oracle : Oracle PL/SQL Code - Examples

Oracle Applications EBS 11i, R12      Oracle Database      Data Warehouse & BI      Oracle Middleware      PL/SQL      Linux ...

Oracle SQL & PL/SQL

Oracle SQL Oracle PL/SQL

The last articles in the site (HOT)

The most visited articles in the site

In-Oracle.com  -> Oracle SQL & PLSQL

-> Oracle PL/SQL Code - Examples

 

 Oracle PL/SQL Code - Examples

 

 

Here are some pl/sql examples. You can run these codes in any tool, sqlplus session. The user you are connected in is not important for this.

 

declare
     vnu_number1     number;
     vnu_number2     number(2);
begin
     select 7 into vnu_number1 from dual;
end;

declare
     vnu_number1    number;
     vnu_number2    number(2);
begin
     select 7 into vnu_number1 from dual;


     dbms_output.put_line('vnu_number1= '||vnu_number1);
end;

 

 

declare
     vnu_number1    number;
     vnu_number2    number(2);
begin
     select 7 into vnu_number1 from dual;
     vnu_number2 := 9;

     if vnu_number2 = 9 then
           vnu_number1 := 1;
     else
           vnu_number1 := 0;
     end if;

     dbms_output.put_line('vnu_number1= '||vnu_number1);
end;

 

 

declare
      vnu_number1    number;
      vnu_number2    number(2);

      cursor c1 is
          select 6 from dual;
 

begin
      for i in c1 loop
           vnu_number2 := 9;
      end loop;

      if vnu_number2 = 9 then
            vnu_number1 := 1;
      else
            vnu_number1 := 0;
      end if;

      dbms_output.put_line('vnu_number1= '||vnu_number1);
end;

 

 

declare
      vnu_number1    number;
      vnu_number2    number(2);

      cursor c1 is
          select 6 NB from dual;
 

begin
      for i in c1 loop
           vnu_number2 := i.NB;
      end loop;

      if vnu_number2 = 9 then
            vnu_number1 := 1;
      else
            vnu_number1 := 0;
      end if;

      dbms_output.put_line('vnu_number1= '||vnu_number1);
end;

 

declare
       vnu_number1    number;
       vva_varchar2    varchar2(2);

begin
       vnu_number1 := 8;
       vva_varchar2 := vnu_number1;

       dbms_output.put_line('vnu_number1= '||vnu_number1);

exception
        when others then
        dbms_output.put_line('Exception: vnu_number1= '||vnu_number1);
end;

 

 

declare
       vnu_number1    number default 22;
       vva_varchar2    varchar2(2);

begin
       vva_varchar2 := '8x';
       vnu_number1 := vva_varchar2;

       dbms_output.put_line('vnu_number1= '||vnu_number1);

exception
        when others then
             dbms_output.put_line('Exception: vnu_number1= '||vnu_number1);
end;

 

declare
       vnu_number1    number default 22;
       vva_varchar2    varchar2(2);

 

       ex2     exception;

begin
       vva_varchar2 := '8x';
       vnu_number1 := vva_varchar2;

       dbms_output.put_line('vnu_number1= '||vnu_number1);

exception

        when  ex2  then

               dbms_output.put_line('Ex2: vnu_number1= '||vnu_number1);


        when others then
              dbms_output.put_line('Exception: vnu_number1= '||vnu_number1);
end;

 

declare
       vnu_number1    number default 22;
       vva_varchar2    varchar2(2);

 

       ex2     exception;

begin
       vva_varchar2 := '8x';
       vnu_number1 := vva_varchar2;
 

       if  vva_varchar2 <> '8x' then

             raise ex2;

       end if;
       dbms_output.put_line('vnu_number1= '||vnu_number1);

exception

        when  ex2  then

               dbms_output.put_line('Ex2: vnu_number1= '||vnu_number1);


        when others then
              dbms_output.put_line('Exception: vnu_number1= '||vnu_number1);
end;

 

 

declare
       vnu_number1    number default 22;
       vva_varchar2    varchar2(2);

 

       ex2     exception;

begin
       vva_varchar2 := null ;
       vnu_number1 := vva_varchar2;
 

       if  vva_varchar2 is null then

             raise ex2;

       end if;
       dbms_output.put_line('vnu_number1= '||vnu_number1);

exception

        when  ex2  then

               dbms_output.put_line('Ex2: vnu_number1= '||vnu_number1);


        when others then
              dbms_output.put_line('Exception: vnu_number1= '||vnu_number1);
end;

 

 

 

In-Oracle.com  -> Oracle SQL & PLSQL

-> Oracle PL/SQL Code - Examples

Oracle Applications EBS 11i, R12      Oracle Database      Data Warehouse & BI      Oracle Middleware      PL/SQL      Linux ...

 

     Copyright (c) 2011-2015  www.in-oracle.com  |  Disclaimer: The views expressed on this web site are my own and do not reflect the views of Oracle Corporation. You may use the information from this site only at your risk.