0% found this document useful (0 votes)
53 views68 pages

VB, Rdbms (2) 1

Uploaded by

priykamesh
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)
53 views68 pages

VB, Rdbms (2) 1

Uploaded by

priykamesh
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/ 68

1

2
3
4
5
6
VISUAL BASIC

7
EX.NO : 01
CALCULATOR
DATE :

AIM:

To create a simple VB calculator program which include the basic mathematic

function like addition, subtraction, multiplication and division.

ALGORITHM:

Step 1 : Start the process.

Step 2 : A new standard.exe form is created.

Step 3 : Place the appropriate controls on the form (text box, command buttons and set

the properties using control array).

Step 4 : The functions for the operators are defined.

Step 5 : The coding is written for each event.

Step 6 : Save the project and run the project.

Step 7 : Stop the process.

8
INPUT:

9
CODING:

Dim T As Double
Dim OP As String

Private Sub Command1_Click(Index As Integer)


Text1.Text = Text1.Text + Command1(Index).Caption
End Sub

Private Sub Command2_Click(Index As Integer)


Select Case Command2(Index).Caption
Case "+"
T = Text1.Text
Text1.Text = ""
OP = "+"
Case "-"
T = Text1.Text
Text1.Text = ""
OP = "-"
Case "*"
T = Text1.Text
Text1.Text = ""
OP = "*"
Case "/"
T = Text1.Text
Text1.Text = ""
OP = "/"
Case "="
Select Case OP
Case "+"
Text1.Text = Val(T) + (Text1.Text)
Case "-"
Text1.Text = Val(T) - (Text1.Text)
Case "*"
Text1.Text = Val(T) * (Text1.Text)
Case "/"
Text1.Text = Val(T) / (Text1.Text)
End Select
Case "+/-"
Text1.Text = -(Text1.Text)
End Select
End Sub

Private Sub CLEAR_Click()


T = Text1.Text
Text1.Text = ""
T=0
End Sub

10
OUTPUT:

RESULT:

The above program has been executed and verified successfully.

11
EX.NO : 02
a. FIBONACCI SERIES
DATE :

AIM:

To create a visual basic program to generate Fibonacci series.

ALGORITHM:

Step 1 : Start the process.

Step 2 : A new standard.exe form is created.

Step 3 : Place the appropriate controls on the form (text box, command buttons, list box

and set the properties)

Step 4 : The coding for accepting input from the user through input box and generating

Fibonacci series and displaying it on list box is written.

Step 5 : Save the project and run the project.

Step 6 : Stop the process.

12
INPUT :

CODING:

Dim x, y, n, i, sum As Integer

Private Sub Command1_Click( )


n = Val (Text1.Text)
x=0
y=1
List1.AddItem x
List1.AddItem y
For i = 3 To n
Sum = x + y
List1.AddItem sum
x= y
y = sum
Next i
End Sub

Private Sub Command2_Click( )


End
End Sub

13
OUTPUT:

RESULT:

The above program has been executed and verified successfully.

14
EX.NO : 02
b. SUM OF N NUMBERS
DATE :

AIM:

To create a visual basic program to find the sum of 'n' numbers.

ALGORITHM:

Step 1 : Start the process.

Step 2 : A new standard.exe form is created.

Step 3 : Place the appropriate controls on the form (text box and command buttons)

Step 4 : Set the properties for each control.

Step 5 : The coding using for loop to find the sum of 'n' numbers is written.

Step 6 : Save the project and run the project.

Step 7 : Stop the process.

15
CODING:

Dim i, s, n As Integer

Private Sub Command1_Click( )


cls
n = Val (Text1.Text)
For i = 1 To n
s=s+i
Next i
Print “sum of ten serial number=”; s
End Sub

16
OUTPUT:

RESULT:

The above program has been executed and verified successfully.


17
EX.NO : 03
MDI FORM
DATE :

AIM:

To create a program MDI from and develop a menu driven program to arrange the
forms in cascading and horizontal styles and also change the color of the form.

ALGORITHM:

Step 1 : Start the process.

Step 2 : A new standard.exe form is created.

Step 3 : Create MDI from using project menu.

Step 4 : Create the appropriate main menus and sub menus using editor.

Step 5 : And also the coding is written to change the color of the form.

Step 6 : The coding is written for each events to arrange the form in horizontal or in

cascade style.

Step 7 : Then save the project and run the project.

Step 8 : Stop the process.

18
Input:

19
CODING:

Private Sub NEW_Click()


Dim FORM As New Form1
FORM.Show
End Sub

Private Sub HORIZONTAL_Click()


MDIForm1.Arrange vbHorizontal
End Sub

Private Sub CASCADE_Click()


MDIForm1.Arrange vbCascade
End Sub

Private Sub RED_Click()


ActiveForm.BackColor = vbRed
End Sub

Private Sub GREEN_Click()


ActiveForm.BackColor = vbGreen
End Sub

Private Sub BLUE_Click()


ActiveForm.BackColor =vbBlue
End Sub

Private Sub EXIT_Click()


End
End Sub

20
Output:

21
RESULT:

The above program has been executed and verified successfully.

22
EX.NO : 04
DRIVELISTBOX, DIRLISTBOX AND
DATE : FILE LISTBOX CONTROLS

AIM:

To write a program to display files in a directory using Drive list box,Dir list
Box and file list box .control and open, edit ,save text file using Rich text box control.

ALGORITHM:

Step 1: Start the process.

Step 2: Add drive link, file and directory controls in your form.

Step 3: Set the properties for each control.

Step 4: Write the necessary code in code editor

Step 5: Execute the program.

Step 6: Stop the process.

23
INPUT:

24
CODING:

Private Sub clear_Click()


RichTextBox1.SetFocus
End Sub

Private Sub open_Click()


f = File1.Path
If Right(f, 1) <> "\" Then
f = File1.Path + "\"
End If
List1.AddItem (f + File1.FileName)
RichTextBox1.LoadFile (f + File1.FileName)
End Sub

Private Sub Dir1_Change()


File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()


Dir1.Path = Drive1.Drive
End Sub

Private Sub save_Click()


CommonDialog1.ShowSave
RichTextBox1.SaveFile CommonDialog1.FileName
End Sub

25
OUTPUT:

RESULT:

The above program has been executed and verified successfully.

26
EX.NO : 05
MENU USING COMMON DIALOG CONTROL
DATE :

AIM:

To create a program using common dialog control to display the font, save and open
dialog box without using the action control property.

ALGORITHM:

Step 1: Start the process.

Step 2: A new standard.exe form is created.

Step 3: Place the appropriate controls on the from (text box, command buttons and

set the properties using control array).

Step 4: The functions for the operators are defined.

Step 5: The coding is written for each event.

Step 6: Save the project and run the project.

Step 7: Stop the process.

27
INPUT:

28
CODING:

Private Sub OPEN_Click()


CommonDialog1.ShowOpen
RichTextBox1.LoadFile CommonDialog1.FileName
End Sub

Private Sub SAVE_Click()


If FLAG = 0 Then
CommonDialog1.ShowSave
RichTextBox1.SaveFile CommonDialog1.FileName
End If
End Sub

Private Sub FONT_Click()


CommonDialog1.Flags = 1
CommonDialog1.ShowFont
Text1.FontSize = CommonDialog1.FontSize
End Sub

Private Sub EXIT_Click()


End
End Sub

OUTPUT:

29
RESULT:

The above program has been executed and verified successfully.


30
EX.NO : 06
TIMER CONTROL
DATE :

AIM:

To create a visual basic program to implement animation using timers.

ALGORITHM:

Step 1 : Start the process.

Step 2 : A new standard.exe form is created.

Step 3 : Place the appropriate controls on the form (timer, picture box and command
button)

Step 4 : Set the timer properties.

Step 5 : Place an image on the picture box.

Step 6 : Write the coding for generating animation of images using timer.

Step 7 : Save the project and run the project.

Step 8 : Stop the process.

31
INPUT:

CODING:
Private Sub Command1_Click()
End
End Sub

Private Sub Timer1_Timer()


If Image1.Visible = True Then
Image1.Visible = False
Image2.Visible = True
Image3.Visible = False

ElseIf Image2.Visible = True Then


Image2.Visible = False
Image1.Visible = False
Image3.Visible = True

ElseIf Image3.Visible = True Then


Image3.Visible = False
Image1.Visible = True
Image2.Visible = False

End If
End Sub

32
OUTPUT:

RESULT:

The above program has been executed and verified successfully.

33
EX.NO : 07
NUMBER CONVERSION
DATE :

AIM:

To create a program for accept a number as input and convert them into BINARY,
OCTAL, HEXADECIMAL.

ALGORITHM:

Step 1 : Start the process.

Step 2 : A new standard.exe form is created.

Step 3 : Place appropriate controls on the form (label boxes, command buttons, text

boxes)

Step 4 : Set appropriate properties for each controls.

Step 5 : The coding for conversion of decimal number to binary, octal & hexadecimal

written for each event in which decimal number is given as input in the text

box.

Step 6 : Then save the project and run the project.

Step 7 : Stop the process.

34
INPUT:

35
CODING:
Dim A As Integer
Dim B As Integer

Private Sub BINARY_Click()


Text2.Text = ""
A = Val(Text1.Text)
While A > 1
B = A Mod 2
Text2.Text = B & Text2.Text
A = Int(A / 2)
Wend
Text2.Text = A & Text2.Text
End Sub

Private Sub OCTAL_Click()


Text2.Text = ""
A = Val(Text1.Text)
While A > 7
B = A Mod 8
Text2.Text = B & Text2.Text
A = Int(A / 8)
Wend
Text2.Text = A & Text2.Text
End Sub

Private Sub HEXA_Click()


Text2.Text = ""
A = Val(Text1.Text)
While A >= 10
B = A Mod 16
Select Case B
Case 10
Text2.Text = "A" & Text2.Text
Case 11
Text2.Text = "B" & Text2.Text
Case 12
Text2.Text = "C" & Text2.Text
Case 13
Text2.Text = "D" & Text2.Text
Case 14
Text2.Text = "E" & Text2.Text
Case 15
Text2.Text = "F" & Text2.Text
Case Else
Text2.Text = B & Text2.Text
End Select
A = Int(A / 16)
Wend

36
If A = 0 Then
Text2.Text = Text2.Text
Else
Text2.Text = A & Text2.Text
End If
End Sub

Private Sub EXIT_Click()


End
End Sub

OUTPUT:

RESULT:

The above program has been executed and verified successfully.

37
EX.NO : 8
STUDENT MARK LIST
DATE :

AIM:

To write a VB program to manipulate the student mark list with oracle


database connectivity program.

ALGORITHM:

Step 1: Start the process.

Step 2: Open oracle with window for back end usage.

Step 3: The student table is created using create table student query with
student_id, name, class, mark, total and percentage fields.

Step 4: The values are inserted in student table using INSERT command.

Step 5: In order to view the student record select * from student query is used.

Step 6: To use the Visual basic as front end, click on Start → All Programs →
Microsoft Visual basic 6.0 – New Project.

Step 7: Select 7- labels, 7- Text boxes, 4- Command buttons and 1- adodc control
by place them in the form design window.

Step 8: Change the caption for the controls using properties window.

Step 9: If add command button is clicked, all the text box values are cleared
and it will be ready to accept new values.

38
Step 10: If save command button is clicked, save the record in database after entering
student details.

Step 11: If delete command button is clicked, data base the student values will be
deleted from data base.

Step 12: Open the code editor window and write appropriate coding.

Step 13: Run the project using start icon from toolbar and save the form write

(.frm) & project with (.vbp) extension.

Step 14: Save the program.

Step 15: Stop the process.

39
INPUT:

40
ORACLE CODING:

SQL>create table student(sid number(10),sname varchar2(20),class varchar2(20),mark1


number(3), mark2 number(3),total number(3),percentage number(3,2));

Table created.

SQL>insert into student values(001,’Deepak’,’III BCA’,70,80,150,75.00);

1 row created.

SQL>select * from student;

SID SNAME CLASS MARK1 MARK2 TOTAL PERCENTAGE

001 DEEPAK III BCA 70 80 150 75.00

VISUAL BASIC CODING:

Private Sub Command1_Click()


Adodc1.Recordset.AddNew
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text1.SetFocus
End Sub

Private Sub Command2_Click()


Adodc1.Recordset.Fields(0) = Text1.Text
Adodc1.Recordset.Fields(1) = Text2.Text
Adodc1.Recordset.Fields(2) = Text3.Text
Adodc1.Recordset.Fields(3) = Text4.Text
Adodc1.Recordset.Fields(4) = Text5.Text
Adodc1.Recordset.Fields(5) = Text6.Text
Adodc1.Recordset.Fields(6) = Text7.Text
Adodc1.Recordset.Update

