Sunteți pe pagina 1din 93

NANDHA ENGINEERING COLLEGE

ERODE-52 BONAFIDE CERTIFICATE

Department of MASTER OF COMPUTER APPLICATIONS Name : ______________________________________Register No : __________________ Semester : First Branch : Computer Applications

Certified that this is a bonafide record of work done by the above student in the.Laboratory during the Academic Year 2012-2013.

Staff-in-charge

Head of the Department

Submitted for the University Practical Examination Held on

Internal Examiner

External Examiner

INDEX
S.NO DATE TITLE CREATION OF BASE TABLES AND VIEWS DATA MANIPULATION USING INSERT,DELETE AND UPDATE IN TABLE SELECT,SUB QUERIES AND JOIN 3 09.10.2012 DATA CONTROL COMMANDS HIGH-LEVEL LANGUAGE EXTENSIONS-PL/SQL OR TANSACT SQL USE OF CURSORS,PROCEDURES AND FUNCTIONS EMBEDDED SQL OR DATABASE CONNECTIVITY ORACLE OR SQL SERVER TRIGGERS PAGE NO 3 MARKS SIGNATURE

18.09.2012

13

25.09.2012

19

27

16.10.2012

36

15.11.2012

38

15.11.2012

44

22.11.2012

51

27.12.2012

WORKING WITH FORMS

57

02.12.2012

WORKING WITH MENUS WORKING WITH REPORTS

61 72
87

10

02.12.2012

FRONT END TOOLS

EXERCISE: 1 DATE:18.09.2012 CREATION OF BASE TABLES AND VIEWS.

AIM: To create the student table and view the table format. ALGORITHM: Step1: Start the program. Step2: Create the basic tables and insert the values. Step3: View the table. Step4: Some functions query was created and view the result. Step5: Stop the program.

CODING: SYNTAX : Create table tablename(column_ name1 datatype, column_ name2 datatype, column_ name datatype, column_ name4 datatype, column_ name5 datatype, column_ name6 datatype,); EXAMPLE: SQL> create table firstmca(stunamevarchar(5),gender varchar(5),rollnovarchar(5),deptnamevarchar(5),address varchar(8),percent number(10)); RESULT : Table created. SYNTAX : Insert into tablenamevalues(Values_1,Values_2,Values_3,Values_4,Values_5,Values_6);

EXAMPLE: SQL> insert into firstmcavalues('gokul','m','01','DBMS','OOTY',85); RESULT: 1 row created. EXAMPLE: SQL> insert into firstmcavalues('mano','m','02','AFM','mumbai',75); RESULT: 1 row created. EXAMPLE: SQL> insert into firstmcavalues('kalai','f','03','DS','Chennai',70); RESULT: 1 row created. EXAMPLE: SQL> insert into firstmcavalues('Vengi','m','04','PSP','London',65); RESULT: 1 row created. EXAMPLE: SQL> insert into firstmca values('sidu','f','05','CO','Lucknow',80); RESULT: 1 row created. EXAMPLE: SQL> insert into firstmcavalues('kavi','m','06','SPM','Dubai',86); RESULT: 1 row created.

SYNTAX: Select * from tablename; EXAMPLE: SQL> select * from firstmca; OUTPUT: STUNAME Gokul Mano Kalai Vengi Sidu Kavi GENDER M M F M F M 6 rows selected. SYNTAX: Select stuname from tablename; EXAMPLE: SQL> select stuname from firstmca; RESULT: STUNAME Gokul Mano Kalai Vengi Sidu kavi 6 rows selected. ROLLNO 01 02 03 04 05 06 DEPTNAME DBMS AFM DS PSP CO SPM ADDRESS Ooty Mumbai Chennai London Lucknow Dubai 75 70 65 80 86 PERCENT 85

SYNTAX: Select stuname,gender from tablename; EXAMPLE: SQL> select stuname,gender from firstmca; RESULT: STUNAME Gokul Mano Kalai Vengi Sidu kavi 6 rows selected. EXAMPLE: SQL> select sysdate from dual; RESULT: SYS DATE 18-SEP-12 GENDER M F F M M M

SYNTAX: Select max(percent) from tablename; EXAMPLE: SQL> select max(percent)from firstmca; OUTPUT: MAX(PERCENT) 86

SYNTAX: Select min(percent) from tablename; EXAMPLE: SQL> select min(percent)from firstmca; RESULT: MIN(PERCENT) 65 SYNTAX: Select avg(percent) from tablename; EXAMPLE: SQL> select avg(percent)from firstmca; OUTPUT: AVG(PERCENT) 76.833333 SYNTAX: Select stuname from tablename where percent>=80; EXAMPLE: SQL> select stuname from firstmca where percent>=80; OUTPUT: STUNA gokul sidu Kavi

SYNTAX: Altertabletablenamemodify(columnnamevarchar(6),columnamevarchar(6)); EXAMPLE: SQL> alter table firstmcamodify(stunamevarchar(6),gender varchar(6)); OUTPUT: Table altered.

SINGLE LINE FUNCTION EXAMPLE: selectSQL> select abs(-15)from dual; OUTPUT: ABS(-15) 15

EXAMPLE: SQL> select power(5,2) from dual;

OUTPUT: POWER(5,2) 25

EXAMPLE: SQL> select round(15.19,1)from dual;

OUTPUT: ROUND(15.19,1) 15.2

EXAMPLE: SQL> select sqrt(25) from dual; OUTPUT: SQRT(25) 5

EXAMPLE: SQL> select ceil(14.33) from dual; OUTPUT: CEIL(14.33) 15 EXAMPLE: SQL> select cos(90) from dual; OUTPUT: COS(90) -.4480736

EXAMPLE: SQL> select sin(180) from dual;


9

OUTPUT: SIN(180) -.8011526

EXAMPLE: SQL> select exp(5) from dual; OUTPUT: EXP(5) 148.41316 EXAMPLE: SQL> select mod(10,3) from dual; OUTPUT: MOD(10,3) 1 EXAMPLE: SQL> select lower('GOKUL') from dual; OUTPUT: LOWER gokul

