Professional Documents
Culture Documents
DISPLAYING VALUES:
SQL> select * from deposit;
ACNO CNAME BNAME AMOUNT ACDATE
---------- -------------------- -------------------- ---------- ---------
2317 prabha idappadi 10000 29-NOV-18
1199 anish idappadi 20000 29-NOV-18
4133 raja salem 20000 30-JAN-18
SQL>
2.INSERTING THE VALUES
TABLE CREATION:
SQL> create table job(jobid varchar(20) primary key,jobtitle varchar(20),minsal number(10,3),maxsal
number(10,5));
Table created.
SQL> create table employee(empno varchar(20) primary key,empname varchar(20),emp
sal number(10,5),empmob number(12),depno number(5));
Table created.
SQL> create table deposit(acno varchar(10),cname varchar(20),bname varchar(20),a
mount number(10,2),acdate date);
Table created.
SQL> create table borrow(loanno varchar(10),cname varchar(20),bname varchar(20),
amount number(10,2));
Table created.
SQL> commit;
Commit complete.
TABLE DESCRIPTION:
SQL> desc job;
Name Null? Type
----------------------------------------- -------- ----------------------------
JOBID NOT NULL VARCHAR2(20)
JOBTITLE VARCHAR2(20)
MINSAL NUMBER(10,3)
MAXSAL NUMBER(10,5)
SQL> desc employee;
Name Null? Type
----------------------------------------- -------- ----------------------------
EMPNO NOT NULL VARCHAR2(20)
EMPNAME VARCHAR2(20)
EMPSAL NUMBER(10,5)
EMPMOB NUMBER(12)
DEPNO NUMBER(5)
SQL> desc deposit;
Name Null? Type
----------------------------------------- -------- ----------------------------
ACNO VARCHAR2(10)
CNAME VARCHAR2(20)
BNAME VARCHAR2(20)
AMOUNT NUMBER(10,2)
ACDATE DATE
SQL> desc borrow;
Name Null? Type
----------------------------------------- -------- ----------------------------
LOANNO VARCHAR2(10)
CNAME VARCHAR2(20)
BNAME VARCHAR2(20)
AMOUNT NUMBER(10,2)
INSERTING VALUES
SQL> insert into job values('&jobid','&jobtitle',&minsal,&maxsal);
Enter value for jobid: ap317
Enter value for jobtitle: professor
Enter value for minsal: 20000
Enter value for maxsal: 50000
old 1: insert into job values('&jobid','&jobtitle',&minsal,&maxsal)
new 1: insert into job values('ap317','professor',20000,50000)
1 row created.
SQL> insert into job values('&jobid','&jobtitle',&minsal,&maxsal);
Enter value for jobid: gl904
Enter value for jobtitle: lecturer
Enter value for minsal: 10000
Enter value for maxsal: 30000
old 1: insert into job values('&jobid','&jobtitle',&minsal,&maxsal)
new 1: insert into job values('gl904','lecturer',10000,30000)
1 row created.
SQL> insert into job values('&jobid','&jobtitle',&minsal,&maxsal);
Enter value for jobid: ap950
Enter value for jobtitle: professor
Enter value for minsal: 15000
Enter value for maxsal: 40000
old 1: insert into job values('&jobid','&jobtitle',&minsal,&maxsal)
new 1: insert into job values('ap950','professor',15000,40000)
1 row created.
SQL> commit;
Commit complete.
SQL> insert into employee values('&empno','&empname',&empsal,&empmob,&depno);
Enter value for empno: 9042
Enter value for empname: prabhakaran
Enter value for empsal: 30000
Enter value for empmob: 9042442317
Enter value for depno: 1
old 1: insert into employee values('&empno','&empname',&empsal,&empmob,&depno)
new 1: insert into employee values('9042','prabhakaran',30000,9042442317,1)
1 row created.
SQL> insert into employee values('&empno','&empname',&empsal,&empmob,&depno);
Enter value for empno: 2317
Enter value for empname: anish
Enter value for empsal: 40000
Enter value for empmob: 9500871199
Enter value for depno: 2
old 1: insert into employee values('&empno','&empname',&empsal,&empmob,&depno)
new 1: insert into employee values('2317','anish',40000,9500871199,2)
1 row created.
SQL> insert into employee values('&empno','&empname',&empsal,&empmob,&depno);
Enter value for empno: 4133
Enter value for empname: raja
Enter value for empsal: 25000
Enter value for empmob: 9442794133
Enter value for depno: 3
old 1: insert into employee values('&empno','&empname',&empsal,&empmob,&depno)
new 1: insert into employee values('4133','raja',25000,9442794133,3)
1 row created.
SQL> commit;
Commit complete.
SQL> insert into deposit values('2317','prabha','idappadi',10000,'29-nov-18');
1 row created.
SQL> insert into deposit values('1199','anish','idappadi',20000,'29-nov-18');
1 row created.
SQL> insert into deposit values('4133','raja','salem',20000,'30-jan-18');
1 row created.
SQL> insert into deposit values(9894,'jaya','konganapuram',5000,'10-nov-18');
1 row created.
SQL> commit;
Commit complete.
SQL> insert into borrow values('l90424','prabha','idappadi',50000);
1 row created.
SQL> insert into borrow values('l9500','anish','idappadi',20000);
1 row created.
SQL> insert into borrow values('l9442','raja','salem',100000);
1 row created.
SQL> commit;
Commit complete
DISPLAYING THE VALUES
SQL> select * from job;
JOBID JOBTITLE MINSAL MAXSAL
-------------------- -------------------- ---------- ----------
ap317 professor 20000 50000
gl904 lecturer 10000 30000
ap950 professor 15000 40000
SQL> select * from employee;
EMPNO EMPNAME EMPSAL EMPMOB DEPNO
-------------------- -------------------- ---------- ---------- ----------
9042 prabhakaran 30000 9042442317 1
2317 anish 40000 9500871199 2
4133 raja 25000 9442794133 3
SQL> select * from deposit;
ACNO CNAME BNAME AMOUNT ACDATE
---------- -------------------- -------------------- ---------- ---------
2317 prabha idappadi 10000 29-NOV-18
1199 anish idappadi 20000 29-NOV-18
4133 raja salem 20000 30-JAN-18
9894 jaya konganapuram 5000 10-NOV-18
SQL> select * from borrow;
LOANNO CNAME BNAME AMOUNT
---------- -------------------- -------------------- ----------
l90424 prabha idappadi 50000
l9500 anish idappadi 20000
l9442 raja salem 100000
SQL> select acno,amount,cname,acdate from deposit where acdate between '1-nov-18' and '30-nov-18';
ACNO AMOUNT CNAME ACDATE
---------- ---------- -------------------- ---------
2317 10000 prabha 29-NOV-18
1199 20000 anish 29-NOV-18
9894 5000 jaya 10-NOV-18
SQL> select jobid,jobtitle from job where minsal>=15000;
JOBID JOBTITLE
-------------------- --------------------
ap317 professor
ap950 professor
SQL> select empname as name from employee where depno=1;
NAME
--------------------
Prabhakaran
SQL> select empno,empname from employee where depno between 0 and 2;
EMPNO EMPNAME
-------------------- --------------------
9042 prabhakaran
2317 anish
3.STRING FUNCTIONS
SQL> create table employee(empno number(10),empname varchar(20),empsal number(10
,2),depno number(5));
Table created.
SQL> insert into employee values(01,'anish',10000,10);
1 row created.
SQL> insert into employee values(02,'anand',20000,20);
1 row created.
SQL> insert into employee values(03,'aravinth',10000,15);
1 row created.
SQL> insert into employee values(05,'abc_xyx',20000,40);
1 row created.
SQL>
4. AGGREGATE FUNCTIONS AND SORTING
TABLE CREATION:
SQL> create table deposit(acno varchar(10),cname varchar(20),bname varchar(20),amount
number(10,2),acdate date);
Table created.
SQL> commit;
Commit complete.
SQL> create table branch(bname varchar(20),city varchar(20));
Table created.
SQL> commit;
Commit complete.
SQL> create table customers(cname varchar(20),city varchar(20));
Table created.
SQL> commit;
Commit complete.
DISPLAYING THE VALUES
SQL> select * from deposit;
ACNO CNAME BNAME AMOUNT ACDATE
---------- -------------------- -------------------- --------------- -------------
2317 prabha idappadi 10000 29-NOV-18
1199 anish idappadi 20000 29-NOV-18
4133 raja salem 20000 30-JAN-18
9894 jaya konganapuram 5000 10-NOV-18
SQL> select sum(amount) from deposit;
SUM(AMOUNT)
-----------
55000
SQL> select * from borrow;
LOANNO CNAME BNAME AMOUNT
-------------- -------------------- -------------------- ---------------
l90424 prabha idappadi 50000
l9500 anish idappadi 20000
l9442 raja salem 100000
SQL> select sum(amount) from borrow where bname='idappadi';
SUM(AMOUNT)
-----------
70000
SQL> select count(cname) from deposit;
COUNT(CNAME)
------------
4
SQL> select count(bname) from borrow;
COUNT(BNAME)
------------
3
SQL> select * from employee;
EMPNO EMPNAME EMPSAL EMPMOBILE DEPNO
-------------------- -------------------- ------------- ------------------- ----------
ap123 anish 20000 9042442317 1
gl23 raja 10000 9042442317 1
ap45 prabha 30000 9500871199 1
SQL> create table supplier as select * from employee;
Table created.
SQL> select * from supplier;
EMPNO EMPNAME EMPSAL EMPMOBILE DEPNO
-------------------- -------------------- ------------ -------------------- ----------
ap123 anish 20000 9042442317 1
gl23 raja 10000 9042442317 1
ap45 prabha 30000 9500871199 1
INSERTING VALUES:
SQL> insert into bank values('ac01','prabhakaran',5000);
1 row created.
PLSQL BLOCK:
declare
acno varchar2(6);
accbal number(7,2);
minbal constant number(7,2):=500.00;
withdraw number(7,2);
begin
acno:=&acno;
withdraw:=&withdraw;
select amount into accbal from bank where accno=acno;
accbal:=accbal-withdraw;
if accbal>=minbal then
update bank set amount=amount-withdraw where accno=acno;
else
dbms_output.put_line('unable to process your balance is beleow Rs.500');
end if;
end;
/
OUTPUT:
SQL> @bankop
Enter value for acno: 'ac04'
old 7: acno:=&acno;
new 7: acno:='ac04';
Enter value for withdraw: 1000
old 8: withdraw:=&withdraw;
new 8: withdraw:=1000;
SQL> @bankop
Enter value for acno: 'ac05'
old 7: acno:=&acno;
new 7: acno:='ac05';
Enter value for withdraw: 1000
old 8: withdraw:=&withdraw;
new 8: withdraw:=1000;
TABLE CREATION
Table created.
PLSQL BLOCK:
declare
pi constant number(4,2):=3.14;
Radius number(5);
area number(14,2);
begin
Radius:=3;
while Radius<=7
loop
area:=pi*power(Radius,2);
insert into calarea values(Radius,area);
Radius:=Radius+1;
end loop;
end;
/
OUTPUT:
SQL> @area
PLSQL BLOCK
declare
num varchar(6);
len number(2);
rev varchar(6);
begin
num:=#
len:=length(num);
for cntr in reverse 1..len
loop
rev:=rev||substr(num,cntr,1);
end loop;
dbms_output.put_line('THE GIVEN NUMBER IS : ' ||num);
dbms_output.put_line('THE REVERSE OF THE NUMBER IS : '||rev);
end;
/
OUTPUT:
SQL> @Reverse
old 6: num:=#
new 6: num:='12345';
SQL>
8. TRIGGER
Table creation
SQL> create table client_master(client_no varchar2(5),name varchar2(10),address varchar2(10),baldue
number(10,2));
Table created.
Describing the table
SQL> desc client_master;
Name Null? Type
----------------------------------------- -------- ----------------------------
CLIENT_NO VARCHAR2(5)
NAME VARCHAR2(15)
ADDRESS VARCHAR2(10)
BALDUE NUMBER(10,2)
Inserting values
SQL> insert into client_master values('001','prabha','idappadi',40000);
1 row created.
SQL> insert into client_master values('002','anish','idappadi',50000);
1 row created.
SQL> insert into client_master values('003','raghu','salem',20000);
1 row created.
SQL> insert into client_master values('004','somu','salem',10000);
1 row created.
SQL> insert into client_master values('005','prakash','sangiri',50000);
1 row created.
To save the values
SQL> commit;
Commit complete.
Displaying the values
SQL> select * from client_master;
CLIEN_NO NAME ADDRESS BALDUE
------------- --------------- ------------- -----------
001 prabha idappadi 40000
002 anish idappadi 50000
003 raghu salem 20000
004 somu salem 10000
005 prakash sangiri 50000
Table Creation To Store The Modification Of The Client_master Table
SQL> create table auditclient(client_no varchar2(5),name varchar2(10),baldue nu
mber(10,2),operation varchar2(10),userid varchar2(10),opdate date);
Table created.
Describing the table
SQL> desc auditclient;
Name Null? Type
------------------------------- -------- ----------------------------
CLIENT_NO VARCHAR2(20)
NAME VARCHAR2(20)
BALDUE NUMBER(10,2)
OPERATION VARCHAR2(10)
USERID VARCHAR2(20)
OPDATE DATE
Displaying the values
SQL> select * from auditclient;
no rows selected
To Write PLSQL Code
SQL> set serveroutput on;
SQL> edit client
PLSQL Block
create or replace trigger audit_trail after update or delete on client_master for each row
declare
voperation varchar(10);
vclientno varchar(5);
vname varchar(10);
vbaldue number(10,2);
begin
if updating then
voperation:='update';
else
voperation:='delete';
end if;
vclientno:=:old.client_no;
vname:=:old.name;
vbaldue:=:old.baldue;
insert into auditclient values(vclientno,vname,vbaldue,voperation,user,sysdate);
end;
/
To Compile The PLSQL Code
SQL> @client
Trigger created.
Modifying the client_master table
SQL>
9.BANK DATABASE
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim str As String
Dim confirm As Integer
Private Sub add_Click()
rs.AddNew
clear
End Sub
Private Sub delete_Click()
confirm = MsgBox("Do you want to delete the Customer detail", vbYesNo + vbCritical, "Deletion Confirmation")
If confirm = vbYes Then
rs.delete adAffectCurrent
MsgBox "Record has been Deleted successfully", vbInformation, "Message"
rs.Update
del
Else
MsgBox "Profile Not Deleted ..!!", vbInformation, "Message"
End If
End Sub
Private Sub DEPOSIT_Click()
Label6.Visible = True
Label11.Visible = False
Label12.Visible = True
OK.Visible = True
Text9.Visible = True
Text10.Visible = False
Text11.Visible = True
End Sub
Private Sub first_Click()
rs.MoveFirst
display
End Sub
Private Sub Form_Load()
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=H:\dbms prgm\bank.mdb;Persist Security Info=False"
rs.Open "Select * from bank", con, adOpenDynamic, adLockPessimistic
Frame2.Visible = False
End Sub
Public Function display()
Text1.Text = rs!acno
Text2.Text = rs!cname
Text3.Text = rs!actype
Text4.Text = rs!address
Text5.Text = rs!dop
Text6.Text = rs!opbal
Text7.Text = rs!mobile
Text8.Text = rs!dob
Text11.Text = rs!abal
If rs!gender = "male" Then
Option1.Value = True
ElseIf rs!gender = "female" Then
Option2.Value = True
End If
End Function
Public Function clear()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Option1.Value = False
Option2.Value = False
End Function
Public Function del()
rs.Close
rs.Open "Select * from bank", con, adOpenStatic, adLockPessimistic
If Not rs.EOF Then
rs.MoveNext
display
Else
MsgBox "No Record Found"
End If
End Function
Private Sub last_Click()
rs.MoveLast
display
End Sub
Private Sub next_Click()
rs.MoveNext
If Not rs.EOF Then
display
Else
rs.MoveFirst
display
End If
End Sub
Private Sub OK_Click()
If DEPOSIT.Value = True Then
Text11.Text = Val(Text6.Text) + Val(Text9.Text)
rs.Fields("abal") = Text11.Text
rs.Fields("tamt") = Text9.Text
rs.Fields("mot").Value = "DEPOSIT"
MsgBox "YOUR TRANSACTION IS SUCESSFULL..!!!", vbInformation
rs.Fields("opbal") = Text11.Text
rs.Update
ElseIf WITHDRAW.Value = True Then
Text11.Text = Val(Text6.Text) - Val(Text10.Text)
If Val(Text11.Text) >= 500 Then
MsgBox "PLEASE WAIT YOUR TRANSACTION IS BEING PROCESSED....."
MsgBox "COLLECT YOUR AMOUNT....."
Text6.Text = Val(Text11.Text)
rs.Fields("opbal") = Text6.Text
rs.Fields("tamt") = Text10.Text
rs.Fields("mot").Value = "WITHDRAW"
rs.Fields("abal") = Text11.Text
rs.Update
Else
MsgBox "UNABLE TO PROCESS......!!!!"
MsgBox "YOUR BALANCE IS BELOW RS.500....."
OK.Visible = False
Text11.Text = Val(Text6.Text)
End If
End If
End Sub
Private Sub previous_Click().
rs.MovePrevious
If rs.BOF Then
rs.MoveLast
display
Else
display
End If
End Sub
Private Sub save_Click()
rs.Fields("acno").Value = Text1.Text
rs.Fields("cname").Value = Text2.Text
rs.Fields("actype").Value = Text3.Text
rs.Fields("address").Value = Text4.Text
If Option1.Value = True Then
rs.Fields("gender").Value = "male"
ElseIf Option2.Value = True Then
rs.Fields("gender").Value = "female"
End If
rs.Fields("dop").Value = Text5.Text
rs.Fields("opbal").Value = Text6.Text
rs.Fields("mobile").Value = Text7.Text
rs.Fields("dob").Value = Text8.Text
MsgBox "Data is saved successfully ..!!!", vbInformation
rs.Update
End Sub
Private Sub search_Click()
rs.Close
rs.Open "Select * from bank where acno='" + Text1.Text + "'", con, adOpenDynamic, adLockPessimistic
If Not rs.EOF Then
display
Else
MsgBox "NO SUCH ACCOUNT NUMBER ..!!", vbInformation
End If
End Sub
Private Sub transaction_Click()
Frame2.Visible = True
Label6.Visible = False
Label11.Visible = False
Label12.Visible = False
Text9.Visible = False
Text10.Visible = False
Text11.Visible = False
OK.Visible = False
End Sub
Private Sub WITHDRAW_Click()
Label6.Visible = False
Label11.Visible = True
Label12.Visible = True
OK.Visible = True
Text9.Visible = False
Text10.Visible = True
Text11.Visible = True
End Sub
OUTPUT:
10.BUS RESERVATION
BUS DETAILS FORM
Dim con As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim str As String
Dim confirm As Integer
Private Sub addnew_Click()
rs.addnew
clear
End Sub
Private Sub check_Click()
Label12.Visible = True
Text10.Visible = True
reserve.Visible = True
End Sub
Private Sub delete_Click()
confirm = MsgBox("Do you want to delete the details of the bus", vbYesNo + vbCritical, "Deletion Confirmation")
If confirm = vbYes Then
rs.delete adAffectCurrent
MsgBox "Record has been Deleted successfully", vbInformation, "Message"
rs.Update
del
Else
MsgBox "Unable to Delete the details..!!", vbInformation, "Message"
End If
End Sub
Private Sub find_Click()
rs.Close
rs.Open "Select * from bus where busno='" + Text1.Text + "'", con, adOpenDynamic, adLockPessimistic
If Not rs.EOF Then
display
Else
MsgBox "PLSEASE ENTER VALID BUS NUMBER ..!!", vbInformation
End If
End Sub
Private Sub first_Click()
rs.MoveFirst
display
End Sub
Private Sub Form_Load()
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=H:\dbms prgm\BUSDET.mdb;Persist Security Info=False"
rs.Open "Select * from bus", con, adOpenDynamic, adLockPessimistic
Label12.Visible = False
Text10.Visible = False
reserve.Visible = False
End Sub
Public Function display()
Text1.Text = rs!busno
Text2.Text = rs!bname
Text3.Text = rs!start
Text4.Text = rs!End
If rs!btype = "a/c" Then
Option1.Value = True
ElseIf rs!btype = "non a/c" Then
Option2.Value = True
End If
Text5.Text = rs!fare
Text6.Text = rs!arrival
Text7.Text = rs!depature
Text8.Text = rs!avseat
Text9.Text = rs!doj
End Function
Private Sub last_Click()
rs.MoveLast
display
End Sub
Private Sub next_Click()
rs.MoveNext
If Not rs.EOF Then
display
Else
rs.MoveFirst
display
End If
End Sub
Private Sub previous_Click()
rs.MovePrevious
If rs.BOF Then
rs.MoveLast
display
Else
display
End If
End Sub
Private Sub reserve_Click()
Text8.Text = Val(Text8.Text) - Val(Text10.Text)
If Val(Text8.Text) < 0 Then
MsgBox "RESERVATION FULL PLS TRY ANOTHER DAY....."
reserve.Visible = False
Text8.Text = Val(Text8.Text) + Val(Text10.Text)
Else
rs.Fields("avseat").Value = Text8.Text
rs.Fields("resseat").Value = Text10.Text
confirm = MsgBox("DO YOU WANT TO RESERVE", vbYesNo + vbCritical, "Confirmation")
If confirm = vbYes Then
rs.Update
Form2.Show
Else
Form1.Show
Text8.Text = Val(Text8.Text) + Val(Text10.Text)
End If
End If
End Sub
Private Sub save_Click()
rs.Fields("busno").Value = Text1.Text
rs.Fields("bname").Value = Text2.Text
rs.Fields("start").Value = Text3.Text
rs.Fields("end").Value = Text4.Text
If Option1.Value = True Then
rs.Fields("btype").Value = "a/c"
ElseIf Option2.Value = True Then
rs.Fields("btype").Value = "non a/c"
End If
rs.Fields("fare").Value = Text5.Text
rs.Fields("arrival").Value = Text6.Text
rs.Fields("depature").Value = Text7.Text
rs.Fields("avseat").Value = Text8.Text
rs.Fields("doj").Value = Text9.Text
MsgBox "New Bus Details added successfully ..!!!", vbInformation
rs.Update
End Sub
Public Function clear()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text8.Text = ""
Text9.Text = ""
Option1.Value = False
Option2.Value = False
End Function
Public Function del()
rs.Close
rs.Open "Select * from bus", con, adOpenStatic, adLockPessimistic
If Not rs.EOF Then
rs.MoveNext
display
Else
MsgBox "No Record Found"
End If
End Function