Documente Academic
Documente Profesional
Documente Cultură
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
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
57
02.12.2012
61 72
87
10
02.12.2012
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
OUTPUT: POWER(5,2) 25
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 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
10
OUTPUT: UPPER GOKUL EXAMPLE: SQL> select length('gokul')from dual; OUTPUT: LENGTH('GOKUL') 5
11
RESULT:
Thus the above program has been executed and verified successfully.
12
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.
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
Null?
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
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
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
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.
23
TOTALUNITS 30 5 25 10
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
OUTPUT:
PID 104 PNAME Mobile SNAME Nokia
RESULT: Thus the above program has been executed and verified successfully.
25
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
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
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
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
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')
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')
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 /
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:
Thus the above program was compiled and executed successfully. 42
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
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
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 /
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 /
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
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
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:
56
57
EXIT: Privite sub exit_click() end End sub FORM CONNECTIVITY: (i) Connection from form1 to form2.
58
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
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
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
62
63
64
65
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
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:
72
REPORT: Private Sub Command5_Click() DataReport1.Show End Sub END Private Sub Form_Load() End Sub
73
74
75
76
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.
Hari
12
78
79
80
FORM 16: Select the table name and for their connection for datareport.
81
82
83
84
RESULT:
Thus the above program has been executed and verified successfully.
85
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
89
90
91
FORM 6: Properties for data environment is set with the username and password.
92
RESULT:
Thus the above program has been executed and verified successfully. 93