DBMS Evalution

1:

declare

begin

update cust000 set contact=NULL where cust_id=111;

end;

2:

set SERVEROUTPUT ON;

declare

i number;

fact number;

num number;

begin

i:=1;

fact:=1;

num:=#

while i<=num loop

fact:=fact*i;

i:=i+1;

end loop;

dbms_output.put_line(‘Factorail of given number is ‘ ||fact);

end;

3:

set SERVEROUTPUT ON;

declare

i number;

fact number;

num number;

begin

i:=5;

num:=&num;

while i<=num loop

dbms_output.put_line(i);

i:=i+5;

end loop;

end;

user define Exception

import java.util.*;
class InvalidRadiusException extends Exception
{
InvalidRadiusException(String s)
{
super(s);
}
}
class test
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);

int radius ;
try
{
System.out.println(“Enter radius of Circle”);
radius=sc.nextInt();

if(radius<0)
{
throw new InvalidRadiusException(“Radius is Invalid”);
}
else
{
float area=((22/7)*radius*radius);
System.out.println(“Area of Circle is “+area);
}
}
catch(InvalidRadiusException e)
{
System.out.println(e.getMessage());
}

}
}

sql question

–create table aryan (name varchar(30),branch varchar(30),cgpa float);
–insert into aryan values(‘ghi’,’MEC’,7);
select *from aryan;
select branch,min(cgpa) from aryan group by branch;

question1:

show the name and course code of the student having minimum cgpa in each branch.
ans:

select  name,branch from aryan where (branch,cgpa)=any(select branch,min(cgpa) from aryan group by branch);

DBMS 24/02/2015

Capture

–create table employee999 (e_id int primary key,e_name varchar(30));
–insert into employee999 values(6,’alisha’);
–create table course999 (c_id int primary key,c_name varchar(30));
–insert into course999 values(103,’os’);
–create table t999 (c_id int references course999(c_id),e_id int references employee999(e_id));
–insert into t999 values(103,2);

Question:1

show name of teacher who is teaching networks.

ans:

using sub query:

select e_name from employee999 where e_id=any( select e_id from t999 where c_id=(select c_id from course999 where c_name=’network’));

using sub query and join

select e_name from employee999 where e_id=any (select t999.e_id from t999 inner join course999 on course999.c_id=t999.c_id where course999.c_name=’network’);

sachin java

interface car
{
public int price( int price);
}

class vehicle implements car
{
public int price(int price )
{
return(price);
}
}

class showInterface implements car
{
public int price(int price)
{
return(price);
}
}

class NewMain
{
public static void main(String args[])
{
vehicle v = new vehicle();
showInterface s = new showInterface();
car c;
c =v;
System.out.println(“Price of vehicle = “+ c.price(20000));

c = s;
System.out.println(“Area Of Triangle = “+ c.price(100000));
}
}

Java (12/02/2015) package

output

letss

1: Create package <abc> with <employee> class

package abc;
public class employee{
String name=”Aryan”;
String design=”Developer”;
public void show(){
System.out.println(“******************* Detail **********************”);
System.out.println(“Name : “+name+”\tDesignation : “+design);
System.out.println(“************************************************”);
}
}

2. Create 2nd package <def> with class <department>

package def;

import java.util.Scanner;
import abc.employee;
public class department extends employee{
String dept;
public void show(){
Scanner x=new Scanner(System.in);
System.out.println(“\nEner  D1 ->  D2 ->  ->  D3”);
dept=x.nextLine();
if(dept.matches(“d1”))
{
System.out.println(“***************** Department : CSE *****************”);
}
if(dept.matches(“d2”))
{
System.out.println(“****************   Department : MECH ****************”);
}
if(dept.matches(“d3”))
{
System.out.println(“***************** Department : IT *********************”);
}

}

}

3. Import <abc> and <def> package in class <hello>

import abc.employee;
import def.department;
public class hello{
public static void main(String[] args)
{
employee dt=new department();
employee emp=new employee();
emp.show();
dt.show();
}
}
}
}

DBMS EVALUTION

Table for employee having attributes (emp_id, emp_name, emp_dept)

Table for branch (emp_id, emp_current_branch, emp_salary)

Enter 5 dummy records in database

  • All the columns should be Not Null

  • Emp_salary should not be greater than 25000

-> create table emp420(emp_id number(10) primary key,emp_name varchar(30) not null,emp_dept varchar(30) not null )

>>>>create table branch420(emp_id number(10) not null,emp_current_branch varchar(30) not null,emp_salary number(10) not null check(emp_salary >=25000 ))

  • Show the emp_id and emp_current branch for those having id E1001.

  • ->1.select emp_id,emp_current_branch from branch420 where emp_id=111

  • Match the pattern for Emp_name who have last alphabet ‘R’ in their name.

->2.select *from emp420 where emp_name like ‘%d’

  • Count number of employee working in ‘HR’ department.

  • ->3.select count(emp_dept) from emp420 where emp_dept=’HR’

  • Add a new column in Employee table as “Permanent Address”

  • >4.alter table emp420 add addres varchar(30)

  • Add a new column Company name and having the default entry as “COGNIZANT”

  • ->5.alter table emp420 add company varchar(30) default ‘COGNIZANT’

  • Put a restriction over branch table that it would can never insert any extra entry, that is not present in employee table.

  • (add foreign key)->alter table branch420 add foreign key(emp_id) references emp420(emp_id)

  • Update the size of emp_dept to 20

  • ->6.alter table emp420 modify emp_dept varchar(20)

  • Update the salary of employee E1001 from 10000 to 24000

  • update branch set emp_salary=24000 where emp_id=’111′

  • Rename the column “Permanent address” to “Address”

  • alter table emp420 remane column addres to permanent_address

jav Evalution

import java.util.*;
class worker
{
Scanner sc=new Scanner(System.in);
int hours_rate=100;
String name;
int no_days;
int hours=0;
int total;
String worker_type;
void get_info()
{
System.out.println(“Enter the worker name”);
name=sc.next();
System.out.println(“Enter the worker type”);
worker_type=sc.next();
System.out.println(“Enter the No of days”);
no_days=sc.nextInt();
for(int i=1;i<=no_days;i++)
{
System.out.println(“Enter hours for “+i+ “day”);
hours=sc.nextInt();
hours=hours+hours;

}

}

void pay()
{
total=hours*100;

}

void display()
{
System.out.println(“worker name : “+name);
System.out.println(“worker type : “+worker_type);
System.out.println(“No of Days  : “+no_days);
System.out.println(“Total hours : “+hours);
System.out.println(“Total amount to pay : “+total);
}

}
class abc
{
public  static void main(String args[])
{
worker w=new worker();
w.get_info();
w.pay();
w.display();

}
}