41
MsgBox "record saved"
End Sub

Private Sub Command3_Click()


Adodc1.Recordset.Delete
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
MsgBox "record deleted"
End Sub

Private Sub Command4_Click()


End
End Sub

Private Sub Text6_Click()


Text6.Text = Val(Text4.Text) + Val(Text5.Text)
End Sub

Private Sub Text7_Click()


Text7.Text = Val(Text6.Text) / 10
End Sub

42
OUTPUT:

43
ORACLE

44
EX.NO : 08
EMPLOYEE DETAILS
DATE :

AIM:

To create an EMPLOYEE table with necessary fields and perform any one Logical,

Comparison, Group, Sort and Set operation.

ALGORITHM:

Step 1: Start the process.

Step 2: Create a table EMPLOYEE with the following fields Empno, name by using create

command and Set Empno as PRIMARY KEY.

Step 3: Describe the table.

Step 4: Insert number of rows in EMPLOYEE table.

Step 5: Execute any one Logical, Comparison, Group, Sort and Set statements.

Step 6: Stop the process.

45
CODING:

SQL>CREATE TABLE emp1(empno number(10),constraint empno_pk primary

key(empno),name varchar(20),designation varchar2(20),GENDER varchar2(4),age

number(3),salary number(5));

Table created.

SQL>CREATE TABLE emp2(empno number(10),constraint empid_pk primary

key(empno),name varchar(20),designation varchar2(20),GENDER varchar2(4),age

number(3),salary number(5));

Table created.

SQL> insert into emp1 values(&empno,'&name','&designation','&GENDER',&age,&salary);

Enter value for empno: 101

Enter value for name: venkat

Enter value for designation: manager

Enter value for GENDER: male

Enter value for age: 21

Enter value for salary: 50000

old 1: insert into emp1 values(&empno,'&name','&designation','&GENDER',&age,&salary)

new 1: insert into emp1 values(101,'venkat','manager','male',21,50000)

1 row created.

46
SQL> insert into emp1 values(&empno,'&name','&designation','&GENDER',&age,&salary);

Enter value for empno: 102

Enter value for name: tamil

Enter value for designation: general_manager

Enter value for GENDER: male

Enter value for age: 22

Enter value for salary: 45000

old 1: insert into emp1 values(&empno,'&name','&designation','&GENDER',&age,&salary)

new 1: insert into emp1 values(102,'tamil','general_manager','male',22,45000)

1 row created.

SQL> insert into emp1 values(&empno,'&name','&designation','&GENDER',&age,&salary);

Enter value for empno: 103

Enter value for name: naveen

Enter value for designation: apprentice

Enter value for GENDER: male

Enter value for age: 20

Enter value for salary: 1000

old 1: insert into emp1 values(&empno,'&name','&designation','&GENDER',&age,&salary)

new 1: insert into emp1 values(103,'naveen','apprentice','male',20,10)

1 row created.

47
SQL> insert into emp2 values(&empno,'&name','&designation','&GENDER',&age,&salary);

Enter value for empno: 104

Enter value for name: sathish

Enter value for designation: clerk

Enter value for GENDER: male

Enter value for age: 20

Enter value for salary: 30000

old 1: insert into emp2 values(&empno,'&name','&designation','&GENDER',&age,&salary)

new 1: insert into emp2 values(104,'sathish','clerk','male',20,30000)

1 row created.

SQL> insert into emp2 values(&empno,'&name','&designation','&GENDER',&age,&salary);

Enter value for empno: 105

Enter value for name: selva

Enter value for designation: office_boy

Enter value for GENDER: male

Enter value for age: 22

Enter value for salary: 34000

old 1: insert into emp2 values(&empno,'&name','&designation','&GENDER',&age,&salary)

new 1: insert into emp2 values(105,'selva','office_boy','male',22,34000)

1 row created.

SQL> insert into emp2 values(&empno,'&name','&designation','&GENDER',&age,&salary);

48
Enter value for empno: 105

Enter value for name: santhosh

Enter value for designation: xerox_boy

Enter value for GENDER: male

Enter value for age: 20

Enter value for salary: 10000

