Ex. No: 1 STUDY OF DDL COMMANDS AIM : To study the usage of various data definition language commands. PROCEDURE : DDL is used to create an object (e.g. table) ,alter the structure of an object and also to drop the object created. The DDL commands are i) Create table ii) Alter table iii) Truncate table iv) Drop table 1. Create Table It is used to create a table with a certain fields. Syntax create table tablename ( field1 datatype1 ,field2 datatype2,……..); 2. Alter Table It is used to add or delete a field from the table. Syntax To add a field alter table tablename add fieldname datatype; To drop a field alter table tablename drop column fieldname; To modify the datatype
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Ex. No: 1 STUDY OF DDL COMMANDS
AIM: To study the usage of various data definition language commands.
PROCEDURE:
DDL is used to create an object (e.g. table) ,alter the structure of an object and also to drop the object created.
The DDL commands are i) Create tableii) Alter tableiii) Truncate tableiv) Drop table
1. Create Table It is used to create a table with a certain fields.
SQL> desc students; Name Null? Type ---------------------------- -------- --------------------------- SNAME VARCHAR2(10) REGNO NUMBER SEM NUMBER
2. Alter Table Command
Add Command
SQL> alter table students add dept varchar(5);
Table altered.
SQL> desc students; Name Null? Type --------------------------------- --------------------------- SNAME VARCHAR2(10) REGNO NUMBER SEM NUMBER DEPT VARCHAR2(5)
Drop Command
SQL> alter table students drop column dept;
Table altered.
Modify Command
SQL> alter table students modify sem varchar(5);
Table altered.
3. Truncate Command
SQL> insert into students values('anitha',5001,'3');
1 row created.
SQL> insert into students values('priya',5002,'5');
1 row created.
SQL> select * from students;
SNAME REGNO SEM---------- ---------- -----anitha 5001 3priya 5002 5
SQL> truncate table students;
Table truncated.
4. Drop Command
SQL> drop table students; Table dropped.
SQL> select * from students;select * from students *ERROR at line 1:ORA-00942: table or view does not exist
RESULT: Thus the DDL commands are studied and executed.
Ex. No: 2 STUDY OF DML COMMANDS
AIM: To study the usage of various data manipulation language commands.
PROCEDURE:
DML are used to query and manipulate existing objects like tables.
The DML commands are i) Insert Commandii) Select Commandiii) Update Commandiv) Delete Command
1. Insert Command It is used to insert records into the table. Syntax insert into tablename values (values…………..);
2. Select Command It is used to display the records from the table which satisfies the condition.
Syntax select * from tablename where condition;
3. Update Command It is used to update the records which are already present in the table.
Syntax update tablename set fieldname = value where condition;
4. Delete Command It is used to delete the records from the table with some condition.
Syntax delete from tablename where condition;
OUTPUT: 1. Insert Command
SQL> desc students; Name Null? Type ----------------------------------------- -------- ---------------------------- SNAME VARCHAR2(10) REGNO NUMBER SEM NUMBER DEPT VARCHAR2(5)
SQL> insert into students values('anitha',5001,5,'cse');
1 row created.
SQL> insert into students values('&name',®no,&sem,'&dept');Enter value for name: arunEnter value for regno: 5002Enter value for sem: 5Enter value for dept: cseold 1: insert into students values('&name',®no,&sem,'&dept')new 1: insert into students values('arun',5002,5,'cse')
1 row created.
SQL> /Enter value for name: bharathiEnter value for regno: 5003Enter value for sem: 5Enter value for dept: itold 1: insert into students values('&name',®no,&sem,'&dept')new 1: insert into students values('bharathi',5003,5,'it')
1 row created.
SQL> insert into students values('anitha',5004,3,'cse');
1 row created.
2. Select Command
SQL> select * from students;
SNAME REGNO SEM DEPT---------- --------- ------- --------anitha 5001 5 csearun 5002 5 csebharathi 5003 5 itanitha 5004 3 cse
SNAME REGNO SEM DEPT---------- --------- ------- --------anitha 5001 5 csearun 5002 5 csebharathi 5003 5 itanitha 5004 3 cse
SQL> select * from students where regno >= 5002 and dept = 'cse';
SNAME REGNO SEM DEPT---------- --------- ------- --------arun 5002 5 cseanitha 5004 3 cse3. Update Command
SQL> update students set dept = 'cse' where sname = 'bharathi';
1 row updated.
SQL> update students set sem= 5 where regno = 5004;
1 row updated.
SQL> select * from students;
SNAME REGNO SEM DEPT---------- --------- ------- --------anitha 5001 5 csearun 5002 5 csebharathi 5003 5 cseanitha 5004 5 cse
4. Delete Command
SQL> delete from students where regno = 5004;
1 row deleted.
SQL> select * from students;
SNAME REGNO SEM DEPT---------- --------- ------- --------anitha 5001 5 csearun 5002 5 csebharathi 5003 5 cse
SQL> delete from students;
3 rows deleted.
SQL> select * from students;
no rows selected
RESULT: Thus the DML commands are studied and executed.Ex. No: 3 STUDY OF DCL COMMANDS
AIM: To study the usage of various data control language commands.
PROCEDURE:
DCL provides user with privileges commands. The owner of database objects (E.g. table) has the sole authority over them.
i) Grant Command ii) Revoke Command
1) Grant Command
To grant the privileges on a particular table to another user.
Syntax:
Grant privileges on tablename to user;
2) Revoke Command To revoke the privileges on a particular table from another user. Syntax: Revoke privileges on tablename from user;
3) Create user To create new user.
Syntax: Create user username identified by another username;
OUTPUT:
1) Creating User
SQL> create user system1 identified by system;
User created.
SQL> desc students; Name Null? Type ----------------------------------------- -------- ---------------------------- SNAME VARCHAR2(10) REGNO NUMBER SEM NUMBER DEPT VARCHAR2(5)
SQL> insert into students values('anitha',5001,5,'cse');
1 row created.
SQL> insert into students values('&name',®no,&sem,'&dept');Enter value for name: arunEnter value for regno: 5002Enter value for sem: 5Enter value for dept: cseold 1: insert into students values('&name',®no,&sem,'&dept')new 1: insert into students values('arun',5002,5,'cse')
1 row created.
SQL> /Enter value for name: bharathiEnter value for regno: 5003Enter value for sem: 5Enter value for dept: itold 1: insert into students values('&name',®no,&sem,'&dept')new 1: insert into students values('bharathi',5003,5,'it')
1 row created.
SQL> insert into students values('anitha',5004,3,'cse');
1 row created.
SQL> select * from students;
SNAME REGNO SEM DEPT---------- --------- ------- --------anitha 5001 5 csearun 5002 5 csebharathi 5003 5 itanitha 5004 3 cse
2) Grant Command
SQL> grant select , update on students to system1;
Grant succeeded.
SQL> grant all on students to system1;
Grant succeeded.
3) Revoke Command
SQL> revoke update,select on students from system1;
Revoke succeeded.
SQL> revoke all on students from system1;
Revoke succeeded.
RESULT: Thus the DCL commands are studied and executed.
Ex. No: 4 STUDY OF TCL COMMANDS
AIM: To study the usage of various transaction control language commands.
PROCEDURE:
A transaction is a logical unit of work. All changes made to the database can be referred to as a transaction. Transaction changes can be made permanent to a database only if they are committed.
TCL commands arei) Commitii) Save pointiii) Rollback
1) Commit This command is used to end a transaction. It is used made the transaction changes permanent to the database. This command also erases all save points in the transaction.
Syntax: commit;
2) Save point Save points are like markers to divide a very lengthy transaction to smaller ones. They are used to identify a point in transaction to which user can later rollback.
Syntax: savepoint savepoint_id;
3) Rollback A rollback command is used to undo the work done in the current transaction. User can either rollback the entire transaction so that all changes made by SQL statements are undone , or rollback a transaction to a save point .
Syntax: rollback; or rollback to savepoint _id;
OUTPUT:
1) Savepoint SQL> select * from students;
SNAME REGNO SEM DEPT---------- --------- ------- -------anitha 5001 5 csepriya 5002 5 csekumar 5001 5 cseanita 4001 5 cse
SQL> update students set sname = 'christy' where regno = 4001;
1 row updated.
SQL> insert into students values('abirami',5003,5,'it');
1 row created.
SQL> savepoint mark1;
Savepoint created.
SQL> select * from students;
SNAME REGNO SEM DEPT---------- --------- ------- -------anitha 5001 5 csepriya 5002 5 csekumar 5001 5 csechristy 4001 5 cseabirami 5003 5 it
SQL> insert into students values('abirami',5003,5,'cse');
SQL>select('The regno of '|| sname || ' is '|| sno) from tab1;
('THEREGNOOF'||SNAME||'IS'||SNO)---------------------------------------------------------------------The regno of anitha is 1The regno of guna is 3The regno of lavan is 4The regno of divesh is 6The regno of dinesh is 8The regno of vennila is 2The regno of man is 9
7 rows selected.
5) Miscellaneous functions
SQL> select uid from dual;
UID--------- 5
SQL> select user from dual;
USER------------------------------SYSTEM
SQL> select vsize('hello') from dual;
VSIZE('HELLO')-------------- 5
RESULT: Thus the various built in functions in SQL are studied and executed.
Ex. No: 6 GROUP FUNCTIOINS & SET OPERATIONS
AIM: To study the usage of various group functions & set operations.
PROCEDURE: Group function
A group function returns a result based on a group of rows.
The group functions arei) Avg functionii) Min functioniii) Max functioniv) Sum functionv) Count function
Set Operations Set operators combine the results of two queries into a single one.
The set operators arei) unionii) union alliii) intersect iv) minus
OUTPUT:
Group functions
SQL> select * from eemp;
ENAME SAL DEPT -------------- --------- ---------Remya 55000 it guna 60000 cseani 650000 ecelav 550000 csekan 40000 cseven 45000 it
SQL>select ename, sal from eemp where sal > all (select sal from eemp where dept = 'cse');
ENAME SAL---------- ----------ani 650000
SQL>
RESULT: Thus the usage of joins and sub queries are studied and executed.
Ex. No: 8 PL/SQL
AIM: To study the usage of Procedural Language/ SQL.
PROCEDURE:
PL/SQL extends SQL by adding control structures found in other procedural language. A PL/SQL block can be divided into three parts i) A declarative part ii) An executable part iii) An exception handling part Structure of PL/SQL block
DECLARE Declarations BEGIN Executable statements Exception Handlers END;
Control Structures i) if then ii) simple loop iii) while loop iv) for loop
OUTPUT
Simple Loop
SQL> declare a number:=100; begin loop a :=a+25; exit when a =250; dbms_output.put_line(a); end loop; end; SQL> / 125 150 175 200 225 PL/SQL procedure successfully completed.
While loop
SQL > declare a number:=100; begin while a < 250 loop a:=a+25; dbms_output.put_line(a); end loop; end;SQL> / 125 150 175 200 225 250
PL/SQL procedure successfully completed.
For Loop
SQL> declare a number:=100; begin for i in 1..5 loop a:=a+25; dbms_output.put_line(a); end loop; end;SQL> / 125 150 175 200 225
PL/SQL procedure successfully completed.
If then
SQL>declare a number:=100; begin if a > 100 then a := a - 50; else a := a+ 50; end if; dbms_output.put_line(a); end;SQL> / 150
PL/SQL procedure successfully completed.
RESULT: Thus the PL/SQL basics are studied and executed.
Ex. No: 9 PROCEDURE
AIM: To execute PL/ SQL procedure in SQL PLUS.
PROCEDURE:
A procedure is a subprogram that performs a specific action.
Syntax To create a procedure
create or replace procedure proc_name( arguments) is local declarations begin executable statements exception exception handler end;
To execute a procedure
SQL> exec proc_name(parameters);
OUTPUT:
SQL>create table store(icode varchar2(20),iname varchar2(20),iqty number,iprice number);Table Created ;
SQL> desc store; Name Null? Type ------------------------------- -------- ---- ICODE VARCHAR2(20) INAME VARCHAR2(20) IQTY NUMBER IPRICE NUMBER
1. INSERT PROCEDURE:
To Create procedure
SQL>ed v;
create or replace procedure iiadd(v1 varchar,v2 varchar,v3 number,v4 number) aspcode varchar(20);pname varchar(20);pqty number;pprice number;beginpcode :=v1;pname :=v2;pqty :=v3;pprice :=v4;insert into store values(pcode,pname,pqty,pprice);end;
SQL> @ v; 13 /
Procedure created.
To Execute procedure:
SQL> exec iiadd('p','book',10,100);
PL/SQL procedure successfully completed.
SQL> select * from store;
ICODE INAME IQTY IPRICE-------------------- -------------------- --------- ---------p book 10 100
SQL> ed p;create or replace procedure iidel(v1 varchar) aspcode varchar(20);beginpcode :=v1;delete from store where icode =pcode;dbms_output.put_line (‘record deleted’);end;SQL> @ p; 11 /
Procedure created.
Z
To Execute procedure:
SQL> exec iidel(‘c'); record deletedPL/SQL procedure successfully completed.
SQL> ed u;create or replace procedure iiup(v1 varchar,v2 number)aspcode varchar(20);price number ;prprice number;beginpcode :=v1;price :=v2;select price into prprice from store where icode=pcode;update store set iprice=prprice where icode=pcode;dbms_output.put_line('record updated successfully');
RESULT: Thus the PL/SQL procedure are studied and executed.
Ex. No: 10 FUNCTIONS
AIM: To execute PL/ SQL function in SQL PLUS.
PROCEDURE: A function is a subprogram that computes a value.
Syntax To create a function create or replace function func_name ( arguments) return datatype is local declarations begin executable statements exception exception handler end;
OUTPUT:
SQL> desc product; Name Null? Type ----------------------------------------- -------- --------------------------- PCODE VARCHAR2(5) PNAME VARCHAR2(10) QTY_HAND NUMBER(5) QTY_MIN NUMBER(5)
create or replace function reorder_func(code varchar)return number isreorderqty number;minqty number;handqty number;beginselect qty_hand,qty_min into handqty,minqty from product where pcode=code;if handqty < minqty thenreorderqty := minqty -handqty;return reorderqty;elsereorderqty := 0;return reorderqty;end if;end;
SQL> @ reorder; 17 /
Function created.
Executing the function:
SQL> declare a varchar(5); b number; begin a:=&a; b:=reorder_func(a); dbms_output.put_line('quantity to be ordered is' || b); end; /
Enter value for a: 'sg'old 5: a:=&a;new 5: a:='sg';quantity to be ordered is 0
PL/SQL procedure successfully completed.
SQL> /Enter value for a: 'rc'old 5: a:=&a;new 5: a:='rc';quantity to be ordered is 15
PL/SQL procedure successfully completed.
RESULT: Thus the PL/SQL functions are studied and executed.
Ex. No: 11 EMBEDDED SQL
Aim:To implement embedded SQL concept using JAVA as Front End and MS-Access
as Back End for Database Manipulation.
Procedure:
1. Create MS-Access table named employee with it’s as emp.
2. Create a data source by establishing JDBC/ODBC connection.
3. Develop a java application mainjdbc.java as
i) Create an object myjdbc mj= new myjdbc();
ii) In ,try catch block
* Declare methods for connection ,executing the query statement and record set.
Thus the embedded SQL concept using JAVA as Front End and MS-Access as Back End for Database Manipulation was executed.
Ex. No: 11 TRIGGERS
AIM: To write trigger program to maintain the inventory level.
PROCEDURE: A database trigger is stored procedure that is fixed when an insert, update, or delete statement is issued against the associated table.
Syntax for creating triggers Create or replace trigger trigger_name [before/after] [insert/update/delete] on table_name [for each statement/ for each row ] [ when condition] ;
EXNO:12 CURSORS
AIM:
To implement cursor for performing payroll processing
PROCEDURE:
1. Create the employee & attendance table with required fields.
2. Enter the values into the table.
3. Create a salary table into which the payroll process is to be
executed.
4. Declare a cursor to fetch values from employee table.
5. Select the workdays,months,years from attendance table for each
employee number in the employee table
6. Calculate the salary for each employee and insert it in the salary
beginopen emp;loopfetch emp into empno,empname,empsal,empgrade;exit when emp%notfound;select workdays,months,years into wd,m,y from attendence where eno = empno;netsalary :=(empsal/30) * wd;insert into salary1 values(empno,empname,empgrade,netsalary,wd,m,y);end loop;close emp;commit;end;
/
PL/SQL procedure successfully completed.
SQL> select * from employee;
ENO ENAME ESAL EGRADE ------- -------------- -------- ------------- 1 arun 5000 b 2 raju 6522 b 3 balu 10000 a
SQL> select * from attendence;
ENO WORKDAYS MONTHS YEARS --------- --------- --------- --------- 1 15 6 2 2 56 9 2 3 88 4 3
SQL> select * from salary;
ENO ENAME E NETSAL WORKDAYS MONTHS YEARS --------- - ------------ ------ - - --------- --------- -------- ---------- 1 arun b 7611 15 6 2 2 raju b 8524.2 56 9 2 3 balu a 133660.27 88 4 3
3 rows selected.
RESULT:
Thus the cursor is implemented to perform payroll process.
EXNO:13 TRIGGERS
AIM:
To write a Trigger program to maintain the inventory level.
PROCEDURE:
1. Create a stock table with required fields.
2. Create procedure for inserting values into the table.
3. Insert the values into the table.
4. Create procedure for updating the table.
5. Create a trigger point to catch the illegal entry.
SQL> create or replace trigger trr1 before update on prod6 for each row begin if :new.qtysales > :old.qtyhand then raise_application_error ( -20001,'quantity is less'); end if; end; /
SQL> Trigger created.
Update Procedure
SQL> ed t2;
create or replace procedure stock_update1(x1 varchar , x4 number) as tqty number(20); thand number(20); begin select qtyhand,qtysales into thand,tqty from prod6 where pcode = x1; if SQL%FOUND then update prod6 set qtyhand = thand - x4 where pcode = x1; update prod6 set qtysales = tqty + x4 where pcode = x1; dbms_output.put_line('record updated'); end if; end;
*ERROR at line 1:ORA-20001: quantity is lessORA-06512: at "SYSTEM.TRR1", line 3ORA-04088: error during execution of trigger 'SYSTEM.TRR1'ORA-06512: at "SYSTEM.STOCK_UPDATE1", line 8ORA-06512: at line 1
RESULT:
Thus trigger is implemented and executed for maintaining inventory Level.
EXNO: 14 EMBEDDED SQL
AIM:To implement Embedded SQL concept using JAVA as Front End and MS-Access
as Back End for Database Manipulation.
PROCEDURE:
1. Create MS-Access table named employee with it’s as emp.
2. Create a data source by establishing JDBC/ODBC connection.
3. Develop a java application mainjdbc.java as
i) Create an object myjdbc mj= new myjdbc();
ii) In ,try catch block
* Declare methods for connection ,executing the query statement and
record set.
* Established JDBC-ODBC connection (name,drivermanager).
*Call the query to be executed rs=st.executeQuery(“ select * from mployee” )
To design and implement a banking system using VisualBasic as Front End and
oracle as Back End.
PROCEDURE:
1. Create a database for banking with required fields using SQL.
2. Create forms in VB in required format.
3. Select adodc component and also appropriate control to the form wherever the
control is needed.
4. Write the appropriate coding for each form created in VB.
5. Run the forms for results.
SOURCE CODE FOR FORM1:
Private Sub ACCOUNT_Click()Form2.ShowEnd Sub
Private Sub exit_Click()Unload MeEnd Sub
Private Sub transcation_Click()Form3.ShowEnd Sub
SOURCE CODE FOR FORM2:
Private Sub INSERT_Click()Adodc1.Recordset.AddNewEnd Sub
Private Sub transa_Click()Form3.ShowEnd Sub
Private Sub UPDATE_Click()Adodc1.Recordset.updateMsgBox "record updated successfully"End Sub
Private Sub DELETE_Click()Adodc1.Recordset.deleteMsgBox "record Deleted"Adodc1.Recordset.MoveNextIf Adodc1.Recordset.EOF = True ThenAdodc1.Recordset.MovePrevious
End IfEnd Sub
Private Sub HOME_Click()Form1.ShowEnd Sub
Private Sub exit_Click()Unload MeEnd Sub
Private Sub clear_Click()Text1.Text = ""Text2.Text = ""Text3.Text = ""End Sub
SOURCE CODE FOR FORM3:
Private Sub DEPOSIT_Click()Dim s As Strings = InputBox("enter the amount to be deposited")Text2.Text = Val(Text2.Text) + Val(s)A = Text2.TextMsgBox "CURRENT BALANCE IS Rs." + Str(A)Adodc1.Recordset.UpdateEnd Sub
Private Sub WITHDRAW_Click()Dim s As Strings = InputBox("enter the amount to be deleted")Text2.Text = Val(Text2.Text) - Val(s)A = Text2.TextMsgBox "CURRENT BALANCE IS Rs." + Str(A)Adodc1.Recordset.UpdateEnd Sub
Private Sub ACCOUNT_Click()Form2.ShowEnd Sub
Private Sub HOME_Click()
Form1.ShowEnd Sub
Private Sub clear_Click()Text1.Text = ""Text2.Text = ""End Sub
Private Sub exit_Click()Unload MeEnd Sub
SCREEN SHOTS:
FORM 1[HOME PAGE]
FORM 2:[ACCOUNT DETAILS]
FORM 3: [Transaction –Deposit]
FORM 3:[Transaction after deposit]
RESULT:
Thus Bank Management system is designed and implemented successfullly
EXNO: 16 PAYROLL PROCESSING SYSTEM
AIM:To design and implement a Payroll Processing System using VisualBasic as Front
End and oracle as Back End.
PROCEDURE:
1. Create a database for payroll processing with required fields using SQL.
2. Create forms in VB in required format.
3. Select adodc component and also appropriate control to the form wherever the
control is needed.
4. Write the appropriate coding for each form created in VB.
5. Run the forms for results.
SOURCE CODE FOR FORM 1:
Private Sub emp_Click()Form2.ShowEnd Sub
Private Sub Exit_Click()Unload MeEnd Sub
Private Sub salary_Click()Form3.ShowEnd Sub
SOURCE CODE FOR FORM 2:
Private Sub add_Click()Adodc1.Recordset.AddNewMsgBox "record added"End Sub
Private Sub clear_Click()Text1.Text = " "Text2.Text = " "Text3.Text = " "Text4.Text = " "Text5.Text = " "End Sub
Private Sub delete_Click()
Adodc1.Recordset.deleteMsgBox "record deleted"Adodc1.Recordset.MoveNextIf Adodc1.Recordset.EOF = True ThenAdodc1.Recordset.MovePreviousEnd If End Sub
Private Sub Exit_Click()Unload MeEnd Sub
Private Sub main_Click()Form1.ShowEnd Sub
Private Sub modify_Click()Adodc1.Recordset.UpdateEnd Sub
SOURCE CODE FOR FORM 3:
Private Sub calc_Click()Dim g, n As Doubleg = (Val(Text2.Text) + Val(Text2.Text) * (Val(Text3.Text) / 100) + Val(Text2.Text) * (Val(Text5.Text) / 100))Text8.Text = gn = g - (Val(Text5.Text) + Val(Text6.Text))Text7.Text = nAdodc1.Recordset.UpdateMsgBox " NET SALARY IS" + Str(n)End Sub