0% found this document useful (0 votes)
35 views63 pages

Visual Basic and RDBMS (Lab)

The document outlines various programming exercises using Microsoft Visual Basic, including creating a calculator, generating Fibonacci series, developing a menu-driven program, and implementing file operations. Each exercise includes a step-by-step guide for designing forms, writing code, and executing programs successfully. Additionally, it covers database operations such as creating an employee table and inserting records using SQL commands.

Uploaded by

ssvigneshvicky77
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views63 pages

Visual Basic and RDBMS (Lab)

The document outlines various programming exercises using Microsoft Visual Basic, including creating a calculator, generating Fibonacci series, developing a menu-driven program, and implementing file operations. Each exercise includes a step-by-step guide for designing forms, writing code, and executing programs successfully. Additionally, it covers database operations such as creating an employee table and inserting records using SQL commands.

Uploaded by

ssvigneshvicky77
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 63

……………………………………………………

………………………………………………………………………………………..

This is to certify that the bonafide record for


……………………………………………………………… has done by
…………………………………….. of …………………………. .Register
No…………………………..during the academic year 20 - 20

Submitted for the practical examination held on…………………………….


S.NO Date Particulars Page No. Signature
Ex No : 1

Date :

To write a program to develop a calculator with basic operator.

Step 1: Start the process.


Step 2: Click start > All program > Microsoft Visual Studio 6.0 >
Microsoft Visual Basic. A project Window dialogue box appears,
set it standard EXE icon and click ok.
Step 3: All empty form is opened. A form is designed by using Text
box and Command button.
Step 4: By clicking the require command button type the
appropriate code for the form design to calculate the basic
operation using calculation.
Step 5: Save the form and run the program.
Step 6: The result is display in the List box.
Step 7: Stop the process.
Public Curval As Double
Public Prevval As Double
Public Choice As String
Public Result As Double
Private Sub command1_Click(Index As Integer)
Text1.Text = Text1.Text & command1(Index).Caption
Curval = Val(Text1.Text)
End Sub
Private Sub cmdAC_Click(Index As Integer)
Curval = Prevval = 0
Text1.Text = " "
End Sub
Private Sub cmdDiv_Click(Index As Integer)
Text1.Text = " "
Prevval = Curval
Curval = 0
Choice = "/"
End Sub
Private Sub cmdEqual_Click(Index As Integer)
Select Case Choice
Case "+"
Result = Prevval + Curval
Text1.Text = Str(Result)
Case "-"
Result = Prevval - Curval
Text1.Text = Str(Result)
Case "*"
Result = Prevval * Curval
Text1.Text = Str(Result)
Case "/"
Result = Prevval / Curval
Text1.Text = Str(Result)
End Select
Curval = Result
End Sub
Private Sub cmdMinus_Click(Index As Integer)
Text1.Text = ""
Prevval = Curval
Curval = 0
Choice = "-"
End Sub
Private Sub cmdMul_Click(Index As Integer)
Text1.Text = " "
Prevval = Curval
Curval = 0
Choice = "*"
End Sub
Private Sub cmdNegative_Click(Index As Integer)
Curval = -Curval
Text1.Text = Str(Curval)
End Sub
Private Sub cmdPlus_Click(Index As Integer)
Text1.Text = ""
Prevval = Curval
Curval = 0
Choice = "+"
End Sub
:
Thus the above program has been executed successfully.
Ex No : 2
Date :

To write a simple programs using loops and decisions-making


statements for Generate Fibonacci series.

Step 1: Start the process.


Step 2: Click Start > All programs > Microsoft Visual Studio 6.0 >
Microsoft Visual Basic. A project window dialog box appears select
standard. EXE icon and click ‘OK’.
Step 3: An empty form is opened a form is designed by using label
button, textbox and command button.
Step 4: By chickink the required command button type the
appropirate code for calculating the fibonacci series values.
Step 5: Save the form and run the process.
Step 6: The result is displayed in the textbox.
Step 7: Stop the process.
Private Sub Command1_Click()
n = Val(Text1.Text)
i=0
Sum = 0
Do While i < n
Sum = Sum + i
i=i+1
Loop
f1 = 0
f2 = 1
i=0
s = Str(f1) + " " + Str(f2)
Do While i < n
f3 = f1 + f2
s = s + " " + Str(f3)
f1 = f2
f2 = f3
i=i+1
Loop
Text3.Text = s
Text2.Text = Sum
End Sub
Private Sub Command2_Click()
End
End Sub
Thus the above program has been executed successfully.
Ex No : 3