old 1: insert into emp2 values(&empno,'&name','&designation','&GENDER',&age,&salary)

new 1: insert into emp2 values(106,'santhosh','xerox_boy','male',20,10000)

1 row created.

SQL> select * from emp1 where salary>1000;

EMPNO NAME DESIGNATION GENDER AGE SALARY

101 venkat manager male 21 50000

102 tamil general_manager male 22 45000

SQL> select * from emp1 order by age desc;

EMPNO NAME DESIGNATION GENDER AGE SALARY

102 tamil general_manager male 22 45000

101 venkat manager male 21 50000

103 naveen apprentice male 20 1000

49
SQL>select * from emp1 union select * from emp2;

EMPNO NAME DESIGNATION GENDER AGE SALARY

102 tamil general_manager male 22 45000

101 venkat manager male 21 50000

103 naveen apprentice male 20 1000

104 sathish clerk male 20 30000

105 selva office boy male 22 34000

106 santhosh Xerox_boy male 20 10000

SQL>select name, sum(salary) from emp1 group by name;

NAME SUM(SALARY)

tamil 45000

venkat 50000

naveen 1000

SQL>select * from emp1 where age>20 and gender=’male’;

EMPNO NAME DESIGNATION GENDER AGE SALARY

101 venkat manager male 21 50000

102 tamil general_manager male 22 45000

50
EX.NO : 09
INVENTORY SYSTEM
DATE :

AIM:

To write PL/SQL program to update rate filed by 20% more. Alter table by adding a field no

of items and update VALUES without using PL/SQL.

ALGORITHM:

Step 1: Start the process.

Step 2: Create a table INVENTORY with fields prono, proname and rate.

Step 3: Insert appropriate VALUES to the table.

Step 4: Create a PL/SQL code to modify the VALUES of the column rate by 20%.

Step 5: By using Alter command add a column no of items to the table.

Step 6: Set VALUES for the no of items field using UPDATE command.

Step 7: Stop the process.

51
CODING:

SQL> CREATE TABLE inventory(prono number(5),CONSTRAINT prono_pk primary


key(prono),proname varchar2(15),rate number(7,2));

Table created.

SQL> DESC inventory;

Name Null? Type

PRONO NOT NULL NUMBER(5)

PRONAME VARCHAR2(15)

RATE NUMBER(7,2)

SQL> INSERT INTO inventory VALUES(&prono,'&proname',&rate);

Enter value for prono: 100

Enter value for proname: chair

Enter value for rate: 1000

old 1: INSERT INTO inventory VALUES(&prono,'&proname',&rate)

new 1: INSERT INTO inventory VALUES(100,'chair',1000)

1 row created.

SQL> /

Enter value for prono: 101

Enter value for proname: table

Enter value for rate: 5000

old 1: INSERT INTO inventory VALUES(&prono,'&proname',&rate)

new 1: INSERT INTO inventory VALUES(101,'table',5000)

1 row created.

52
SQL> /

Enter value for prono: 102

Enter value for proname: ac

Enter value for rate: 10000

old 1: INSERT INTO inventory VALUES(&prono,'&proname',&rate)

new 1: INSERT INTO inventory VALUES(102,'ac',10000)

1 row created.

SQL> /

Enter value for prono: 103

Enter value for proname: fan

Enter value for rate: 3000

old 1: INSERT INTO inventory VALUES(&prono,'&proname',&rate)

new 1: INSERT INTO inventory VALUES(103,'fan',3000)

1 row created.

SQL> /

Enter value for prono: 104

Enter value for proname: book

Enter value for rate: 5000

old 1: INSERT INTO inventory VALUES(&prono,'&proname',&rate)

new 1: INSERT INTO inventory VALUES(104,'book',5000)

1 row created.

53
SQL> SELECT * FROM inventory;

PRONO PRONAME RATE

100 chair 1000

101 table 5000

102 ac 10000

103 fan 3000

104 book 5000

SQL> declare

2 begin

3 update inventory set rate=rate+(rate*20/100);

4 end;

5/

PL/SQL procedure successfully completed.

SQL> SELECT * FROM inventory;

PRONO PRONAME RATE

100 chair 1200

101 table 6000

102 ac 12000

103 fan 3600

104 book 6000

54
SQL> ALTER TABLE inventory ADD(no_of_items number(5));