EXAMPLE: SQL> select upper('gokul') from dual;

10

OUTPUT: UPPER GOKUL EXAMPLE: SQL> select length('gokul')from dual; OUTPUT: LENGTH('GOKUL') 5

EXAMPLE: SQL> select ltrim('gokul','g') from dual; OUTPUT: LTRI Okul

EXAMPLE: SQL> select rtrim('gokul','l') from dual; OUTPUT: RTRI Goku

EXAMPLE: SQL> select initcap('gokul') from dual;

11

OUTPUT: INITC Gokul

RESULT:
Thus the above program has been executed and verified successfully.

12

EXERCISE: 2(a) DATE:25.09.2012 DATA MANIPULATION

AIM: To create the data manipulation for (a) Insert Delete Update ALGORITHM: Step 1: Start the program. Step 2: Tables are crated and the values are inserted to table . Step 3: Constrains was added to the field ticket no to the table. Step 4: New column is added to the table and the table is displayed. Step 5: Stop the program.

CODING: The INSERT INTO statement

The INSERT INTO statement is used to insert a new row in a table.


SQL INSERT INTO Syntax It is possible to write the INSERT INTO statement into two forms. The first form doesnt specify the column names where the data will be inserted only their values. SYNTAX: INSERT INTO table_nameVALUES(value1,value2,value3,);

13

SQL INSERT INTO Example SQL> INSERT INTO persons VALUES (5,kalai,akkash,rome 2,jeniva);

RESULT:
1 row created. The DELETE Statement The delete statement is used to delete rows in a table. SQL DELETE syntax Delete from table_name Where some_column=some_value EXAMPLE: SQL>delete from persons Where last name =lkalai and first name=aakash; RESULT: 1 row deleted. EXAMPLE: SQL>select * from pesons; OUTPUT: P_ID 4 1 2 3 5 LASTE NAME Nilsson Hansen Swenson Petersen Tjessem FIRST NAME Johan Ola Tove Kari Jakob ADDRESSS Bracken 2 Timotevin Brogan 23 Storgt 20 CITY stavenger Sandnes Sandnes Stavenger

DELETE All Rows It is possible to delete all rows in a table without deleting the table. This means that the able structure, attributes, and indexes will be intact.

14

SYNTAX:

Delete from table_name; Or Delete * from table_name; EXAMPLE: SQL>select * from tab; OUTPUT: TNAME account bank discounts doctor tiger EXAMPLE: SQL>desc bank; OUTPUT: Name NAME ACC_NO AMMOUNT EXAMPLE: SQL>select * from discounts; OUTPUT: PRODNAME Diamonds Ruby Sapphire Emerald Topaz PRODPRICE 1000 850 600 2000 400
15

TABTYPE CLUSTERID table table table table table

Null?

Type VARCHAR2(10) NUMBER(10) NUMBER(20)

PRODDISC 10 15 25 20 30

EXAMPLE: SQL>delete discounts; RESULT: 5 rows deleted. EXAMPLE: SQL>select * from discounts; RESULT: No rows selected. The UPDATE statement The update statement is used to update the existing records in a table. SQL UPDATE Syntax Update table_nameSet column1=value, column2=value2, Where come_column=some_value; The where clause specified which record or records that should be updated. If you omit the where clauses ,all records will be updated.

SQL UPDATE with WHERE clause example EXAMPLE: SQL>select * from persons; OUTPUT: P_ID 4 1 2 3 5 LASTE NAME Nilsson Hansen Swenson Petersen Tjessem FIRST NAME Johan Ola Tove Kari Jakob ADDRESSS Bracken 2 Timotevin Brogan 23 Storgt 20 CITY stavenger Sandnes Sandnes Stavenger

16

EXAMPLE: SQL>update persons 2 set address=nisstien67,city=Sandnes 3 where lastname=tjessem and first name=Jakob; RESULT: 1 row updated. EXAMPLE: SQL>select * from persons; OUTPUT: P_ID 4 1 2 3 5 LASTE NAME Nilsson Hansen Swenson Petersen tjessem FIRST NAME Johan Ola Tove Kari Jakob ADDRESSS Bracken 2 Timotevin Brogan 23 Storgt 20 Nisstien 67 CITY stavenger Sandnes Sandnes Stavenger Sandnes

SQL update without where clause


EXAMPLE: SQL>select * from tiger; OUTPUT: SNO 1 2 3 3 4 5 6 RESULT: 7 rows selected.
17

NAME Vici Parba Jothi Rain Reshma Giri Joy

MARK 98 89 79 67 69 54 75

EXAMPLE: SQL>update tiger set sno=5,name=joy; RESULT: 7 row updated . EXAMPLE: SQL>select * from tiger; OUTPUT: SNO 5 5 5 5 5 5 5 RESULT: 7 rows selected. NAME Joy Joy Joy Joy Joy Joy Joy

RESULT:
Thus the above program has been executed and verified successfully.

18

EXERCISE: 2(b) DATE: 25.09.2012 DATA MANIPULATION

AIM: To create the data manipulation for (b) Select Sub Query Join

CODING: The SQL SELECT Statement The SELECT statement is used to select data from a database. The result is stored in a result table , called the result-set.

SQL SELECT Syntax SELECT column_list FROM table_name [WHERE Clause] [GROUP BY Clause] [HAVING Clause] [ORDER BY Clauses]; And SYNTAX: select*fromtable_name; EXAMPLE: SQL>select *from persons;
19

OUTPUT: P_ID 4 1 2 3 5 6 RESULT: 6 rows selected. The SQL SELECT DISTINCT statement In a table, some of the columns may contain duplicate values. This is not a problem however sometimes you will want to list only the different values in a table The distinct keyword can be used to return only different values. LAST NAME Nelson Hansen Svendson Pettersen Tjessem Kalai FIRST NAME Johan Ola Tove Kari Jakob Aakash ADDRESS Bakken2 Timotevin Borgvn 23 Storgt 20 Rome2 CITY Stavanger Sandnes Sandnes Stavenger jeniva

