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

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);
}
}

Saturday, 7 July 2018

Java Program for Classes and Objects

class object_new
{
int id;
String name;

public void method1(int d,String n)
{
id = d;
name = n;
}
public void display()
{
System.out.println("My id is :"+ id);
System.out.println("My name is :"+ name);
}
}
class object1
{
public static void main(String args[])
{
object_new obj=new object_new();
object_new obj1=new object_new();
obj.method1(99,"Balwant Singh");
obj1.method1(101,"BSB");
obj.display();
obj1.display();
}
}

Basic Java Program

class basic
{
public static void main(String args[])
{
System.out.println("This is first Basic Program for programmers");
}
}

Saturday, 25 November 2017

How to Create SEQUENCE


CREATE SEQUENCE  SNO_BSB

MINVALUE 0 MAXVALUE 9999

INCREMENT BY 1

START WITH 1

CACHE 20

NOORDER

 CYCLE ;

This will create sequence with minvalue of 0 and maxvalue of  9999 and this will get increment by one every time. It will start with 1 having cache value of 20 and there is noorder and cycle means it will get repeated once reached it;s limit.

How to create auto-increment trigger

create or replace TRIGGER SNO_INC_TRG

BEFORE INSERT ON Bsb
for each row

BEGIN
if inserting then
      if :NEW."SNO" is null then
         select SNO_SEQ.nextval into :NEW."SNO" from dual;
      end if;
   end if;
END;

This trigger is setting the next value of sequence into the column when the column named SNO has null value. This trigger gets executed before the insertion on table bsb and it will triggered every time the new row gets inserted.
                                               

Monday, 23 October 2017

How to Use Java Scanner Class


Program:


import java.util.*;
public class InputValues
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);

// Your name
System.out.print("What is your name? ");
String name = in.nextLine();

// Your age
System.out.print("How old are you? ");
int age = in.nextInt();
System.out.println("Hello, " + name + ". Your Age is "+ age +". Nice to Meet You");
}
}


Output:
Hello, bsb. Your Age is 23. Nice to Meet You

Saturday, 26 August 2017

Simple java ArrayList Program

Program:

package JavaCoders;
import java.util.*;
class ArrayList1
{
public static void main(String[] x)
{
ArrayList<String>ar=new ArrayList<String>();
ArrayList ar1=new ArrayList();
ArrayList ar2=new ArrayList();
ArrayList ar3=new ArrayList();


Monday, 3 July 2017

Program of interface in java

Program:

package JavaCoders;
/**
 *
 * @author Bsb
 */
interface abc
{
void m1();
}
interface bca
{
void m1();

Friday, 16 June 2017

How to Create a Basic Java Applet in NetBeans

Program:

package JavaCoders;
/**
 *
 * @author Bsb
 */
import java.applet.Applet;
import java.awt.Graphics;
public class applet_example extends Applet

{

Thursday, 15 June 2017

Program in java to check if two Strings are Anagram or not

Anagram program in java

Program:

package JavaCoders;
import java.util.Arrays;
public class Anagram
{
void ana(String s1,String s2)
{
String st1=s1.replaceAll("\\s", "");
String st2=s2.replaceAll("\\s", "");
boolean b=true;
if(st1.length()!=st2.length())

How to print sum of even numbers in java

Program:

package JavaCoders;
import java.util.Scanner;
/**
*
* @author Bsb
*/
class even_sum
{
public static void main(String[] args)
{
int i;
int sum=0;
System.out.println("Enter the number upto you want to sum:");
Scanner sc=new Scanner(System.in);
int num=sc.nextInt();
for(i=1;i<=num;i++)


Tuesday, 13 June 2017

How to reverse string in java

Program:

package JavaCoders;

import java.util.Scanner;
public class rev_string
{
public static void main(String[] args)
{
String str1="";
String str2="";
System.out.println("Enter the string to be reversed:\n");
Scanner scn=new Scanner(System.in);
str1=scn.next();
for(int i=str1.length()-1;i>=0;i--)
{
str2=str2+str1.charAt(i);
}
System.out.println("Reversed String is: "+str2);
}
}

OUTPUT:

How-to-reverse-string-in-java

You can also go to link that ellaborate it more:

Monday, 12 June 2017

Simple Program of Typecasting in java

Simple Program of Typecasting in java Program:

package JavaCoders;
class Conversion
{
public static void main(String[] args)
{
String x="20000";
int a=67;
short b;
long c;
float d;
double e;
char f;
String z;
b=(short)a;
c=a;
d=a;
e=a;
f=(char)a;

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