Dbms Record
Transcript of Dbms Record
S.No. Date Name of the ExperimentPage No.
Marks Obtained
Signature
1Data Definition Language and Data Manipulation Language
1
2Database Language with Constraints
7
3 Cursors 10
4 Triggers 15
5 Functions 19
6 Procedures 23
7 Embedded SQL 27
8 Entity Relationship Model 36
9 Payroll Process 41
10 Banking System 47
11 Library Information System 53
Average =
CONTENTS
Ex No. : 1
Aim:To write SQL Queries using Data Definition Language and
Data Manipulation Language
DATA DEFINITION LANGUAGE
CREATE
Syntax:
SQL> create table <table_name> ( col_name1, datatype(size),………..);SQL> create table <table_name> as select * from <source_table_name>
Queries: SQL> create table employee(emp_id number(5),emp_name varchar2(10), salary number(6));
Table created.
SQL> desc employee; Name Null? Type ----------------------------------------- ---------- ---------------------------- EMP_ID NUMBER(5) EMP_NAME VARCHAR2(10) SALARY NUMBER(6)
SQL> create table emp as select * from employee;Table created.
SQL> desc emp; Name Null? Type ----------------------------------------- ---------- ---------------------------- EMP_ID NUMBER(5) EMP_NAME VARCHAR2(10) SALARY NUMBER(6)
ALTER:
Syntax:
SQL> alter table <table_name> add( new col_name1, datatype(size),………..);
Queries:
SQL> alter table employee add(experience number(2));
Table altered.SQL> desc employee;
Name Null? Type ----------------------------------------- ---------- ---------------------------- EMP_ID NUMBER(5) EMP_NAME VARCHAR2(10) SALARY NUMBER(6) EXPERIENCE NUMBER(2)
TRUNCATE:
Syntax:
SQL> truncate table <table_name>;
Queries:
SQL> truncate table employee;
Table truncated.
SQL> desc employee; Name Null? Type ----------------------------------------- ---------- ---------------------------- EMP_ID NUMBER(5) EMP_NAME VARCHAR2(10) SALARY NUMBER(6) EXPERIENCE NUMBER(2)
SQL> select * from employee;
no rows selected
DROP:
Syntax:
SQL>drop table <table_name>;
Queries:
SQL> drop table employee;
Table dropped.
SQL> desc employee;ERROR:ORA-04043: object employee does not exist
DATA MANIPULATION LANGUAGE
INSERT:
Syntax:SQL> insert into <table_name> values(val1,……);SQL> insert into <table_name> values(‘&col_name1’,……);
Queries:
SQL> insert into employee values(1006,'Ram',8500);1 row created.
SQL> insert into employee values(&emp_no,'&name',&sal);Enter value for emp_no: 1007Enter value for name: ranjithEnter value for sal: 15000old 1: insert into employee values(&emp_no,'&name',&sal)new 1: insert into employee values(1007,'ranjith',15000)
1 row created.
SQL> select * from employee; EMP_ID EMP_NAME SALARY ------------- --------------------- ------------- 1006 Ram 8500 1007 Ranjith 15000
SQL>
SELECT:
Syntax:
SQL> select *from <table_name>;
Queries:
SQL> select * from employee;
EMP_ID EMP_NAME SALARY ------------- --------------------- ------------- 1006 Ram 8500 1007 Ranjith 15000
SQL>
UPDATE:
Syntax:
SQL> update <table_name> set col_name1=value where col_name2=value;
Queries:
SQL> update employee set Salary=&sal where emp_id=&emp_id;Enter value for sal: 9200Enter value for emp_id: 1006old 1: update employee set experience=&exp where emp_id=&emp_idnew 1: update employee set experience=5 where emp_id=1006
1 row updated.
SQL> select * from employee;
EMP_ID EMP_NAME SALARY ------------- --------------------- ------------- 1006 Ram 9200 1007 Ranjith 15000
SQL>
DELETE:
Syntax:
SQL> Delete from <table_name> where col_name=value;
Queries:
SQL> delete from employee where emp_id=1007;
1 row deleted.
SQL> select * from employee;
EMP_ID EMP_NAME SALARY ------------- --------------------- ------------- 1006 Ram 9200 SQL>
Result:
Contents Max. Marks Marks ObtainedDesign 20Development 20Queries & Execution 20Viva Voce 20Record 20Total 100
Ex No. : 2
Aim:To write SQL queries implementing constraints with DDL and DML
Syntax:
SQL> create table <table_name> ( col_name1, datatype(size),……….., primary key(col_name1,….) );
SQL> create table <table_name> ( col_name1, datatype(size),……….., unique(col_name1,….) );
SQL> create table <table_name> ( col_name11, datatype(size),……….., foreign key(col_name11,….) as references <source_table_name>(col_name21,… );
SQL> create table <table_name> (col_name1 datatype(size) not null,………);SQL> create table <table_name>(col_name1 datatype(size),…..,
check(col_name1 in value));SQL> create table <table_name>(col_name1 datatype(size),…..,
check(col_name1 not in value));SQL> create table <table_name>(col_name1 datatype(size),…..,
check(col_name1 between value1 and value2));
Queries:
SQL> create table sample(id number(5), name varchar2(10), primary key(id));
Table created.
SQL> desc sample; Name Null? Type ---------------- ----------------- ---------------------------- ID NOT NULL NUMBER(5) NAME VARCHAR2(10)
SQL> create table sample(id number(5), name varchar2(10), unique(id));
Table created.
SQL> desc sample; Name Null? Type ---------------- ----------------- ---------------------------- ID NUMBER(5) NAME VARCHAR2(10)
SQL> create table samp (id number(5), name varchar2(10), foreign key(id) references sample(id));
Table created.
SQL> desc samp; Name Null? Type ---------------- ----------------- ---------------------------- ID NUMBER(5) NAME VARCHAR2(10)
SQL> create table sample (id number(5) not null, name varchar2(10));
Table created.
SQL> desc sample; Name Null? Type ---------------- ----------------- ---------------------------- ID NOT NULL NUMBER(5) NAME VARCHAR2(10)
SQL> create table sample (id number(5), name varchar2(10), check(id in 2000));Table created.
SQL> create table sample (id number(5), name varchar2(10), check(id not in 2000));Table created.
SQL> create table sample (id number(5), name varchar2(10), check(id between 2000 and 3000));
Table created.
Result:
Contents Max. Marks Marks ObtainedDesign 20Development 20Queries & Execution 20Viva Voce 20Record 20Total 100
Ex No. : 3
Aim:To a write a PL/SQL program to implement cursors.
For Creating Database:
Algorithm:
1. Create a database with SQL for "bank" table with attributes "ac_no", "name" and "balance”.
2. Set "ac_no" as primary key for that table.
Queries:
For creating database for “bank”
SQL> create table bank (ac_no number(11), name varchar2(10), balance number(5), primary key(ac_no));
SQL> insert into bank values(&ac_no,'&name',&balance);
CURSORS
Algorithm:
For Deposit:
1. Start the procedure named withdraw2. Declare 2 variables to get 2 integers3. Declare a cursor named cur4. get the balance into the cursor for the given account no5. open the cursor and fetch the data into the variables6. to update the current balance subtract the given amount to the existing balance7. exit loop when cursor fetches null value8. close cursor and end the procedure
For withdraw:1. Start the procedure2. Declare two variables as number for ac_no and amount.3. Declare a cursor named cur4. get the balance into the cursor for the given account no5. open the cursor and fetch the data into the variables6. to update the current balance add the given amount to the existing balance7. close cursor and end the procedure
Queries:
For deposit:
SQL> create or replace procedure deposit(m number,n number) asc number;cursor cur is select balance from scott.bank where ac_no=m;begin
open cur;loop
fetch cur into c;update bank set balance=c+n where bank.ac_no=m;exit when cur%NOTFOUND;
end loop;close cur;
end;/
For Withdraw:
SQL> create or replace procedure withdraw(m number,n number) asc number;cursor cur is select balance from scott.bank where ac_no=m;begin
open cur;loop
fetch cur into c;update bank set balance=c-n where bank.ac_no=m;exit when cur%NOTFOUND;
end loop;close cur;
end;/
Database for the table “bank”:
SQL> desc bank
Name Null? Type----------------------------------- ----------------- ---------------------------- AC_NO NOT NULL NUMBER(11) NAME VARCHAR2(10) BALANCE NUMBER(5)
Output:
For deposit:
SQL> select * from bank;
AC_NO NAME BALANCE ------------- ------------------------- ----------------- 6152004 SaravanaKumar.S 2600 6152005 SathyaAnand.R 7200 6152006 Saravanan.A 2500
SQL> exec deposit(6152004,500)
PL/SQL procedure successfully completed.
SQL> select * from bank;
AC_NO NAME BALANCE -------------- ------------------------ ----------------- 6152004 SaravanaKumar.S 3100 6152005 SathyaAnand.R 7200 6152006 Saravanan.A 2500
For Withdraw:
SQL> select * from bank;
AC_NO NAME BALANCE -------------- ------------------------ ----------------- 6152004 SaravanaKumar.S 3100 6152005 SathyaAnand.R 7200 6152006 Saravanan.A 2500
SQL> exec withdraw(6152004,500);
PL/SQL procedure successfully completed.
SQL> select * from bank;
AC_NO NAME BALANCE -------------- ------------------------ ----------------- 6152004 SaravanaKumar.S 2600 6152005 SathyaAnand.R 7200 6152006 Saravanan.A 2500
SQL>
Result:
Contents Max. Marks Marks ObtainedDesign 20Development 20Queries & Execution 20Viva Voce 20Record 20Total 100
Ex No. : 4
Aim:To a write a PL/SQL program to implement triggers.
For Creating Database:
Algorithm:3. Create a database with SQL for "bank" table with attributes "ac_no", "name" and
"balance”.4. Set "ac_no" as primary key for that table.
Queries:
For creating database for “bank”
SQL> create table bank (ac_no number(11), name varchar2(10), balance number(5), primary key(ac_no));
SQL> insert into bank values(&ac_no,'&name',&balance);
TRIGGERSFor Negative Balance:
Algorithm:1. Create a trigger2. Declare a trigger trig that fires before insert or update of balance from table
“bank”.3. Use row level trigger using for each row4. While inserting or updating if balance is in negative, report an error5. End trigger
Queries:SQL> create or replace trigger mytrig
before insert or update of balance onscott.bankfor each rowbegin
if :new.balance<0 thenraise_application_error(-20003,'Negative balance not allowed');
end if;end;/
For Low balance:
Algorithm:
1. Create a trigger2. Declare a trigger trig that fires before insert or update of balance from table
“bank”.3. Use row level trigger using for each row4. While inserting or updating if balance is less than 450, report an error5. End trigger
Queries:
SQL> create or replace trigger trigbefore insert or update of balance onscott.bankfor each rowbegin
if :new.balance<450 thenraise_application_error(-20003,’Balance low');
end if;end;/
Database for the table “bank”:
SQL> desc bank
Name Null? Type----------------------------------- ----------------- ---------------------------- AC_NO NOT NULL NUMBER(11) NAME VARCHAR2(10) BALANCE NUMBER(5)
Output:
SQL> update bank set balance=200 where ac_no=6152004;update bank set balance=200 where ac_no=6152004
*ERROR at line 1:ORA-20003: Balance lowORA-06512: at "SCOTT.TRIG", line 3ORA-04088: error during execution of trigger 'SCOTT.TRIG'
SQL> update bank set balance=-200 where ac_no=6152004;update bank set balance=-200 where ac_no=6152004
*ERROR at line 1:ORA-20003: Negative balance not allowedORA-06512: at "SCOTT.MYTRIG", line 3ORA-04088: error during execution of trigger 'SCOTT.MYTRIG'
SQL> update bank set balance=2600 where ac_no=6152004;
1 row updated.
SQL>
Result:
Contents Max. Marks Marks ObtainedDesign 20Development 20Queries & Execution 20Viva Voce 20Record 20Total 100
Ex No. : 5
Aim:To a write a PL/SQL program to find factorial of a number and first ‘n’ numbers
of Fibonacci series using functions.
i) FACTORIAL
Algorithm:
1. Create a function named as fact.2. Declare the variable N, T.3. Get the value of N.4. If n=1 then return 1.5. If n>1 then return n*fact(n-1).6. Execute the value of factorial using dbms_output.put_line().7. End of program.
Queries:
SQL> create or replace function fact(n in number) return number is
beginIf n=1 then
return 1;Else
Return n*fact(n-1);End if;
end;/
SQL> declareN number;T number;
beginN:=&NO;T:=fact(N);Dbms_output.put_line(‘THE FACTORIAL IS ‘||T);
end;/
ii) FIBONACII SERIES
Algorithm:1. Create a function fib.2. Declare the variables I and N.3. If n=1 then return 0.4. If n=2 then return 1.5. If n>2 then return fib(n-1)+fib(n-2).6. Execute the series using dbms_output.put_line().7. End of program.
Queries:
SQL> create or replace function fib(n in number)return number isbegin
If n=1 then return 0;
End if;If n=2 then
return 1;Else
Return fib(n-1)+fib(n-2);End if;
end;/
SQL> declare i number;n number;f number;
beginN:=&NO;Dbms_output.put_line(‘FIBONACCI SERIES IS’);For I in 1..N Loop
F:=fib(I);Dbms_output.put_line (F);
End loop;end;/
Output:
i) FACTORIAL
Enter value for no: 5old 5: N:=&NO;new 5: N:=5;THE FACTORIAL IS 120
ii) FIBONACII SERIES
Enter value for no: 5old 6: N:=&NO;new 6: N:=5;FIBONACCI SERIES IS01123
Result:
Contents Max. Marks Marks ObtainedDesign 20Development 20Queries & Execution 20Viva Voce 20Record 20Total 100
Ex No. : 6
Aim:To a write a PL/SQL program to perform arithmetic operations and to find square
of a number using procedures.
i) ARITHMETIC OPERATIONS:
Algorithm:
1. Create the procedure arith using SQL.2. Declare two variables for performing arithmetic operations.3. Declare the variables for storing the result.4. Perform the operations addition, subtraction, multiplication and division using the
variables.5. Print the result.
Queries:
SQL> create or replace procedure arith(n1 in number, n2 in number) asadd1 number(5);sub1 number(5);mul1 number(5);div1 number(5);
beginadd1:=n1+n2;sub1:=n1-n2;mul1:=n1*n2;div1:=n1/n2;dbms_output.put_line ('Addition value '||add1); dbms_output.put_line ('Subtraction value '||sub1);dbms_output.put_line ('Multiplication value '||mul1);dbms_output.put_line ('Division value '||div1);
end;/
SQL> declarea number(5):=&a;b number(5):=&b;
beginarith (a,b);
end;/
ii) SQUARE Of GIVEN NUMBER:
Algorithm:1. Create the procedure in SQL to find the square of given numbers.2. Declare the variables for performing the operations.3. Declare the variables to store the result.4. Perform the operation of squaring the given numbers using the variables.5. Print the result.6. Display the result using dbms commands.
Queries:
SQL> create or replace procedure sq(a1 in number) asb1 number;res number;
beginres:=a1*a1;b1:=res;dbms_output.put_line('Square of a:'||b1);
end;/
SQL> declarea number(5):=&a;
beginsq(a);
end; /
Output:
i) ARITHMETIC OPERATIONS:
Enter value for a: 20old 2: a number(5):=&a;new 2: a number(5):=20;Enter value for b: 4old 3: b number(5):=&b;new 3: b number(5):=4;Addition value 24Subtraction value 16Multiplication value 80Division value 5
ii) SQUARE Of GIVEN NUMBER:
Enter value for a: 5old 2: a number(5):=&a;new 2: a number(5):=5;Square of a:25
Result:
Contents Max. Marks Marks ObtainedDesign 20Development 20Queries & Execution 20Viva Voce 20Record 20Total 100
Ex No. : 7
Aim:To write a java program to embedded SQL statement and execute the SQL
queries.
For Creating Database:
Algorithm:
5. Create a database with SQL for "bank" table with attributes "ac_no", "name" and "balance”.
6. Set "ac_no" as primary key for that table.
Queries:
For creating database for “bank”
SQL> create table bank (ac_no number(11), name varchar2(10), balance number(5), primary key(ac_no));
SQL> insert into bank values(&ac_no,'&name',&balance);
For Java Programing:
For INSERT:
Algorithm:1. Establish the connection between jdbc and odbc using
DriverManager.GetConnection ().2. Now insert the values into the table.3. Display the results.
Program:
import java.io.*;import java.sql.*;
class Ins{
public static void main(String a[]) throws IOException{
DataInputStream in=new DataInputStream(System.in);String str1,str2,str3,str4;System.out.println("Enter the Ac_no:");str1=in.readLine();System.out.println("Enter the Name:");str2=in.readLine();System.out.println("Enter the Balance:");str3=in.readLine();System.out.println("Enter the Ac_Type:");str4=in.readLine();ResultSet result;String str=new String();str="insert into bank values ("+str1+",'"+str2+"',"+str3+",'"+str4+"')";try{
/*Method1 using jdbc-odbc*///Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//Connection con = DriverManager.getConnection("jdbc:odbc:MyProj","scott","tiger");
/*Method2 using jdbc-oci*/DriverManager.registerDriver(new oracle.jdbc.OracleDriver());Connection con=DriverManager.getConnection("jdbc:oracle:oci8:scott/tiger@db9");
Statement stat=con.createStatement();stat.executeUpdate(str);System.out.println("\n1 row inserted.");
}catch(Exception e){
System.out.println("\nError:"+e);}
}}
For SELECT:
Algorithm:1. Insert the values into the table using SQL.2. Establish the connection between jdbc and odbc using
DriverManager.GetConnection ().3. Select the row(s) to be displayed.4. Display the results.
Program:
import java.io.*;import java.sql.*;
class Sel{
public static void main(String a[])throws IOException{
ResultSet result;String str1=new String();str1="Select * from bank ";try{
/*Method1 using jdbc-odbc*///Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//Connection con=DriverManager.getConnection("jdbc:odbc:MyProj","scott","tiger");
/*Method2 using jdbc-oci*/DriverManager.registerDriver(new oracle.jdbc.OracleDriver());Connection con=DriverManager.getConnection("jdbc:oracle: oci8:scott/tiger@db9");
Statement stat=con.createStatement();result=stat.executeQuery(str1);System.out.println("\nAc_No\tName\t\t\tBalance\tAc_Type\n");System.out.println("-----------------------------------------------\n");while(result.next()){
System.out.println( result.getString(1) + "\t" + result.getString(2) + "\t\t" + result.getString(3) + "\t" + result.getString(4));
}}catch(Exception e){
System.out.println("\nError:"+e);}
}}For DELETE:
Algorithm:1. Insert the values into the table using SQL.2. Get the acc_no that is to be deleted.3. Establish the connection between jdbc and odbc using
DriverManager.GetConnection ().4. Delete the row from the table.5. Display the results.
Program:
import java.io.*;import java.sql.*;
class Del{
public static void main(String a[]) throws IOException{
DataInputStream in=new DataInputStream(System.in);String str;System.out.println("Enter the Ac_no:");str=in.readLine();ResultSet result;String str1=new String();str1="delete from bank where ac_no="+str;try{
/*Method1 using jdbc-odbc*///Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//Connection con=DriverManager.getConnection("jdbc:odbc:MyProj","scott","tiger");
/*Method2 using jdbc-oci*/DriverManager.registerDriver(new oracle.jdbc.OracleDriver());Connection con=DriverManager.getConnection("jdbc:oracle: oci8:scott/tiger@db9");
Statement stat=con.createStatement();stat.executeUpdate(str1);System.out.println("\n1 row Deleted.");
}catch(Exception e){
System.out.println("\nError:"+e);}
}}
For UPDATE:
Algorithm:1. Insert the values into the table using SQL.2. To Update, enter the acc_no and the new amount.3. Validate the connection between jdbc and odbc using
DriverManager.GetConnection ().4. Update the table using executeUpdate command in the embedded SQL.5. Display the results.
Program:
import java.io.*;import java.sql.*;import java.lang.*;
class Upd{
public static void main(String a[])throws IOException{
DataInputStream in=new DataInputStream(System.in);String str4,str3;Double d1,d2;System.out.println("Enter the Ac_no:");str4=in.readLine();System.out.println("Enter the Deposit_Amount:");str3=in.readLine();d1=Double.parseDouble(str3);ResultSet result;String str1=new String();String st;String str2=new String();str2="select * from bank where ac_no="+str4;try{
/*Method1 using jdbc-odbc*///Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");//Connection con=DriverManager.getConnection("jdbc:odbc:MyProj","scott","tiger");
/*Method2 using jdbc-oci*/DriverManager.registerDriver(new oracle.jdbc.OracleDriver());Connection con=DriverManager.getConnection("jdbc:oracle: oci8:scott/tiger@db9");Statement stat=con.createStatement();result=stat.executeQuery(str2);result.next();d2=Double.parseDouble(result.getString(3));d1=d1+d2;st=Double.toString(d1);
str1="update bank set balance="+st+"where ac_no="+str4;stat.executeUpdate(str1);System.out.println("\n1 row Updated.");
}catch(Exception e){
System.out.println("\nError:"+e);}
}}
Database for the table “bank”:
SQL> desc bank
Name Null? Type----------------------------------- ----------------- ---------------------------- AC_NO NOT NULL NUMBER(11) NAME VARCHAR2(10) BALANCE NUMBER(5)
Output:
For SELECT:
For Update:
For INSERT:
For DELETE:
Result:
Ex No. : 8
Contents Max. Marks Marks ObtainedDesign 20Development 20Queries & Execution 20Viva Voce 20Record 20Total 100
Aim:To design and implementing Entity-Relationship model using Oracle and
Visual Basic
For Creating Backend :
Algorithm:1. Create a database using SQL for "student" table with attributes name, regno,
DOB, address1, address2, state, zipcode.2. Set the regno of "Student" table as primary key.3. Create another database using SQL for table "test" with attributes regno,
DBMS, CN, POM, MP_MC, DM, TOC.4. Set regno of “Test” table as primary key.
Queries:
For creating the database “student”:SQL> create table student (regno number(10), name varchar2(10), dob date,
addr1 varchar2(10), addr2 varchar2(10), state varchar2(10), zipcode number(10), primary key (regno));
SQL> insert into student values (®no, '&name', &dob, '&addr1', '&addr', '&state', &zipcode);
For creating the database “test”:SQL> create table test (regno number(10), DBMS number(3), CN number(3),
POM number(3), MP_MC number(3), DM number(3), TOC number(3), primary key (regno));
SQL> insert into test values(®no,'&name',&dob,'&addr1','&addr','&state',&zipcode);
For Creating Frontend:
Algorithm:1. Create a form with form name “frm_Personal” for displaying the personal
details.2. Create a form with form name “frm_Mark” for displaying the Marks.3. Create a form with form name “frm_Student” with 3 command button for
"Student", "Mark" and “close” add the corresponding codes for the button.4. On clicking the Student button, the personal details of all the student in the
database are displayed.5. On clicking the Test button, the marks of the students whose register number
matches with those in Student table alone are displayed.Coding:
Form name = frm_Student
Coding for Student command :
Private Sub cmdPersonal_Click()frm_Personal.Show
End Sub
Coding for Test command :
Private Sub cmdMark_Click()frm_Mark.Show
End Sub
Coding for Close command :
Private Sub cmdClose_Click()Unload me
End Sub
Form name = frm_Personal
Coding for Close command :
Private Sub cmdClose_Click()Unload me
End Sub
Form name = frm_Mark
Coding for Close command :
Private Sub cmdClose_Click()Unload me
End Sub
Database for the table “student’:
SQL> desc student
Name Null? Type----------------------------------- ----------------- ----------------------------REGNO NOT NULL NUMBER(10)NAME VARCHAR2(10)DOB DATEADDR1 VARCHAR2(10)ADDR2 VARCHAR2(10)STATE VARCHAR2(10)ZIPCODE NUMBER(10)
Database for the table “test”:
SQL> desc test
Name Null? Type----------------------------------- ----------------- ----------------------------REGNO NOT NULL NUMBER(10)DBMS NUMBER(3)CN NUMBER(3)POM NUMBER(3)MP_MC NUMBER(3)DM NUMBER(3)TOC NUMBER(3)
Output:
Result:
Ex No. : 9
Contents Max. Marks Marks ObtainedDesign 20Development 20Queries & Execution 20Viva Voce 20Record 20Total 100
Aim:To design a payroll processing and implementing the process using Oracle and Visual Basic
For Creating Backend:
Algorithm:
1. Create a database using SQL for “payroll” table with attributes emp_id, emp_name, DOB, experience, gender, age, address, DOJ, basic salary, HRA, PF and TA.
2. Set primary key for emp_id
Queries:
For creating the database “payroll”:
SQL> create table payroll( id number(5), name varchar2(10), dob date,exp number(4), gender varchar2(10), age number(3), addr varchar2(10), doj date, bpay number(10), hra number(5,2), ta number(5,2), pf number(5,2));
SQL> insert into payroll values(&id, '&name', &dob, &exp, '&gender', &age, '&addr', &doj, &bpay, &hra, &ta, &pf);
For Creating Frontend:
Algorithm:
1. Place a form with from name "frm_Main" and Place 6 command buttons for “add”, "update", "delete", "allowance", "report" and "exit" and enter corresponding coding.
2. "add" is used to add new empolyee details.3. "update" is used to make changes in existing details of an employee.4. "delete" is used to remove details of particular employee.5. "allowance" will perform calculation for allowance of an employee.6. "report" will display employee name,emp_id ,gross salary and net salary.7. Place form with form name "frm_Report" and place 3 command buttons for
"back", "print" and "exit".8. "Back" will take us to "frm_Main".
Coding:
Form name = frm_Main
Coding for Add command :
Private Sub cmdAdd_Click()Adodc1.Recordset.AddNew
End Sub
Coding for update command :
Private Sub cmdUpdate_Click()Adodc1.Recordset.UpdateMsgBox "Record Updated"
End Sub
Coding for Delete command :
Private Sub cmdDelete_Click()Adodc1.Recordset.DeleteMsgBox "Record Deleted"
End Sub
Coding for Allowance command :
Private Sub cmdAllow_Click()txt_HRA.Text = txt_Basic.Text / 100 * 12txt_PF.Text = txt_Basic.Text / 100 * 8txt_TA.Text = txt_Basic.Text / 100 * 4
End Sub
Coding for Report command :
Private Sub cmdReport_Click()frm_Report.Showfrm_Report.txt_EmpName.Text = txt_EmpName.Textfrm_Report.txt_EmpID.Text = txt_EmpID.Textfrm_Report. txt_NetSal.Text = txt_Basic.Textfrm_Report.txt_GrossSal.Text = Val(txt_Basic.Text) + Val(txt_HRA.Text) – Val(txt_PF.Text) +Val(txt_TA.Text)
End Sub
Coding for Exit command :
Private Sub cmdExit_Click()Unload me
End Sub
Form name = frm_Report
Coding for Back command :
Private Sub cmdBack_Click()Frm_Main.Show
End Sub
Coding for Print command :
Private Sub cmdPrint_Click()Frm_Main.printform
End Sub
Coding for Exit command :
Private Sub cmdExit_Click()Unload me
End Sub
Database for the table “payroll”:
SQL> desc payroll
Name Null? Type----------------------------------- ----------------- ----------------------------ID NUMBER(5)NAME VARCHAR2(10)DOB DATEEXP NUMBER(4)GENDER VARCHAR2(10)AGE NUMBER(3)ADDR VARCHAR2(10)DOJ DATEBPAY NUMBER(10)HRA NUMBER(5,2)TA NUMBER(5,2)PF NUMBER(5,2)
Output:
Result:
Contents Max. Marks Marks ObtainedDesign 20Development 20Queries & Execution 20Viva Voce 20Record 20Total 100
Ex No. : 10
Aim:To design a banking system and implementing the process using Oracle and Visual Basic
For Creating Backend :
Algorithm:
1. Create a database using SQL for "bank" table with attributes "ac_no", "name" and "balance”
2. Set "ac_no" as primary key for that table.
Queries:
For creating the database “bank’:
SQL> create table bank( ac_no number(11), name varchar2(10), balance number(5), primary key(ac_no));
SQL> insert into bank values(&ac_no, '&name', &balance);
For Creating Frontend:
Algorithm:
1. Place a form with form name "frm_Main" and caption and 4 command buttons for "deposit", "withdraw", "Balance Enquiry" and “Exit” and enter corresponding codings.
2. "Deposit " will add money to the account if we give account number and amount to be added. If given account number is wrong, then the message "NOT FOUND" will be displayed.
3. "withdraw" will drop money from the account .4. "Balance Enquiry" will display the current balance in given account number.
5. Place a form with form name "process" and place 2 buttons for “process” and “cancel" and enter corresponding coding.
Coding:
Form name = frm_Main
Coding for Deposit command :
Private Sub cmdDeposit_Click()frm_process.Showfrm_Main.Caption = "Deposit System"frm_process.cmdProcss.Caption = “Deposit”
End Sub
Coding for Withdraw command :
Private Sub cmdWithdraw_Click()frm_process.Showfrm_Main.Caption = "Withdraw System"frm_process.cmdProcss.Caption = “Withdraw”
End Sub
Coding for Balance Enquiry command :
Private Sub cmdBalance_Click()frm_process.Showfrm_Main.Caption = "Balance Enquiry System"frm_process.lblAmt.Visible = Falsefrm_process.lblAmt.Visible = Falsefrm_process.cmdProces.Caption = "Check"
End Sub
Coding for Close command :
Private Sub cmdClose_Click()Unload me
End Sub
Coding for Form Active (when ever the form gets active) :
Private Sub frm_Main_Activate()
frm_Main.Caption = "Bank Processing System"End Sub
Form name = frm_Process
Coding for Process command :
Private Sub cmdProcess_Click()Dim str, str1, str2 As Stringstr = "ac_no="str1 = txt_AcNo.Textstr2 = str + str1If cmdProcess.Caption = "Check" Then
Adodc1.Recordset.Filter = str2lblBalance.Visible = True
End IfIf cmdProcess.Caption = "Withdraw" Then
Adodc1.Recordset.Filter = str2lblBalance.Visible = FalseIf lblBalance.Caption = "" Then
MsgBox ("not found")Else
val1 = lblBalance.Captionval2 = Text2.Textval3 = val1 - val2lblBalance.Caption = val3Adodc1.Recordset.UpdateAdodc1.Recordset.SavelblBalacne.Visible = True
End IfEnd IfIf cmdProcess.Caption = "Deposit" Then
Adodc1.Recordset.Filter = str2lblBalance.Visible = FalseIf lblBalance.Caption = "" Then
MsgBox ("not found")Else
val1 = lblBalance.Captionval2 = txtAmt.Textval3 = Val(val1) + Val(val2)lblBalance.Caption = val3Adodc1.Recordset.UpdateAdodc1.Recordset.Save
lblBalance.Visible = TrueEnd If
End IfEnd Sub
Coding for Cancel command :
Private Sub cmdCancel_Click()Unload Me
End Sub
Coding for Form Load (when ever form gets loaded) :
Private Sub frm_Process_Load()lblBalance.Visible = False
End Sub
Design of the table “bank”:
SQL> desc bank
Name Null? Type----------------------------------- ----------------- ---------------------------- AC_NO NOT NULL NUMBER(11) NAME VARCHAR2(10) BALANCE NUMBER(5)
Output:
Result:
Contents Max. Marks Marks ObtainedDesign 20Development 20Queries & Execution 20Viva Voce 20Record 20Total 100
Ex No. : 11
Aim:To design a Library information system and implementing the process using
Oracle and Visual Basic
For Creating Backend :
Algorithm:1. Create a database using SQL for “lib” table with attributes book_name, id, author,
publisher, ISBN, level, price and edition.2. Create another database using SQL for “member” table with member_id,
max_books and validity.3. Set primary key for member_id.
Queries:
For creating the database “library”:SQL> create table lib (id number(6), book_name varchar2(10), author varchar2(10),
ISBN varchar2(10), publisher varchar2(10), Book_level varchar2(10), price number(4),
edition varchar2(10));SQL> insert into library values (&id, '&name', '&author', '&ISBN', '&publisher', '&level',
'&price', '&edition');
For creating the database “member”:SQL> create table member (id number(10), max_books number(2), validity date,
primary key(id));SQL> insert into member values(&id, &max_books, &validity);
For Creating Frontend:
Algorithm:1. Place a form with form name "frm_Main" and 3 commands buttons for "book
details", "student details" and "close" and enter corresponding codings.2. If we click "student details", there appears a form (frm_Search), enter member_id
in it. If give member_id is correct then a form(frm_Member) will display the student name, maximum number of books and validity.
3. If we click "BookDetails", there appears a form (frm_Book) with menu consisting "search", "update" and "delete".
4. Using "search" menu, if we give book_name, then author, publisher, ISBN, id, level, price and edition will be displayed.
5. Using "Update" menu, we can make changes and save the record.6. Using "delete" menu, we can delete the unwanted book details.
Coding:
Form name = frm_Main
Coding for Book Details command :
Private Sub cmdBook_Click()frm_Book.Show
End Sub
Coding for Member Details command :
Private Sub cmdMember_Click()frmSearch.ShowfrmSearch.lblFind.Caption = "Member ID"
End Sub
Coding for Close command :
Private Sub cmdClose_Click()Unload me
End Sub
Form name = frm_Book
Coding for Delete menu :
Private Sub mnu_opt_del_Click()If Adodc1.Recordset.EOF = False Then
Adodc1.Recordset.DeleteAdodc1.Recordset.MoveNext
ElseMsgBox ("Error: Deleting record that does not exist.")
End IfEnd Sub
Coding for Exit menu :
Private Sub mnu_file_exit_Click()Unload Me
End Sub
Coding for Search menu :
Private Sub mnu_opt_search_Click()frm_Search.Show
End Sub
Coding for Update menu :
Private Sub mnu_opt_update_Click()Adodc1.Recordset.Update
End Sub
Form name = frm_Member
Coding for Ok Command :
Private Sub cmdOk_Click()Adodc1.Recordset.UpdateUnload Me
End Sub
Form name = frm_Search
Coding for Cancel Command :
Private Sub cmdCancel_Click()Unload Me
End Sub
Coding for Ok Command :
Private Sub cmdOk_Click()Dim a, b, c As StringIf lblFind.Caption = "Book Name" Then
b = "book_name="c = txtFind.Texta = b + "'" + c + "'"frm_Book.Adodc1.Recordset.Filter = aIf frm_Book.txtFind.Text <> "" Then
MsgBox ("Book Found")
ElseMsgBox ("Book Not Found")
End IfFrm_Book.Adodc1.RefreshUnload Me
End IfIf lblFind.Caption = "Member ID" Then
b = "Reg_no="c = txtFind.Texta = b + "'" + c + "'"frm_Member.Adodc1.Recordset.Filter = afrm_Member.ShowUnload Me
End IfEnd Sub
Database for the table “lib”:
SQL> desc lib
Name Null? Type----------------------------------- ----------------- ----------------------------ID NUMBER(6)BOOK_NAME VARCHAR2(10)AUTHOR VARCHAR2(10)ISBN VARCHAR2(10)PUBLISHER VARCHAR2(10)BOOK_LEVEL VARCHAR2(10)PRICE NUMBER(4)EDITION VARCHAR2(10)
Database for the table “member”: SQL> desc member
Name Null? Type----------------------------------- ----------------- ----------------------------ID NOT NULL NUMBER(10)MAX_BOOKS NUMBER(2)VALIDITY DATE
Output:
Result:
Contents Max. Marks Marks ObtainedDesign 20Development 20Queries & Execution 20Viva Voce 20Record 20Total 100