SQL SELECT DISTINCT SYNTAX: select distinctcolumn_namefromtable_name; EXAMPLE: Sql>select * from persons; OUTPUT: P_ID 4 1 2 3 5 6 RESULT: 6 rows selected
20

LASTE NAME Nilsen Hansen Svendson pettersen Tjessen kalai

FIRST NAME Johan Ola Tove Kari Jakob Aakash

ADDRESS Bakken 2 Timotevin Borgvn 23 Storgt 20 Rome2

CITY Stavanger Sandnes Sandnes Stavenger jeniva

EXAMPLE: SQL>select distinct city from persons; OUTPUT: City Stavanger Sandnes Stavenger Jeniva

The WHERE Clause The where clauses is used to extract only those records that fulfill a specified criterion. SQL WHERE SYNTAX: Select column_name from table_name where column_name operator value; WHERE clause EXAMPLE: SQL> select * from persons where city=sandnes; OUTPUT: P_ID 1 2 LASTE NAME Hansen Svendson FIRST NAME Ola Tove ADDRESS Timotevin Borgvn 23 CITY Sandnes Sandnes

JOINS
EXAMPLE: SQL> create table p1(pid number(5),pnamevarchar(20),snamevarchar(15),unitprice number(5));

21

RESULT: Table created. EXAMPLE: SQL> insert into p1 values(100,'camera','nikon',300); RESULT: 1 row created. EXAMPLE: SQL> insert into p1 values(101,'tv','onida',100); RESULT: 1 row created. EXAMPLE: SQL> insert into p1 values(102,'fridge','vediocon',150); RESULT: 1 row created. EXAMPLE: SQL> insert into p1 values(103,'ipod','apple',75); RESULT: 1 row created. EXAMPLE: SQL> insert into p1 values(104,'mobile','nokia',50); RESULT: 1 row created. EXAMPLE: SQL> select * from p1 ;

22

OUTPUT:
PID 100 101 102 103 104 PNAME Camera Tv Fridge Ipod Mobile SNAME Nikon onida Videocon Apple Nokia UNITPRICE 300 100 150 75 50

EXAMPLE: SQL> create table ordritems(odrid number(5),pid number(5),totalunits number(3),customer varchar(10)); RESULT: Table created. EXAMPLE: SQL> insert into ordritemsvalues(5100,104,30,'infosys'); RESULT: 1 row created. EXAMPLE: SQL> insert into ordritemsvalues(5101,102,5,'satyam'); RESULT: 1 row created. EXAMPLE: SQL> insert into ordritemsvalues(5102,103,25,'wipro'); RESULT: 1 row created.

EXAMPLE: SQL> insert into ordritems values(5103,101,10,'tcs');

23

RESULT: 1 row created. EXAMPLE: SQL> select * from ordritems;

OUTPUT: ORDID 5100 5101 5102 5103


EXAMPLE: SQL> select odrid,pname,unitprice,sname,totalunits from p1,ordritems where ordritems.pid=p1.pid;

PID 104 102 103 101

TOTALUNITS 30 5 25 10

CUSTOMER Infosys Satyam Wipro Tcs

OUTPUT: ORDID 5103 5101 5102 5100 PNAME tv fridge ipod mobile UNITPRICE 100 150 75 50 SNAME onida videocon apple nokia TOTALUNITS 10 5 25 30

LEFT OUTER JOIN EXAMPLE: SQL> select p1.pid,p1.pname,ordritems.odrid,ordritems.totalunits from ordritems,p1 where ordritems.pid(+)=p1.pid;

OUTPUT:
PID 100 101 102 103 104 PNAME Camera Tv Fridge Ipod Mobile ORDID 5103 5101 5102 5100 TOTALUNITS 10 5 25 30

24

RIGHT OUTER JOIN EXAMPLE: SQL> select p1.pid,p1.pname,ordritems.odrid,ordritems.totalunits from ordritems,p1 where ordritems.pid=p1.pid(+);

OUTPUT:
PID 101 102 103 104 PNAME Tv Fridge Ipod Mobile ORDID 5103 5101 5102 5100 TOTALUNITS 10 5 25 30

NON EQUI JOIN EXAMPLE: SQL> select pid,pname,sname from p1 where sname!='nokia';

OUTPUT:
PID 100 101 102 103 PNAME Camera Tv Fridge Ipod SNAME Nikon Onida Videocon Apple

EXAMPLE: SQL> select pid,pname,sname from p1 where sname='nokia';

OUTPUT:
PID 104 PNAME Mobile SNAME Nokia

RESULT: Thus the above program has been executed and verified successfully.
25

EXERCISE: 3 DATE:09.10.2012 DATA CONTROL COMMAND

AIM: To create a program using queries function. ALGORITHM: Step1: Start the process. Step2: To view the table using select query. Step3: Select the table for getting the maximum ticket no from the table using sub queries. Step4: View the ticket from the ticket header. Step5: Stop the process.

CODING:
SYNTAX: Create table tablename(variable datatype(size)); EXAMPLE: SQL> create table ch(catcode number(10)); RESULT: Table created. SYNTAX: Insert into tablenamevalues(&variable); EXAMPLE: SQL> insert into chvalues(&catcode);

26

RESULT: Enter value for catcode: 40 old 1: insert into ch values(&catcode) new 1: insert into ch values(40) 1 row created. SYNTAX: Select * from table name; EXAMPLE: SQL> select * from ch; OUTPUT: CATCODE 40

SYNTAX: Create table tablename(column_name1 datatype, column_name2 datatype, column_name3 datatype, column_name4 datatype,column_name5 datatype, column_name6 datatype); EXAMPLE: SQL> create table rh(routeid number(5),catcode number(5),origin varchar(10),destination varchar(10),distance_kms number(10),fare number(5)); RESULT: Table created. SYNTAX: insert into tablename values(value_1, value_2, value_3, value_4, value_5, value_6); EXAMPLE: SQL> insert into rhvalues(&routeid,&catcode,'&origin','&destination',&distance_kms,&fare);

