S.No. Date Name of The Experiment No. Marks Obtained Signature
S.No. Date Name of The Experiment No. Marks Obtained Signature
S.No. Date Name of The Experiment No. Marks Obtained Signature
4 Triggers 15
5 Functions 19
6 Procedures 23
7 Embedded SQL 27
9 Payroll Process 41
10 Banking System 47
Average =
CONTENTS
Ex No. : 1
Aim:
To write SQL Queries using Data Definition Language and
Data Manipulation Language
CREATE
Syntax:
Queries:
Table created.
Syntax:
Queries:
Table altered.
SQL> desc employee;
TRUNCATE:
Syntax:
Queries:
Table truncated.
no rows selected
DROP:
Syntax:
Queries:
Table dropped.
INSERT:
Syntax:
SQL> insert into <table_name> values(val1,……);
SQL> insert into <table_name> values(‘&col_name1’,……);
Queries:
1 row created.
SQL>
SELECT:
Syntax:
Queries:
SQL>
UPDATE:
Syntax:
Queries:
1 row updated.
SQL>
DELETE:
Syntax:
Queries:
1 row deleted.
SQL>
Contents Max. Marks Marks Obtained
Design 20
Development 20
Queries & Execution 20
Viva Voce 20
Record 20
Total 100
Result:
Ex No. : 2
Aim:
To write SQL queries implementing constraints with DDL and DML
Syntax:
Queries:
Table created.
Table created.
SQL> desc sample;
Name Null? Type
---------------- ----------------- ----------------------------
ID NUMBER(5)
NAME VARCHAR2(10)
Table created.
SQL> create table sample (id number(5) not null, name varchar2(10));
Table created.
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.
Result:
Ex No. : 3
Aim:
To a write a PL/SQL program to implement cursors.
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:
SQL> create table bank (ac_no number(11), name varchar2(10), balance number(5),
primary key(ac_no));
CURSORS
Algorithm:
For Deposit:
Queries:
For deposit:
For Withdraw:
Output:
For deposit:
SQL>
Contents Max. Marks Marks Obtained
Design 20
Development 20
Queries & Execution 20
Viva Voce 20
Record 20
Total 100
Result:
Ex No. : 4
Aim:
To a write a PL/SQL program to implement triggers.
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:
SQL> create table bank (ac_no number(11), name varchar2(10), balance number(5),
primary key(ac_no));
TRIGGERS
For Negative Balance:
Algorithm:
1. Create a trigger
2. Declare a trigger trig that fires before insert or update of balance from table
“bank”.
3. Use row level trigger using for each row
4. While inserting or updating if balance is in negative, report an error
5. End trigger
Queries:
SQL> create or replace trigger mytrig
before insert or update of balance on
scott.bank
for each row
begin
if :new.balance<0 then
raise_application_error(-20003,'Negative balance not allowed');
end if;
end;
/
For Low balance:
Algorithm:
1. Create a trigger
2. Declare a trigger trig that fires before insert or update of balance from table
“bank”.
3. Use row level trigger using for each row
4. While inserting or updating if balance is less than 450, report an error
5. End trigger
Queries:
Output:
1 row updated.
SQL>
Contents Max. Marks Marks Obtained
Design 20
Development 20
Queries & Execution 20
Viva Voce 20
Record 20
Total 100
Result:
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:
Queries:
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:
i) FACTORIAL
Result:
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:
Queries:
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> declare
a number(5):=&a;
begin
sq(a);
end;
/
Output:
i) ARITHMETIC OPERATIONS:
Result:
Ex No. : 7
Aim:
To write a java program to embedded SQL statement and execute the SQL
queries.
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:
SQL> create table bank (ac_no number(11), name varchar2(10), balance number(5),
primary key(ac_no));
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");
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");
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");
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");
Output:
For SELECT:
For Update:
For INSERT:
For DELETE:
Contents Max. Marks Marks Obtained
Design 20
Development 20
Queries & Execution 20
Viva Voce 20
Record 20
Total 100
Result:
Ex No. : 8
Aim:
To design and implementing Entity-Relationship model using Oracle and
Visual Basic
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:
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
Result:
Ex No. : 9
Aim:
To design a payroll processing and implementing the process using Oracle and
Visual Basic
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:
SQL> insert into payroll values(&id, '&name', &dob, &exp, '&gender', &age, '&addr',
&doj, &bpay, &hra, &ta, &pf);
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:
Result:
Ex No. : 10
Aim:
To design a banking system and implementing the process using Oracle and
Visual Basic
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:
SQL> create table bank( ac_no number(11), name varchar2(10), balance number(5),
primary key(ac_no));
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:
Coding for Form Active (when ever the form gets active) :
Result:
Ex No. : 11
Aim:
To design a Library information system and implementing the process using
Oracle and Visual Basic
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:
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:
Result: