Saturday, 11 August 2018

Oracle / PLSQL: IF-THEN-ELSE Statement

SET SERVEROUTPUT ON;

DECLARE
   a number(3) := 100;
   b number(3) := 200;
BEGIN
   IF( a = 100 ) THEN
      IF( b <> 200 ) THEN
         dbms_output.put_line(b);
      END IF;
   END IF;
   dbms_output.put_line(a);
END;

/

Simple PL/SQL Program

SET SERVEROUTPUT ON;

DECLARE
   c_id varchar2(100):= 'AR';
   r_id  varchar2(100);
   c_name varchar2(100);
  BEGIN
   SELECT region_id, country_name INTO r_id, c_name
   FROM countries
   WHERE country_id = c_id;
  dbms_output.put_line('Region Id is: '|| c_id || ' Country Name is: '|| c_name);

END;

/

Oracle / PLSQL: IF-THEN-ELSE-IF-ELSE Statement

SET SERVEROUTPUT ON;

DECLARE
   a number(3) := 100;
BEGIN
   IF (a = 50 ) THEN
      dbms_output.put_line('Value of a is 80' );
   ELSIF ( a = 75 ) then
      dbms_output.put_line('Value of a is 76' );
   ELSE
       dbms_output.put_line('None of the values is matching');
   END IF;
   dbms_output.put_line('Real value of a is: '|| a );
END;

/

PL/SQL Basic Loop Statement

SET SERVEROUTPUT ON ;

DECLARE
   x number := 4;
BEGIN
   LOOP
      dbms_output.put_line(x);
      x := x + 1;
      exit WHEN x > 5;
   END LOOP;
      dbms_output.put_line(x);
END;

/

Oracle / PLSQL: FOR LOOP IN REVERSE

SET SERVEROUTPUT ON:

Declare
b2 varchar2(100);
Begin
select count(*) into b2 from countries;
for i in reverse 1..b2 loop
dbms_output.put_line('Reverse Value is: '|| i);
end loop;
end;
/

Simple Program of Java

class object
{
public int id=10;
public String name="Balwant";
public static void main(String args[])
{
object ob = new object();
System.out.println("\n" + "" +ob.id);
System.out.print(ob.name);
}
}

Oracle / PLSQL: FOR LOOP

set serveroutput on; declare a1 varchar2(100); begin select count(*) into a1 from employees; for i in 1..a1 loop dbms_output.put_line...