27

RESULT: Enter value for routeid: 1 Enter value for catcode: 40 Enter value for origin: erode Enter value for destination: salem Enter value for distance_kms: 70 Enter value for fare: 50 old 1: insert into rh values(&routeid,&catcode,'&origin','&destination',&distance_kms,&fare) new 1: insert into rh values(1,40,'erode','salem',70,50)

1 row created. SYNTAX: Select * from tablename; EXAMPLE: SQL> select * from rh; OUTPUT: ROUTEID CATCODE ORIGIN 1 40 erode DESTINATION DISTANCE_KMS FARE salem 70 50

SYNTAX: Create table tablename(column_name1 datatype,column_name2 datatype); EXAMPLE: SQL> create table ph(place_id number(10),busstationvarchar(10)); RESULT: Table created.

28

SYNTAX: Insert into tablenamevalues(value_1,value_2); EXAMPLE: SQL> insert into phvalues(&place_id,'&busstation'); RESULT: Enter value for place_id: 1 Enter value for busstation: Erode old 1: insert into ph values(&place_id,'&busstation') new 1: insert into ph values(1,'Erode')

1 row created. SYNTAX: Select * from tablename; EXAMPLE: SQL> select * from ph; OUTPUT:

PLACE_ID 1

BUSSTATION Erode

SYNTAX: Create table tablename(column_name1 datatype, column_name2 datatype, column_name3 datatype); EXAMPLE: SQL> create table rd(route_id number(10),place_id number(10),day varchar(10)); RESULT: Table created.

29

SYNTAX: Insert into tablenamevalues(value_1,value_2,vale_3); EXAMPLE: SQL> insert into rdvalues(&route_id,&place_id,'&day'); RESULT: Enter value for route_id: 1 Enter value for place_id: 101 Enter value for day: monday old 1: insert into rd values(&route_id,&place_id,'&day') new 1: insert into rd values(1,101,'monday')

1 row created. SYNTAX: Select * from tablename; EXAMPLE: SQL> select * from rd; OUTPUT: ROUTE_ID 1 PLACE_ID 101 DAY Monday

SYNTAX: Create table tablename(column_name1 datatype,column_name2 datatype); EXAMPLE: SQL> create table th(ticketno number(10),no_of_tickets number(10)); RESULT: Table created.

30

SYNTAX: Insert into tablenamevalues(value_1,value_2); EXAMPLE: SQL> insert into thvalues(&ticket,&no_of_tickets); RESULT: Enter value for ticket: 1 Enter value for no_of_tickets: 5 old 1: insert into th values(&ticket,&no_of_tickets) new 1: insert into th values(1,5)

1 row created. SYNTAX: Select * from tablename; EXAMPLE: SQL> select * from th; OUTPUT:

TICKETNO 1

NO_OF_TICKETS 5

SYNTAX: Create table tablename(column_name1 datatype, column_name2 datatype, column_name3 datatype, column_name4 datatype, column_name5 datatype, column_name6 datatype); EXAMPLE: SQL> create table td(ticketno number(10),passenger_namevarchar(10),gender varchar(10),age number(10),seat_no number(10),amt number(10)); RESULT: Table created. 31

SYNTAX: Insert into tablenamevalues(value_1, value_2, value_3, value_4, value_5, value_6); EXAMPLE: SQL> insert into td values(&ticketno,'&passenger_name','&gender',&age,&seat_no,&amt); RESULT: Enter value for ticketno: 1 Enter value for passenger_name: gokul Enter value for gender: male Enter value for age: 22 Enter value for seat_no: 5 Enter value for amt: 50 old 1: insert into td values(&ticketno,'&passenger_name','&gender',&age,&seat_no,&amt) new 1: insert into td values(1,'gokul','male',22,5,50) 1 row created. SYNTAX: Select * from tablename; EXAMPLE: SQL> select * from td; OUTPUT: TICKETNO 1 PASSENGER_NAME gokul GENDER male AGE 22 SEAT_NO 5 AMT 50

SYNTAX: Select * from tablename where origin=value and destination=value;

EXAMPLE: SQL> select * from rh where origin='chennai' and destination='coimbatore'; 32

OUTPUT:

ROUTEID 3 SYNTAX:

CATCODE 60

ORIGIN chennai

DESTINATION Coimbatore

DISTANCE_KMS 75

FARE 200

Select distinct columnname from tablename order by columnnamedesc; EXAMPLE: SQL> select distinct catcode from rh order by catcodedesc;

OUTPUT: CATCODE 40 50 60

SYNTAX: Select * from tablename;

EXAMPLE: SQL> select * from rh; OUTPUT: ROUTEID 1 2 3 CATCODE 40 50 60 ORIGIN erode chennai chennai DESTINATIO salem salem coimbatore DISTANCE_KMS 70 80 75 FARE 50 100 200

33

RESULT:
Thus the above program has been executed and verified successfully.

34

EXERCISE: 4 DATE: 16.10.2012 HIGH LEVEL LANGUAGES EXTENSION-PL/SQL or TRANSACT SQL

AIM: Display the row from table details and route details with greater than of table header and route header in the ticket number. ALGORITHM: Step1: Start the process. Step2: All rows are displayed by subquires from the table. Step3: View table is displayed. Step4: Create a ticket number, tables and if it display by using quries. Step5: Stop the process.

CODING: EXAMPLE: SQL> select * from td where ticketno>any(select ticketno from th); OUTPUT: TICK 401 EXAMPLE: SQL> select * from rh where rout_id>all(select rout_id from rd where place_id=100); OUTPUT: ROUT_ID CATCODE ORIGIN DESTINATION 001 20 madras erode DISTANCE_KMS 200 PASS_NAME GENDER arun MALE AGE 21 SEATNO AMOUNT 44 100

35

EXAMPLE: SQL> create view tke as select a.ticketno,b.origin,destination,rout_id from tha,rh b; OUTPUT: View created. EXAMPLE: SQL> select* from tke;