Table altered.

SQL> UPDATE inventory SET no_of_items=5 WHERE prono=100;

1 row updated.

SQL> UPDATE inventory SET no_of_items=10 WHERE prono=101;

1 row updated.

SQL> UPDATE inventory SET no_of_items=7 WHERE prono=102;

1 row updated.

SQL> UPDATE inventory SET no_of_items=3 WHERE prono=103;

1 row updated.

SQL> UPDATE inventory SET no_of_items=9 WHERE prono=104;

1 row updated.

SQL> SELECT * FROM inventory;

PRONO PRONAME RATE NO_OF_ITEMS

100 chair 1200 5

101 table 6000 10

102 ac 12000 7

103 fan 3600 3

104 book 6000 9

55
EX.NO : 10
BEFORE DATABASE TRIGGER
DATE :

AIM:

To create a Database Trigger to check the data validity on Inventory management

system.

ALGORITHM:

Step 1: Start the process.

Step 2: CREATE TABLE PMASTER with the necessary fields and set pno as PRIMARY

KEY.

Step 3: Create a table PTRANS with the necessary fields and set tno as PRIMARY KEY and

pno as FOREIGN KEY.

Step 4: Create a TRIGGER pm for PMASTER table to check NULL VALUES of the

Column Name before Inserting or Updating.

Step 5: Create a TRIGGER pt for PTRANS table to check the capacity not less than or equal

to zero Before Inserting or Updating.

Step 6: Stop the process.

56
CODING:

SQL> CREATE TABLE pmaster(pno number(5),CONSTRAINT pno_pk primary key(pno),name

varchar2(15),rate number(7,2));

Table created.

SQL> CREATE TABLE ptrans(tno number(5),CONSTRAINT tno_pk primary

key(tno),pno,CONSTRAINT pno_fk foreign key(pno) references pmaster,pavail number(4),qty

number(3));

Table created.

SQL> create or replace trigger pm before insert or update on pmaster for each row

2 declare

3 cursor cm is SELECT name FROM pmaster;

4 begin

5 if :new.name is null then

6 raise_application_error(-20000,'NAME CANNOT BE NULL');

7 end if;

8 end;

9/

Trigger created.

57
SQL> create or replace trigger pt before insert or update on ptrans for each row

2 declare

3 cursor ct is SELECT pavail FROM ptrans;

4 begin

5 if :new.pavail<=0 then

6 raise_application_error(-20001,'PRODUCT SHOULD AVAILABLE');

7 end if;

8 end;

9/

Trigger created.

SQL> INSERT INTO pmaster VALUES(&pno,'&name',&rate);

Enter value for pno: 101

Enter value for name:

Enter value for rate: 3000

old 1: INSERT INTO pmaster VALUES(&pno,'&name',&rate)

new 1: INSERT INTO pmaster VALUES(101,'',3000)

58
INSERT INTO pmaster VALUES(101,'',3000) *

ERROR at line 1:

ORA-20000: NAME CANNOT BE NULL

ORA-06512: at "SYSTEM.PM", line 5

ORA-04088: error during execution of trigger 'SYSTEM.PM'

SQL> INSERT INTO ptrans VALUES(&tno,&pno,&pavail,&qty);

Enter value for tno: 1001

Enter value for pno: 101

Enter value for pavail: 0

Enter value for qty: 50

old 1: INSERT INTO ptrans VALUES(&tno,&pno,&pavail,&qty)

new 1: INSERT INTO ptrans VALUES(1001,101,0,50)

INSERT INTO ptrans VALUES(1001,101,0,50)*

ERROR at line 1:

ORA-20001: PRODUCT SHOULD AVAILABLE

ORA-06512: at "SYSTEM.PT", line 5

ORA-04088: error during execution of trigger 'SYSTEM.PT'

59
EX.NO : 11
PROCEDURES
DATE :

AIM:

To write a PL/SQL program to implement the concept “Procedures”.

ALGORITHM:

Step 1: Start the process.

Step 2: CREATE TABLE with the fields id and name.

Step 3: Create a PL/SQL code to insert record in user table.

Step 4: Insert appropriate VALUES to the table.

Step 5: Display the values of user table by using SELECT statement.

Step 6: Stop the process.

60
CODING:

