Thursday 14 March 2019

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('Current value is:'|| i);
end loop;
end;
/

Java program to check armstrong number

Program:


package JavaCoders;
class armstrong
{
public static void main(String[] args) 
{
int c=0,a,temp;
int n=153;       //It is the number to check armstrong
temp=n;
while(n>0)
{
a=n%10;
n=n/10;
c=c+(a*a*a);
}
if(temp==c) 
{
System.out.println("armstrong number");
}
else
{
System.out.println("Not armstrong number");
}
}
}

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;
/

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...