OUTPUT:
TICK_NO ORIGIN 301 madras DESTINATION Erode ROUT_ID 001

RESULT:
Thus the above program was compiled and executed successfully. 36

EXERCISE: 5 DATE: 15.11.2012 USE OF CURSORS, PROCEDURES AND FUNCTIONS

AIM: To create a function, cursor and procedures for using pl/sql queries. ALGORITHM: Step1: Start the process. Step2: Use function to declare the variable. Step 3: Create the cursor to find the balance amount will greater than 300 in the table. Step4: Create a new table account and insert the value. Step5: By using the balance >2500. Step6: Stop the process.

CODING: FUNCTION CREATION: SQL> create or replace function large(a number,bnumber,c number)return number is large number(3); 2 begin 3 large:=a; 4 if(large<b)then 5 large:=b; 6 end if; 7 if(large<3)then 8 large:=c; 9 end if; 10 return(large);
37

11 end; 12 /

RESULT:
Function created.

FUNCTION DECLARATION: SQL> declare 2 a number(3); 3 b number(3); 4 c number(3); 5 d number(3); 6 begin 7 a:=&n1; 8 b:=&n2; 9 c:=&n3; 10 d:=large(a,b,c); 11 dbms_output.put_line('large no is '||d); 12 end; 13 /

RESULT:
Enter value for n1: 5 old 7: a:=&n1; new 7: a:=5; Enter value for n2: 3 old 8: b:=&n2;
38

new 8: b:=3; Enter value for n3: 6 old 9: c:=&n3; new 9: c:=6; large no is 5

RESULT:
PL/SQL procedure successfully completed.

TABLE CREATION: SQL> create table account11(acc_idvarchar(20),name varchar(20),balance number(5)); RESULT: Table created. EXAMPLE: SQL>insert into account11 values('&acc_id','& name','& balance'); Enter value for acc_id: a101 Enter value for name: siddhu Enter value for balance: 50000 old 1: insert into account11 values('&acc_id','& name','& balance') new 1: insert into account11 values('a101','siddhu','50000') RESULT: 1 row created. EXAMPLE: SQL>insert into account11 values('&acc_id','& name','& balance'); Enter value for acc_id: a102 Enter value for name: sumi Enter value for balance: 25000
39

old 1: insert into account11 values('&acc_id','& name','& balance') new 1: insert into account11 values('a102','sumi','25000')

RESULT: 1 row created.

EXAMPLE: SQL>insert into account11 values('&acc_id','& name','& balance'); Enter value for acc_id: a103 Enter value for name: arul Enter value for balance: 15000 old 1: insert into account11 values('&acc_id','& name','& balance') new 1: insert into account11 values('a103','arul','15000')

RESULT: 1 row created.

IMPLICIT CURSOR: SQL>declare 2 cursor c123 is select acc_id,name,balance from acc11 where balance>300; 3 a acc11.acc_id %type; 4 n acc11.name%type; 5 b acc11.balance%type; 6 begin 7 open c123; 8 loop 9 fetch c123 into a,n,b;
40

10 exist when c123% not found; 11 dbms-output.put-line('account-id'||a); 12 dbms-output.put-line('name:'||n); 13 dbms-output.put-line('balance:'||b); 14 end loop; 15 close c123; 16 end; 17 /

RESULT: account-ida101 name:siddhu balance:50000 PL/SQL procedure successfully completed.

EXPLICIT CURSOR: SQL>declare 2 cursor c124 is select * from acc11; 3 id varchar2(14); 4 x c124 % rowtype; 5 begin 6 open c124; 7 id:= '&acc_id'; 8 loop 9 fetch c124 into x; 10 exit when(id=x.acc_id); 11 end loop;
41

12 update acc11 set balance=balance+(balance * 0.02)where acc_id=id and balance>300; 13close c124; 14end; 15 Enter value for acc_id:102 16 Old 7:id:='&acc_id'; 17 New 7:id:='102';

RESULT: PL/SQL procedure successfully completed.

RESULT:
Thus the above program was compiled and executed successfully. 42

EXERCISE: 6 DATE: 15.11.2012 EMBEDDED SQL OR DATABASE CONNECTIVITY

AIM: To create a database using a embedded sql or database connectivity. ALGORITHM: Step1: Start the process. Step2: Create the table and enter the values for sub queries. Step 3: Select the particular values by using the sub queries. Step4: Connect the two columns of one table and view as on in another table. Step5: View the table of two table if the values of two column are same. Step6: Stop the process.

CODING: Example: SQL> create table studdetail(id number(30),firstnamevarchar(20),last varchar(20),age number(20),subject varchar(2),games varchar(20)); RESULT: Table created. EXAMPLE: SQL> insert into studdetailvalues('&acc_id','&firstname','&lastname','&age','&subject','&games'); Enter value for acc_id: 100 Enter value for firstname: siddhu Enter value for lastname: prasath Enter value for age: 20

43

Enter value for subject: ss Enter value for games: cricket old 1: insert into studdetail values('& acc_id','&firstname','&lastname','&age','&subject','&games new 1: insert into studdetail values('100','siddhu','prasath','20','ss','cricket') RESULT: 1 row created. Example: SQL> insert into studdetailvalues('&acc_id','&firstname','&lastname','&age','&subject','&games'); Enter value for acc_id: 200 Enter value for firstname: sumi Enter value for lastname: sampath Enter value for age: 21 Enter value for subject: sc Enter value for games: hockey old 1: insert into studdetail values('&acc_id','&firstname','&lastname', '&age','&subject','&games); new 1: insert into studdetail values('200','sumi','sampath','21','sc','hockey') RESULT: 1 row created. Example: SQL> insert into studdetailvalues('& acc_id','&firstname','&lastname', '&age','&subject','&games'); Enter value for acc_id: 300 Enter value for firstname: sudhiksha Enter value for lastname: nandhu

44