SQL>CREATE TABLE user(id number(6),CONSTRAINT id_pk primary key(id),name

varchar2(20));

Table created.

SQL> create or replace procedure insert user

2 (id in number, name in varchar2)

3 is

4 begin

5 insert into user values(id,'name');

6 end;

7/

Procedure created.

SQL> DESC user

Name Null? Type

ID NOT NULL NUMBER(10)

NAME VARCHAR2(20)

61
SQL> declare

2 v_id user.id%type:=&id;

3 v_name user.name%type:='&name';

4 begin

5 insert user(vid,vname);

6 end;

7/

Enter value for id: 1

old 1: v_id user.id%type:=&id;

new 1: v_id user.id%type:=1;

Enter value for name: deepak

old 1: v_name user.name%type:='&name';

new 1: v_name user.name%type:='deepak';

PL/SQL procedure successfully completed.

SQL> select * from user;

ID NAME

1 deepak

62
SQL>insert into user values(&id,'&name');

Enter value for id: 2

Enter value for name: akkas

old 1: insert into user values(&id,'&name')

new 1: insert into user values(2,'akkas')

1 row created.

SQL>insert into user values(&id,'&name');

Enter value for id: 3

Enter value for name: karan

old 1: insert into user values(&id,'&name')

new 1: insert into user values(3,'karan')

1 row created.

SQL> select * from user;

ID NAME

1 deepak

2 akkas

3 karan

63
EX.NO : 12
STUDENT MARK LIST
DATE :

AIM:

To write a VB program to manipulate the student mark list with oracle database connectivity
program.

ALGORITHM:

Step 1: Start the process.

Step 2: Open oracle with window for back end usage.

Step 3: The student table is created using create table student query with student_id, name, class,
mark, total and percentage fields.

Step 4: The values are inserted in student table using INSERT command.

Step 5: In order to view the student record select * from student query is used.

Step 6: To use the Visual basic as front end, click on Start → All Programs → Microsoft Visual basic
6.0 – New Project.

Step 7: Select 7 labels, 7 Text boxes, 4 Command buttons and 1 adodc 1 control by place them in the
form design window.

Step 8: Change the caption for the controls using properties window.

Step 9: If add command button is clicked, all the text box values are cleared and it will be ready to
accept new values.

Step 10: If save command button is clicked, save the record in database after entering student details.

Step 11: If delete command button is clicked, data base the student values will be deleted
from data base.

Step 12: Open the code editor window and write appropriate coding.

Step 13: Run the project using start icon from toolbar and save the form write (.frm) & project with
(.vbp) extension.

Step 14: Save the program.

Step 15: Stop the process.

64
INPUT:

65
ORACLE CODING:

SQL>create table student(sid number(10),sname varchar2(20),class varchar2(20),mark1


number(3), mark2 number(3),total number(3),percentage number(3,2));

Table created.

SQL>insert into student values(001,’Deepak’,’III BCA’,70,80,150,75.00);

1 row created.

SQL>select * from student;

SID SNAME CLASS MARK1 MARK2 TOTAL PERCENTAGE

001 DEEPAK III BCA 70 80 150 75.00

VISUAL BASIC CODING:

Private Sub Command1_Click()


Adodc1.Recordset.AddNew
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
Text1.SetFocus
End Sub

Private Sub Command2_Click()


Adodc1.Recordset.Fields(0) = Text1.Text
Adodc1.Recordset.Fields(1) = Text2.Text
Adodc1.Recordset.Fields(2) = Text3.Text
Adodc1.Recordset.Fields(3) = Text4.Text
Adodc1.Recordset.Fields(4) = Text5.Text
Adodc1.Recordset.Fields(5) = Text6.Text
Adodc1.Recordset.Fields(6) = Text7.Text
Adodc1.Recordset.Update

66
MsgBox "record saved"
End Sub

Private Sub Command3_Click()


Adodc1.Recordset.Delete
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text5.Text = ""
Text6.Text = ""
Text7.Text = ""
MsgBox "record deleted"
End Sub

Private Sub Command4_Click()


End
End Sub

Private Sub Text6_Click()


Text6.Text = Val(Text4.Text) + Val(Text5.Text)
End Sub

Private Sub Text7_Click()


Text7.Text = Val(Text6.Text) / 10
End Sub

67
RESULT:

68

You might also like