Date :

To write a VB program to develop a menu driven program using


MDI window to display the form and change the color of the form.

Step 1: Start the process.


Step 2: Click start > All programs > Microsoft Visual Studio 6.0 >
Microsoft Visual basic. A project window Dialogue box appears
Select standard EXE icon and click on.
Step 3: A new project Menu and select Add form and click ok. Add
three and form using project menu and change the MDI child
property as true for all the three forms.
Step 4: Click project Menu select Add MDI Form and click ok.
MDI form window opens right click in the MDI Form.
Step 5: Using menu editor create the menu arrange and color
with its sub menus.
Step 6: By clicking the appropriate sub menus type the code
according to the sub menus created.
Step 7: Save the form and run the process.
Step 8: The result is displayed in the MDI form window.
Step 9: Stop the process.
Private Sub mnuCascade_Click()
MDIForm1.Arrange vbCascade
End Sub
Private Sub mnuExit_Click()
End
End Sub

Private Sub mnuGray_Click()


Form1.BackColor = vbGray
mnuRed.Enabled = True
mnuGray.Enabled = False
mnuMagenta.Enabled = True
End Sub

Private Sub mnuLarge_Click()


Form1.WindowState = 2
mnuSmall.Enabled = True
mnuLarge.Enabled = False
End Sub

Private Sub mnuMagenta_Click()


Form1.BackColor = vbMagenta
mnuRed.Enabled = True
mnuGray.Enabled = True
mnuMagenta.Enabled = False
End Sub
Private Sub mnuNew_Click()
Dim Form1 As New Form1
Form1.Show
End Sub

Private Sub mnuRed_Click()


Form1.BackColor = vbRed
mnuRed.Enabled = False
mnuGray.Enabled = True
mnuMagenta.Enabled = True
End Sub

Private Sub mnuSmall_Click()


Form1.WindowState = 1
mnuSmall.Enabled = False
mnuLarge.Enabled = True

End Sub

Private Sub mnuTile_Click()


MDIForm1.Arrange vbTileHorizontal
End Sub
:
Thus the above program has been executed successfully.
Ex no:4
Date :

To write a program to display files in a directory using DriveListBox,


DirListBox, FileListBox control and Open, Edit and Save text file using
RichTextBox control.

Step 1: Start the process.


Step 2: Click Start > All programs > Microsoft Visual Studio 6.0 >
Microsoft Visual Basic. A project window dialog box appears select
standard. EXE icon and click ‘OK’.
Step 3: An Empty form is opened select picture and timer option
from the project menu
Step 4 :A from is designed by using command button type and
richtextbox.
Step 5: BY clicking the require command button type appropirate
code for the form desing to process by Drawing the diagram in the
paint by creating new folder.
Step 6: Save the form and run the process
Step 7: The result is displayed in the window
Step 8: Stop the process
Dim f As String
Private Sub Command1_Click()
f = f & File1.Path
f = f & "/" & File1.FileName
MsgBox (" " & f)
End Sub
Private Sub Command2_Click()
RichTextBox1.LoadFile (f)
End Sub
Private Sub Command3_Click()
RichTextBox1.SaveFile (f)
f=""
End Sub
Private Sub Command4_Click()
End
End Sub
Private Sub Dir1_Change()
File1.Path = Dir1.Path
End Sub
Private Sub Drive1_Change()
Dir1.Path = Drive1.Drive
End Sub
Thus the above program has been executed successfully.
Ex No: 5
Date :

To design a form using common dialog to display the open,


save, font and exit dialog box without using the action control
property.

Step 1: Start the process.


Step 2: Click Start > All programs > Microsoft Visual Studio 6.0 >
Microsoft Visual Basic. A project window dialog box appears select
standard. EXE icon and click ‘OK’.
Step 3: An empty form is opened select component option from
project menu which displays a component option dialog box. The
enable Microsoft RichTextBox6.0 and Microsoft CommonDialog
Control.
Step 4: A form is designed by using Label, Rich Box, Common Dialog
Control buttons.
Step 5: By clicking the required command button type the
appropriate code for the form design to process the command
dialog Control using Open, Save, Font, Exit options.
Step 6: Save the form and run the process.
Step 7: The result is displayed in Rich Text Box.
Step 8: Stop the process.
Private Sub mnuOpen_Click()
CommonDialog1.ShowOpen
RichTextBox1.Text = CommonDialog1.FileName
End Sub