Enter value for age: 18 Enter value for subject: tt Enter value for games: tenis old1: insert into studdetailvalues('& acc_id','&firstname', '&lastname','&age','&subject','&games new 1: insert into studdetail values('300','sudhiksha','nandhu','18','tt','tenis')

RESULT: 1 row created. EXAMPLE: SQL> select *from studdetail; OUTPUT: ID FIRSTNAME 100 siddhu 200 sumi 300 sudhiksha SUB QUERIES EXAMPLE: SQL> select id,firstname from studdetail where firstname in (select firstname from studdetail where su='ss'); OUTPUT: ID 100 FIRSTNAME siddhu LAST prasath sampath nandhu AGE SU GAMES 20 ss cricket 21 sc hockey 18 tttenis

EXAMPLE: SQL> create table mathsgroup13(id number(5),name varchar(20));

45

RESULT: Table created. EXAMPLE: SQL> insert into mathsgroup13 values(400,'arul'); RESULT: 1 row created. EXAMPLE: SQL> insert into mathsgroup13 values(500,'sindhu'); RESULT: 1 row created. EXAMPLE: SQL> select *from mathsgroup13; OUTPUT: ID 400 500 EXAMPLE: SQL> select *from studdetail where age>=(select avg(age)from studdetail); OUTPUT: ID FIRSTNAME 400 arul EXAMPLE: SQL> create table product (product number (4), productnamevarchar (10), suppliernamevarchar (10), unitprice number (10)); RESULT: Table created. EXAMPLE: SQL> insert into product values(100,'camera','canon',7000); LAST NMAE AGE prasath 27 GAMES football NAME arul sindhu

46

RESULT: 1 row created. EXAMPLE: SQL> insert into product values(200,'ipod','apple',18000); RESULT: 1 row created. EXAMPLE: SQL> insert into product values(300,'ac','bluestar',30000); RESULT: 1 row created. EXAMPLE: SQL> insert into product values(400,'fridge','samsung',20000); RESULT: 1 row created. EXAMPLE: SQL> select *from product; OUTPUT: PRODUCTID 100 200 300 400 PRODUCTNAME Camera Ipod Ac Fridge SUPPLIERNAME Canon Apple Bluestar Samsung UNITPRICE 7000 18000 30000 20000

EXAMPLE: SQL> create table orderitem(ordered number(10),productid number(10),totalunits number(10),customer varchar(10)); RESULT: Table created.
47

EXAMPLE: SQL> insert into orderitemvalues(2000,100,40,'wipro'); RESULT: 1 row created. EXAMPLE: SQL> insert into orderitemvalues(3000,200,50,'infosys'); RESULT: 1 row created. SYNTAX: SQL> insert into orderitemvalues(4000,300,60,'hcl'); RESULT: 1 row created. RESULT: SQL> select *from orderitem; OUTPUT: ORDERID 2000 3000 4000 PRODUCTID 100 200 300 TOTALUNITS 40 50 60 CUSTOMER Wipro Infosys HCL

SYNTAX: SQL> select orderid,productname,unitprice,suppliername,totalunits from product,orderitem where orderitem.productid=product.productid; OUTPUT: ORDERID PRODUCTNAME 2000 camera 3000 ipod 4000 ac UNITPRICE 7000 18000 30000 SUPPLIER canon apple bluestar TOTALUNITS 40 50 60

48

SYNTAX: SQL>select orderid,product.productname,product.unitprice,product.supplier.order. Totalunitsfrom product.product,orderitem.order where order.productid=p.productid; OUTPUT: ORDERID PRODUCTNAME 2000 camera 3000 ipod UNITPRICE 7000 18000 SUPPLIER canon apple TOTALUNITS 40 50

RESULT:
Thus the above program has been executed and verified successfully.

49

EXERCISE: 7 DATE:22.11.2012 ORACLE OR SQL SERVER TRIGGERS

AIM:
To create a program using transaction control language and data control command.

ALGORITHM:
Step1:Start the program. Step2:Using transaction control language commit,rollback,savepoint. Step3:Commit is used to save the changes. Step4:Rollback can be used to restore the values. Step5:Savepoint is used to save the values. Step6:By using data control commands such as grant revoke we can be grant the permission. Step7:Stop the program.

CODING:

SYNTAX: SQL> create table gokul(name varchar(10),balance number(10)); RESULT: Table created. EXAMPLE: SQL> insert into gokulvalues('elango',1500); RESULT: 1 row created. EXAMPLE: SQL> insert into gokulvalues('durai',1200);

50

RESULT: 1 row created. EXAMPLE: SQL> insert into gokulvalues('gowri',1900); RESULT: 1 row created. EXAMPLE: SQL> insert into gokulvalues('inba',2500); RESULT: 1 row created. EXAMPLE: SQL> select * from gokul; OUTPUT: NAME Elango Durai Gowri Inba BALANCE 1500 1200 1900 2500

PROGRAM 1:

SQL> set serveroutput on; SQL> create or replace trigger trg1 before update or insert or delete on gokul 2 for each row 3 begin 4 if updating then 51

5 dbms_output.put_line('updating'); 6 elsif inserting then 7 dbms_output.put_line('inserting'); 8 elsif deleting then 9 dbms_output.put_line('deleting'); 10 end if; 11 end; 12 /

OUTPUT: Trigger created.

PROGRAM 2:

SQL> create or replace trigger trg2 2 before update on gokul 3 for each row 4 begin 5 if:new_balance<2000 then 6 raise_application_error(-1800,'low balance'); 7 end if; 8 end trg2; 9 /

OUTPUT: Trigger created.

52

PROGRAM 3:

SQL> create trigger trg3 after insert on t4 referencing new as newrows for each row when(newrows.balance=1800) 2 begin 3 insert into t5 values(:newrows.balance=1800) 4 begin 5 insert into t5 values(:newrows.b1:newrows.a) 6 end trg3; 7 / EXAMPLE: SQL>Create table I(a number(20), b varchar(25)); RESULT: Table created EXAMPLE: SQL> create table s (b varchar(20), a number(25)); RESULT: Table created Trigger created EXAMPLE: SQL> insert into I values(10,cool); RESULT: One row created

EXAMPLE: Select * from s;

53

OUTPUT: B COOL A 10

PROGRAM 4:

SQL> trigger to delete the account details when customer gets deleted SQL> create or replace trigger trg4 After delete on table name For each row Begin Delete from table name when table name. column name; End; SYNTAX: SQL> create table a1(name varchar2(20),custid number(30)); RESULT: Table created. EXAMPLE: create table b1(name varchar2(20),custid number(30)); RESULT: Table created. Insert into a1(&name,&custid); Insert into name:Gokul Insert into custid:08 OUTPUT: Trigger created.

54

RESULT:
Thus the above program has been executed and verified successfully.

55

EXERCISE: 8 DATE:27.11.2012 WORKING WITH FORMS

AIM:
To write a program in vb.net for creating a forms for arithmetic operation.

ALGORITHM:
Step1: Start the process. Step2: Create a form in vb. Step3: Place five command buttons, give the name for command button. Step4: Display code page by clicking the button. Step5: Enter the code for corresponding buttons as given below. Step6:Execute the program by clicking run in the menu. Step7:Stop the process.

CODING:

ADDITION: Private Sub Command1_Click() Text3.Text = Val(Text1.Text) + Val(Text2.Text) End Sub

SUBTRACTION: Private Sub Command2_Click() Text3.Text = Val(Text1.Text) - Val(Text2.Text) End Sub

56

MULTIPLICATION: Private Sub Command3_Click() Text3.Text = Val(Text1.Text) * Val(Text2.Text) End Sub

DIVISION: Private Sub Command4_Click() Text3.Text = Val(Text1.Text) / Val(Text2.Text) End Sub

EXIT: Private Sub Command5_Click() End End Sub

MENU DESIGN: BLUE: Privite sub mblue_click() Form1.backcolor=vbblue End sub

GREEN: Privite sub mgreen_click() Form1.backcolor=vbgreen End sub

57

RED: Privite sub mred_click() Form1.backcolor=vbred End sub

EXIT: Privite sub exit_click() end End sub FORM CONNECTIVITY: (i) Connection from form1 to form2.

58

FORM DESIGN: (ii) Sample Input is given below.

(iii) (iv) (v) (vi) (vii)

Then enter the values in text box1 and textbox2. And click on add command button. The result will be displayed in the result text box. Likewise for subtraction,multiplication and division. Finally click on exit command button.

RESULT:
Thus the above program has been executed and verified successfully. 59

EXERCISE: 9(a) DATE:02.12.2012 WORKING WITH MENU

AIM:
To create a program in vb for creating a menu design.

ALGORITHM:
Step1: Start the process. Step2: Create a form in vb. Step3: Select menu->tools->menu editor ->caption enter &file and &Edit. Step4:&File is the main menu item that lists save,new,minimize,exit when u click on the File option. Step5:In caption enter save,new,minimize,exit and click right arrow ,these details to be entered and Dislayedbelow file option. Step6:In menu->tools->menu editor ->short cut enter ctrl+s ,ctrl+n for short options. Step7:Incaption enter edit,cut,copy,paste and click right arrow ,these details to be entered anddislayedbelow edit option. Step8: In menu->tools->menu editor ->short cut enter ctrl+ e,ctrl+x, ctrl+c, ctrl+v for shortcut Step9: Code to be written for (file->save,new,minimize,exit and edit->edit,cut,copy,paste) double click on these particulars to write code for these to perform its operation. Step10:Execute the program by double clicking run button in the menu Step11: Stop the process.

CODING:
COPY: Private Sub menucopy_Click() Clipboard.Clear 60

Clipboard.SetText Text1.SelText End Sub CUT: Private Sub menucut_Click() Clipboard.Clear Clipboard.SetText Text1.SelText Text1.SelText = "" End Sub

EXIT: Private Sub menuexit_Click() End End Sub

MINIMIZE: Private Sub menuminimize_Click() Form1.WindowState = 1 End Sub NEW: Private Sub menunew_Click() Text1.Text = "" End Sub PASTE: Private Sub menupaste_Click() Text1.SelText = Clipboard.GetText() End Sub

61

SAVE: Private Sub menusave_Click() commondialog1.Filter = "all files(*.*)|*.*|text files(*.txt)|*.txt" CommonDialog1.ShowSave Dim ifile As Integer ifile = FreeFile Open commondialod1.FileName For Output As #file Print #ifile, Text1.Text End Sub

FORM 1: Empty input form.

62

FORM 2: Input form with MENU values.

FORM 3: Form for arrow indication.

63

FORM 4: Form with list values with their shortcut keys.

FORM 5: Form with list value SAVE.

64

FORM 6: Form with main menu EDIT.

FORM 7: Form with list value CUT.

65

FORM 8: Form with common dialogue box and multivaluepropertie as TRUE.

FORM 9: Form with scroll propertie as 3-bothfor scrolling the common dialogue box as up and down as well right and left..

66

FORM 10: In the component dialogue box enable the MICROSOFT COMMON DIALOG CONTROL 6.0(SP3)

FORM 11: In this form click on file->new to enter the sentence or a paragraph.

67

FORM 12: After enter into that box, click on save option from file menu to save that sentence.

FORM 13: In this form, we can perform copy the sentence from that box.

68

FORM 14: After the sentence is copied, we can perform paste option from the edit menu.

FORM 15: Now that selected sentence is pasted in that text box.

69

FORM 16: In this form, we can cut the required words from that sentence.

FORM 17: The required word can be cut frim that text box.

RESULT:
Thus the above program has been executed and verified successfully.

70

EXERCISE: 9(b) DATE:02.12.2012 WORKING WITH REPORTS

AIM:
To create a program in vb for creating a student report.

ALGORITHM:
Step1: Start the process. Step2: Create a table in oracle. Step3: Create a form in vb. Step4:Place five buttons ,double click on each to write code to perform the desired opearttion. Step5:Execute the program by double clicking run button in the menu ,click add new button and enter details and click save button the details entered is updated in the table. Step6:Display values in the oracle Step7: Right click->components->[controls->Microsoft datacontrol 6.0(SP4)(OLEDB),designers->data environment ,data control]click ok Step8: A picture for adodc will appear in the tool box->right click->adodc properties->3rd option->build ->authentication->record source->select the name of the table created in oracle. Step9: Click project explorer->form1->right click->add->data environment->a dialogue box appear->data environment1_connection1->right click->Microsoft oledb provider for oracle->click ok Step10:Click project explorer->form1->right click->add->data environment->a dialogue box appear->data environment1_connection1->right click->add command->command1 will be appear after connection1->right click on command1->properties->data base object->dropdown list select(TABLE)->In object name provide user name, password->your table will appear->select the table name. Step11: Click project explorer->form1->right click->add->data environment->a dialogue box appear>data report->report1 dialogue box will appear Step12:Drag command1 from project environment to data report execute the program by double clicking run button in the menu click report button, a report for student will be generated Step13: Stop the process.

71

SYNTAX: SQL> create table gokul(Name varchar(10),RollNo number(10)); RESULT: Table created. CODING:

ADD NEW: Private Sub Command1_Click() Adodc1.Recordset.AddNew End Sub

SAVE: Private Sub Command2_Click() Adodc1.Recordset.Save End Sub

DELETE: Private Sub Command3_Click() Adodc1.Recordset.Delete End Sub

UPDATE: Private Sub Command4_Click() Adodc1.Recordset.Update End Sub

72

REPORT: Private Sub Command5_Click() DataReport1.Show End Sub END Private Sub Form_Load() End Sub

FORM1: Sample input form

73

FORM 2: Form for ADODC properties.

FORM 3: Form for selection of data environment,data report.

74

FORM 4; Form that shows the ADODC properties.

FORM 5: Establishilng connection from database.

75

FORM 6: Establishing authendication with username and password.

FORM 7: Specifying tablename for recordsource.

76

FORM 8: Properties set to ADODC1 for datasource as object.

FORM 9: Set the datafield in properties as name for textbox1 and same as for that rollno for textbox2.

77

FORM 10: Here we can enter the name and rollno in that text box.

EXAMPLE: SQL> select * from gokul;

RESULT: NAME ROLLNO

Hari

12

78

FORM 11: DataEnvironment is made enabled.

FORM 12: Set properties for command1.

79

FORM 13: Enable the database connection for report.

FORM 14: Add the command from command1 properties.

80

FORM 15: Set the command properties for command.

FORM 16: Select the table name and for their connection for datareport.

81

FORM 17: Select the table name as given in database.

FORM 18: Select the data report from the properties.

82

FORM 19: Data report form is now generated.

FORM 20: In the properties dialog box select datamember as command1.

83

FORM 21: On compilation for generality reporting, security is provided.

FORM 22: Reporrt form is now generated.

84

FORM 23: Output for the report is given below.

RESULT:
Thus the above program has been executed and verified successfully.

85

EXERCISE: 10 DATE:02.12.2012 FRONT END TOOLS

AIM:
To create a program in vb for creating a bank report generation.

ALGORITHM:
Step1: Start the process. Step2: Create a table in oracle. Step3: Create a form in vb. Step4: Place eleven buttons; double click on each to write code to perform the desired operation. Step5: Execute the program by double clicking run button in the menu ,click add button and enter details and click save button the details entered is updated in the table. Step6:Display values in the oracle Step7: Right click->components->[controls->Microsoft data control 6.0(SP4)(OLEDB),designers->data environment ,data control]click ok Step8: A picture for adodc will appear in the tool box->right click->adodc properties->3rd option->build ->authentication->record source->select the name of the table created in oracle. Step9: Click project explorer->form1->right click->add->data environment->a dialogue box appear->data environment1_connection1->right click->Microsoft oledb provider for oracle->click ok Step10: Click project explorer->form1->right click->add->data environment->a dialogue box appear->data environment1_connection1->right click->add command->command1 will be appear after connection1->right click on command1->properties->data base object->dropdown list select(TABLE)->In object name provide user name, password->your table will appear->select the table name. Step11: Click project explorer->form1->right click->add->data environment->a dialogue box appear>data report->report1 dialogue box will appear Step12:Drag command1 from project environment to data report execute the program by double clicking run button in the menu click report button, report for bank report will be generated Step13: Stop the process.

86

CODING: ADD NEW: Private Sub Command1_Click() Adodc1.Recordset.AddNew End Sub REPORT: Private Sub Command10_Click() DataReport1.Show End Sub END: Private Sub Command11_Click() End End Sub MOVEFIRST: Private Sub Command2_Click() Adodc1.Recordset.MoveFirst End Sub MOVENEXT: Private Sub Command3_Click() Adodc1.Recordset.MoveNext End Sub SAVE: Private Sub Command4_Click() Adodc1.Recordset.Save End Sub

87

UPDATE: Private Sub Command5_Click() Adodc1.Recordset.Update End Sub MOVELAST: Private Sub Command6_Click() Adodc1.Recordset.MoveLast End Sub DELETE: Private Sub Command7_Click() Adodc1.Recordset.Delete End Sub MOVEPREVIOUS: Private Sub Command8_Click() Adodc1.Recordset.MovePrevious End Sub CLEAR: Private Sub Command9_Click() Text1.Text = "" Text2.Text = "" Text3.Text = "" Text4.Text = "" Text5.Text = "" Text6.Text = "" Text7.Text = "" Text8.Text = ""

88

Text9.Text = "" End Sub

Private Sub Label3_Click() End Sub

FORM 1: Option for ADODC1 is set enabled.

89

FORM 2: Build the connection string as provider=MSDAORA.1

FORM 3:; Security is provided atthi stage.

90

FORM 4: Form for datareport size at final step of the process.

FORM 5: Database connection is provided.

91

FORM 6: Properties for data environment is set with the username and password.

FORM 7: Report is generated.

92

FORM 8: Drag data content from command1 to datareport.

FORM 9: Finally the datareport is generated from the database.

RESULT:
Thus the above program has been executed and verified successfully. 93

S-ar putea să vă placă și