Private Sub mnuFont_Click()


CommonDialog1.Flags = cdlCFBothOrcdcfeffects
RichTextBox1.Font.Name = CommonDialog1.FontName
RichTextBox1.Font.Size = CommonDialog1.FontSize
RichTextBox1.Font.Bold = CommonDialog1.FontBold
RichTextBox1.Font.Italic = CommonDialog1.FontItalic
RichTextBox1.Font.Underline = CommonDialog1.FontUnderline
End Sub

Private Sub mnuSave_Click()


CommonDialog1.ShowSave
End Sub

Private Sub mnuExit_Click()


End
End Sub
Thus the above program has been executed successfully.
Ex No : 6
Date :

To write a simple program to implement animation using


timers.

Step 1: Start the process.


Step 2: Click Start > All programs > Microsoft Visual Studio 6.0 >
Microsoft Visual Basic. A project window dialog box appears select
standard. EXE icon and click ‘OK’.
Step 3: Create an empty picture box and set an assigned size.
Step 4: Open an paint and draw your own diagram and save it.
Step 5: Insert a timer in design and set its time interval as 100
in its properties.
Step 6: Write an code and insert the picture file path in code.
Step 7: Run the program with increase and decrease speed.
Step 8: Stop the process.
Dim cnt As Integer
Private Sub Command1_Click()
If Timer1_interval > 10 Then
Timer1.Interval = Timer1.Interval - 10
End If
End Sub
Private Sub Command2_Click()
Timer1.Interval = Timer1.Interval + 10
End Sub
Private Sub Form_Load()
cnt = 1
Picture1 = LoadPicture("C:\BCA\1.JPG")
End Sub
Private Sub Timer1_Timer()
cnt = cnt + 1
If cnt > 4 Then
cnt = 1
End If
Picture1.Picture = LoadPicture("C:\BCA\" & cnt & ".JPG")
End Sub
Thus the above program has been executed successfully.
Ex No :7
Date :

To write a program to convert the given decimal number into


Binary, Octal, Hexadecimal number.

Step 1: Start the process.


Step 2: Click Start > All programs > Microsoft Visual Studio 6.0 >
Microsoft Visual Basic. A project window dialog box appears select
standard. EXE icon and click ‘OK’.
Step 3: An empty form is opened a form is designed by using Label
box, Text boxes Command buttons.
Step 4: By clicking the required command button type the
appropriate code for the form design to convert decimal values into
Binary, Octal, Hexadecimal.
Step 5: Save the form and run the process.
Step 6: The result is displayed in the works pending the text boxes.
Step 7: Stop the process.
Private Sub Command1_Click()
Text2.Text = DecToBin(Val(Text1.Text))
Text3.Text = Oct$(Text1.Text)
Text4.Text = Hex$(Text1.Text)
End Sub
Public Function DecToBin(Decivalue As Long, Optional NoOfBits As Integer = 8)
As String
Dim i As Integer
Do While Decivalue > (2 ^ NoOfBits) - 1
NoOfBits = NoOfBits + 8
Loop
DecToBin = vbNullString
For i = 0 To (NoOfBits - 1)
DecToBin = CStr((Decivalue And 2 ^ i) / 2 ^ i) & DecToBin
Next i
End Function
Private Sub Command2_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
End Sub
Private Sub Command3_Click()
End
End Sub
Thus the above program has been executed successfully.
Ex No :8
Date :

To create a table for employee details Empno as primary key &


following joining Registration, Gender, Date of joining, Salary
interest, Set grouping operation.

Step 1: Start the process.


Step 2: Create the table employee with gender, age etc.
Step 3: To display employee description using employee.
Step 4: Use various queries to perform Logical set writing
grouping operation.
Step 5: Use various queries to perform comparison command.
Step 6: The grouping function in perform select from employee.
Step 7: Execute all queries and stop the process.
TABLE CREATION:
SQL> Create table employee3(Empid number(5)primary key, Name varchar2(25), Designation
varchar2(25), Gender varchar2(10), Age number(2), Date_of_joining date, Salary number(10));
Table created

ROW INSERTION:
SQL>insert into employee values
(‘&Empid’,’&Name’,’&Designation’,’&Gender’,’&Age’,’&Date_of_joining’,’&Salary’);
Enter values for Empid: 101
Enter values for Name: Raji
Enter values for Designation: staff
Enter values for Gender: female
Enter values for Age: 21
Enter values for Date_of_joining: 08-oct-10
Enter values for Salary: 250000
Old 1: insert into employee3
Values(‘&Empid’.’&Name’,’&Designation’,’&Gender’,’&Age’,’&Date_of_joining’.’&Salary’)
New 1: insert into employee3 values(‘101’,’raji’,’staff’,’female’,’21’,’08-oct-10’,’250000’)
1 row created
SQL> /
Enter values for Empid: 102
Enter values for Name: Stella
Enter values for Designation: supervisor
Enter values for Gender: female
Enter values for Age: 19
Enter values for Date_of_joining: 06-jun-99
Enter values for Salary: 500000
Old 1: insert into employee3
Values(‘&Empid’.’&Name’,’&Designation’,’&Gender’,’&Age’,’&Date_of_joining’,’&Salary’)
New 1: insert into employee3 values(‘102’,’stella’,’supervisor’,’female’,’19’,’06-jun-99’,’500000’)
1 row created
SQL> /
Enter values for Empid: 103
Enter values for Name: Abi
Enter values for Designation: staff
Enter values for Gender: female
Enter values for Age: 20
Enter values for Date_of_joining: 17-feb-09
Enter values for Salary: 10000
Old 1: insert into employee3
Values(‘&Empid’.’&Name’,’&Designation’,’&Gender’,’&Age’,’&Date_of_joining’,’&Salary’)
New 1: insert into employee3 values(‘103’,’Abi’,’staff’,’female’,’20’,’17-feb-09’,’10000’)
1 row created
SQL> /
Enter values for Empid: 104
Enter values for Name: lavanya
Enter values for Designation: receptionist
Enter values for Gender: female
Enter values for Age: 20
Enter values for Date_of_joining: 19-may-01
Enter values for Salary: 20000
Old 1: insert into employee3
Values(‘&Empid’,’&Name’,’&Designation’,’&Gender’,’&Age’,’&Date_of_joining’,’&Salary’)
New 1: insert into employee3 values(‘104’,’lavanya’,’recepoinst’,’female’,’20’,’08-may-01’,’2000’)
1 row created
SQL> /
Enter values for Empid: 105
Enter values for Name: Divya
Enter values for Designation: staff
Enter values for Gender: female
Enter values for Age: 22
Enter values for Date_of_joining: 19-apr-02
Enter values for Salary: 15000
Old 1: insert into employee3
Values(‘&Empid’,’&Name’,’&Designation’,’&Gender’,’&Age’,’&Date_of_joining’,’&Salary’)
New 1: insert into employee3 values(‘105’,’Divya’,’staff’,’female’,’22’,’19-apr-02’,’15000’)
1 row created
SQL> /
Enter values for Empid: 106
Enter values for Name: logeshwari
Enter values for Designation: executive
Enter values for Gender: female
Enter values for Age: 19
Enter values for Date_of_joining: 05-apr-13
Enter values for Salary: 20000
Old 1: insert into employee3
Values(‘&Empid’,’&Name’,’&Designation’,’&Gender’,’&Age’,’&Date_of_joining’,’&Salary’)
New 1: insert into employee3 values(‘106’,’Logeswari’,’executive’,’female’,’19’,’05-apr-13’,’20000’)
1 row created.
SQL> /
Enter values for Empid: 107
Enter values for Name: Rose
Enter values for Designation: staff
Enter values for Gender: female
Enter values for Age: 24
Enter values for Date_of_joining: 20-dec-98
Enter values for Salary: 10000
Old 1: insert into employee3
Values(‘&Empid’,’&Name’,’&Designation’,’&Gender’,’&Age’,’&Date_of_joining’,’&Salary’)
New 1: insert into employee3 values(‘107’,’Rose’,’staff’,’female’,’24’,’20-dec-98’,’10000’)
1 row created.
SQL> select name, salary empolyee3;
NAME SALARY
--------- --------------
Raji 250000
Stella 50000
Abi 10000
Lavanya 20000
Divya 15000
Logeshwari 20000
Rose 10000
10 rows selected
SQL> select name from employee3 order by name;
NAME
Raji
Stella
Abi
Lavanya
Divya
Logeshwari
Rose
10 rows selected
SQL> Select * from employee3;
EMPID NAME DESIGNATION GENDER AGE DATE_OF_JOIN SALARY
101 Raji staff female 21 08-oct-10 250000
102 Stella supervisor female 20 06-jun-99 50000
103 Abi staff female 20 17-feb-09 10000
104 Lavanya receptionist female 20 19-may-01 20000
105 Divya staff female 22 19-may-02 15000
106 Logeshwari executive female 19 05-apr-13 20000
107 Rose staff female 24 20-dec-98 10000
10 rows selected.
SQL> Select name, designation, salary from employee3 Where salary>10000;
NAME DESIGNATION SALARY
--------- ----------------------- ---------------
Raji Staff 250000
Stella Supervisor 50000
Lavanya Receptionist 20000
Divya Staff 15000
SQL> select name, designation, salary from employee3 Where salary<10000;
NAME DESIGNATION SALARY
---------- ----------------------- --------------
Abi Staff 10000
Rose Staff 10000
SQL> Select name, designation, salary from employee3 Where salary between 10000 and 50000;
NAME DESIGNATION SALARY
--------- ---------------------- --------------
Stella Supervisor 50000
Lavanya Receptionist 20000
Divya Staff 15000
Abi Staff 10000
Rose Staff 10000
5 rows selected.
SQL> Select name, designation, gender from employee3 Where salary=20000 or salary=50000 or
salary=15000;
NAME DESIGNATION GENDER
--------- ---------------------- --------------
Stella Supervisor Female
Logeshwari Executive Female
Divya Staff Female
SQL> Select name, designation, salary from employee3 Where empid>=103 order by salary desc;
NAME DESIGNATION SALARY
--------- ---------------------- ------------
Lavanya receptionist 20000
Logeshwari executive 20000
Divya staff 15000
Abi Staff 10000
Rose Staff 10000
5 rows selected.
SQL> select sum(salary), avg(salary), max(salary), min(salary) from employee3;
SUM(SALARY) AVG(SALARY) MAX(SALARY) MIN(SALARY)
399000 39900 250000 20000
SQL> select max(age)youngest, min(age)oldest from employee3;
YOUNGEST OLDEST
------------------ -----------
19 24
SQL> select max(age)oldest, min(age)youngest from employee3;
OLDEST YOUNGEST
24 19
Thus the above program has been executed successfully.
EX :9
Date :

To write a PL/SQL to update the rate field by more then the


Current rate after updating places for values for the new field.

Step 1: Start the process.


Step 2: Create a table product with the following field Pno as
Primary key, Pname, fields.
Step 3: Insert values to display the product details from product.
Step 4: After inserting values to display the product details from
product.
Step 5: Using PL/SQL procedure to rate value is increment by 20%.
Step 6: Execute all the queries and stop the process.
TABLE CREATION :
SQL > create table inventory (product_no number(5), product_name varchar2(25), rate number(5));
Table created.
ROW INSERTION:
SQL>insert into inventory values(‘&product_no’,’&product_name’,’&rate’);
Enter value for product_no: 101
Enter value for product_name: soap
Enter value for rate: 35
Old 1: insert into inventory values(‘&product_no’,’&product_name’,’&rate’)
New 1: insert into inventory values(‘101’,’soap’,’35’)
1 row created.
SQL> /
Enter value for product_no: 102
Enter value for product_name: shampoo
Enter value for rate: 50
Old 1: insert into inventory values(‘&product_no’,’&product_name’,’&rate’)
New 1: insert into inventory values(‘102’,’shampoo’,’50’)
1 row created.
SQL> /
Enter value for product_no: 103
Enter value for product_name: books
Enter value for rate: 500
Old 1: insert into inventory values(‘&product_no’,’&product_name’,’&rate’)
New 1: insert into inventory values(‘103’,’books’,’500’)
1 row created.
SQL> /
Enter value for product_no: 104
Enter value for product_name: pen
Enter value for rate: 45
Old 1: insert into inventory values(‘&product_no’,’&product_name’,’&rate’)
New 1: insert into inventory values(‘104’,’pen’,’45’)
1 row created.

SQL> /

Enter value for product_no: 105


Enter value for product_name: sketches
Enter value for rate: 150
Old 1: insert into inventory values(‘&product_no’,’&product_name’,’&rate’)
New 1: insert into inventory values(‘105’,’sketches’,’150’)
1 row created.
SQL> Select * from inventory;
PRODUCT_NO PRODUCT_NAME RATE
101 soap 45

102 shampoo 50

103 books 500

104 pen 45

105 sketches 150

SQL >begin
2 > update inventory set rate=((rate+rate)*(20/100));
3 > commit;
4 > end;
5>/
SQL procedure successfully completed.
SQL > Select * from inventory;
PRODUCT_NO PRODUCT_NAME RATE
101 soap 43

102 shampoo 60

103 books 54

105 sketches 150

SQL>alter table inventory add number_of_items integer;


Table created.
SQL> describe inventory
NAME NULL? TYPE
PRODUCT_NO NUMBER(5)
PRODUCT_NAME VARCHAR2(25)
RATE NUMBER(5)
NUMBER_OF_ITEMS NUMBER(38)
SQL > update inventory set number_of_items=5 Where product_no=101;
1 row updated.
SQL > update inventory set number_of_items=5 Where product_no=101;
1 row updated.
SQL > update inventory set number_of_items=6 Where product_no=102;
1 row updated.
SQL > update inventory set number_of_items=7 Where product_no=103;
1 row updated.
SQL > update inventory set number_of_items=8 Where product_no=104;
1 row updated.
SQL > update inventory set number_of_items=9 Where product_no=105;
1 row updated.
SQL > Select * from inventory;
PRODUCT_NO PRODUCT_NAME RATE NUMBER_OF_ITEMS
101 soap 42 5
102 shampoo 60 6
103 books 600 7
104 pen 54 8
105 sketches 180 9
SQL > alter table inventory add total integer;
Table altered.
SQL>update inventory set total =rate* number_of_items Where product_no=101;
1 row updated.
SQL>update inventory set total=rate* number_of_items Where product_no=102;
1 row updated.
SQL>update inventory set total=rate* number_of_items Where product_no=103;
1 row updated.
SQL>update inventory set total=rate* number_of_items Where product_no=104;
1 row updated.

SQL>update inventory set total=rate* number_of_items Where product_no=105;


1 row updated.

SQL> Select * from inventory;

PRODUCT_NO PRODUCT_NAME RATE NUMBER_OF_ITEMS TOTAL

101 soap 42 5 210

102 shampoo 60 6 360

103 books 600 7 42 00

104 pen 54 8 432

105 sketches 180 9 1620


Thus the above program has been executed successfully.
Ex No : 10
Date :

To write a PL/SQL to execute in bank account management table


deposit amount is zero.

Step 1: Start the process.


Step 2: Create a table for bank with the following field b name
primary key ACC name and deposit.
Step 3: Display the bank deposit using desc bank.
Step 4: Insert value character data field using single with prefix
symbol.
Step 5: If the amount is zero. The exception will be received.
Step 6: Because all queries and stop the process.
TABLE CREATION:
SQL>create table imaster (prono number(3), primary key, proname varchar2(15), rate number(7,2));
Table created.
SQL>create table itrans(tno number(3),prono number(3) references imaster(prono),qty number(4));
Table created.

ROW INSERTION:
SQL > insert into imaster values(‘&prono’,’&proname’,’&rate’);
Enter value for prono: 211
Enter value for proname: fan
Enter value for rate: 700
Old 1: insert into imaster values(‘&prono’,’&proname’,’&rate’)
New 1: insert into imaster values(’211’,’fan’,’700’)
1 row created.
SQL> /
Enter value for prono: 222
Enter value for proname: laptop
Enter value for rate: 15000
Old 1: insert into imaster values(‘&prono’,’&proname’,’&rate’)
New 1: insert into imaster values(’222’,’laptop’,’15000’)
1 row created.
SQL> /
Enter value for prono: 233
Enter value for proname: computer
Enter value for rate: 20000
Old 1: insert into imaster values(‘&prono’,’&proname’,’&rate’)
New 1: insert into imaster values(’233’,’computer’,’20000’)
1 row created.
SQL> insert into itrans values(‘&tno’.’&pno’,’&qty’);
Enter value for tno: 001
Enter value for pno: 211
Enter value for qty: 86
Old 1: insert into itrans values(‘&prono’,’&proname’,’&rate’)
New 1: insert into itrans values(’001’,’211’,’86’)
1 row created.
SQL> /
Enter value for tno: 002
Enter value for pno: 222
Enter value for qty: 21
Old 1: insert into itrans values(‘&prono’,’&proname’,’&rate’)
New 1: insert into itrans values(’002’,’222’,’21’)
1 row created.
SQL> /
Enter value for tno: 003
Enter value for pno: 223
Enter value for qty: 92
Old 1: insert into itrans values(‘&prono’,’&proname’,’&rate’)
New 1: insert into itrans values(’003’,’223’,’92’)
1 row created.
SQL> create trigger prono_validity before insert on imaster for each row
2 declear
3 cursor ctrl is prono form imaster:
4 begin
5 if;new,prono is null then
6 raise_application_error
7 (-20000,’product number cannot be null’);
8 end if;
9 end;
10 /
Tigger created
SQL > create trigger itrans before insert on itrans for each row
2 > declear
3 > cursor cp is selected tno form itrans:
4 > begin
5 > if;new,tno is null then
6 > raise_application_error
7 > (-200001,’enter valid transaction number’);
8 > end if;
9 > end;
10 /
Tigger created.
SQL > insert into itrans values(‘&tno’,’&pno’,’&qty’);
Enter value for tno:
Enter value for pno: 223
Enter value for qty: 92
Old 1: insert into itrans values(‘&prono’,’&proname’,’&rate’)
New 1: insert into itrans values(’003’,’223’,’92’)
*
ERROR at lin 1:
ORA-200001: enter valid transaction number
ORA-06512: at”SYSTEM.trans”,line 5
ORA-04088: error during execution of trigger’SYSTEM.trans’
SQL>update imaster set prono=null;
Update imaster set prono=null
*
ERROR at lin 1:
ORA-20000: product number cannot be null
ORA-06512: at “SYSTEM.PRONO_VALIDITY”,line 5
ORA-04088: error during execution of trigger’SYSTEM.PRONO_VALIDITY’
Thus the above program has been executed successfully.
Ex No : 11
Date :

To write a PL/SQL to split the student table based an result icon


handling table and create a student details table.

Step 1: Start the process.


Step 2: Create a table for student mark, branch.
Step 3: Display the student description using desc student.
Step 4: Insert the value for using SQL server.
Step 5: Display the pass and fail table using pass Select * from
Fail.
Step 6: Execute all the queries and stop the process.
TABLE CREATION:
SQL > create table student22 (regno number(5), name varchar2(10) ,mark1 number(5), mark2 number(5),
mark3 number(5), total number(10), result varchar2(10));
Table created
SQL > create table passed (regno number(5),name varchar2(10),mark1 number(5),mark2 number(5),mark3
number(5),total number(10),result varchar2(10));
Table created
SQL > create table failed(regno number(5),name varchar2(10),mark1 number(5),mark2 number(5),mark3
number(5),total number(10),result varchar2(10));
Table created

ROW INSERTION:
SQL > insert into student22 values(‘&regno’,’&name’,’&mark1’,’&mark2’,’&mark3’,’&total’,’&result’);
Enter value for regno: 101
Enter value for name: stella
Enter value for mark1: 90
Enter value for mark2: 80
Enter value for mark3: 80
Enter value for total: 250
Enter value for result: pass
Old 1:insert into student22 values(‘&regno’,‘&name’,’&mark1’,’&mark2’,’&mark3’,’&total’,’&result’);
New 1:insert into student22(‘101’,’stella’,’&90’,’80’,’80’,’250’,’pass’)
1 row created
SQL> /
Enter value for regno: 102
Enter value for name: Raji
Enter value for mark1: 70
Enter value for mark2: 70
Enter value for mark3: 80
Enter value for total: 220
Enter value for result: pass
Old 1:insert into student22 values(‘&regno’,‘&name’,’&mark1’,’&mark2’,’&mark3’,’&total’,’&result’);
New 1:insert into student22(‘102’,’Raji’,’70’,’70’,’80’,’220’,’pass’)
1 row created
SQL> /
Enter value for regno: 103
Enter value for name: Lavanya
Enter value for mark1: 70
Enter value for mark2: 70
Enter value for mark3: 70
Enter value for total: 210
Enter value for result: pass
Old 1:insert into student22 values(‘&regno’,‘&name’,’&mark1’,’&mark2’,’&mark3’,’&total’,’&result’);
New 1:insert into student22(‘103’,’Lavanya’,’70’,’70’,’70’,’210’,’pass’)
1 row created
SQL> /
Enter value for regno: 104
Enter value for name: Abi
Enter value for mark1: 30
Enter value for mark2: 20
Enter value for mark3: 20
Enter value for total: 70
Enter value for result: fail
Old 1:insert into student22 values(‘&regno’,‘&name’,’&mark1’,’&mark2’,’&mark3’,’&total’,’&result’);
New 1:insert into student22(‘104’,’Abi’,’30’,’20’,’20’,’70’,’fail’)
1 row created
SQL> /
Enter value for regno: 105
Enter value for name: Divya
Enter value for mark1: 20
Enter value for mark2: 10
Enter value for mark3: 20
Enter value for total: 50
Enter value for result: pass
Old 1:insert into student22 values(‘&regno’,‘&name’,’&mark1’,’&mark2’,’&mark3’,’&total’,’&result’);
New 1:insert into student22(‘105’,’Divya’,’20’,’10’,’20’,’50’,’fail’)
1 row created
SQL> select * from student22;
REGNO NAME MARK1 MARK2 MARK3 TOTAL RESULT
----------- --------- ------------ ---------- ----------- --------- --------------
101 Stella 90 80 80 250 pass
102 Raji 70 70 80 220 pass
103 Lvanya 70 70 70 210 pass
104 Abi 30 20 20 70 fail
105 Divya 20 10 20 50 fail
10 row selected.
SQL>DECLARE
2 > cursor stud IS SELECT regno,name,mark1,mark2,mark3,total,result from student22;
3 > S_regno number(5);
4 > S_name varchar2(10);
5 > S_mark1 number(5);
6 > S_mark2 number(5);
7 > S_mark3 number(5);
8 > S_total number(10);
9 > S_result varchar2(10);
10 > begin
11 > OPEN stud;
12 > LOOP
13 > FETCH stud into S_regno,S_name,S_mark1,S_mark2,S_mark3,S_total,S_result;
14 > EXIT WHENstud%NOTFOUND;
15 > IF S_result=’pass’ then
16 > insert into
passed(regno,name,mark1,mark2,mark3,total,result)values(S_regno,S_name,S_mark1,S_mark2,S_mark3,S_
total,S_result);
17 > else
18 > insert into
failed(regno,name,mark1,mark2,mark3,total,result)values(S_regno,S_name,S_mark1,S_mark2,S_mark3,S_t
otal,S_result);
19 > END IF;END LOOP;
20 > CLOSE stud;
21 > END;
22 > /
PL/SQL procedure successfully completed.
SQL> Select * from passed_student22;
REGNO NAME MARK1 MARK2 MARK3 TOTAL RESULT
------------ ----------- ------------- ------------ ---------- ----------- -------------
101 Stella 90 80 80 250 pass
102 Raji 70 70 80 220 pass
103 Lavanya 70 70 70 210 pass
6 rows selected.
SQL > Select * from failed_student22;
REGNO NAME MARK1 MARK2 MARK3 TOTAL RESULT
---------- --------- ----------- ----------- ------------ --------- ----------
104 Abi 30 20 20 70 fail
105 Divya 20 10 20 50 fail
Thus the above program has been executed successfully.
Ex No : 12
Date :

To write a program for student database management system


using VB as frontend and ORACLE as backend.

Step 1: Start the process.


Step 2: Open a new Microsoft access project and design the table
using appropriate fields manipulates data type.
Step 3: Open a new VB project and design the form using table,
textbox and command button.
Step 4: Add the new controls Microsoft Adodc control6.0 Microsoft
Data grid control using project menu > components options.
Step 5: Set the connectivity option for each text boxes with
respectively fields menu.
Step 6: Set the path for connecting the data more.
Step 7: Test the connection, add the record source description
click ‘OK’.
Step 8: By clicking the appropriate command button type the
appropriate code for the form design to process the form.
Step 9: Save the form and run the process.
Step 10: The result is displayed in the data grid control.
Private Sub Command1_Click()
Adodc1.Recordset.AddNew
End Sub
Private Sub Command3_Click()
Adodc1.Recordset.Delete
Adodc1.Recordset.MoveNext
If Adodc1.Recordset.EOF Then
Adodc1.Recordset.MoveLast
End If
End Sub
Private Sub Command4_Click()
Adodc1.Recordset.Save
End Sub
Private Sub Command5_Click()
Adodc1.Recordset.Update
End Sub
Private Sub Command6_Click()
Unload me
End Sub
Private Sub command2_click()
Text7.Text = Val(Text4.Text) + Val(Text5.Text) + Val(Text6.Text)
Text8.Text = Val(Text7.Text) / 3
If Val(Text4.Text) < 40 & Val(Text5.Text) < 40 & Val(Text6.Text) < 40 Then
Text9.Text = "pass"
Else
Text9.Text = "fail"
End If
Adodc1.Recordset.Update
Adodc1.Refresh
End Sub
Thus the above program has been executed successfully.

You might also like