1.

DATA DEFINITION, TABLE CREATION, CONSTRAINTS

AIM:  CREATE objects like CREATE TABLE, CREATE FUNCTION, CREATE SYNONYM, CREATE VIEW. Etc.  ALTER Objects like ALTER TABLE, ALTER USER, ALTER TABLESPACE, and ALTER DATABASE. Etc.  DROP Objects like DROP TABLE, DROP USER, DROP TABLESPACE, and DROP FUNCTION. Etc.  TRUNCATE (delete all rows) a table.

Create: To create tables, views, synonyms, sequences, functions, procedures, packages etc. To create tables: Purpose: Syntax: Create table <table_name>(“column1” “DataType for column1”,”column2” “DataType for Column2”,..); Example: create table emp (empno number(5) , name varchar2(20), sal number(10,2), job varchar2(20), comm number(10,2)); Output:Table Created. This query is used to create a table.

1

To create view: Purpose: Views can be considered as virtual tables. A table has a set of definition, and it physically stores the data. A view also has a set of definitions, which is build on top of table(s) or other view(s),and it does not physically store the data. Syntax: Create view <view name> AS <SQL Statement> Example: CREATE VIEW V_emp As SELECT * FROM EMP; Output: View created.

SQL> select * from V_emp; EMPNO NAME SAL JOB COMM ---------------------------------------------------------------------------------11 xxx 15000 SE 2258965 22 yyy 20000 DE 2245689 To create Primary Key :Purpose: A primary key is used to identify each row in a table. When describe that table, it shows NOT NULL value in NULL column. Syntax : Create table <table_name>(“column1” “DataType for column1” ”PRIMARY KEY”,”column2” “DataType for Column2”,..); Example: create table emp (empno number(5) primary key, name varchar2(20), sal number(10,2), job varchar2(20), comm number(10,2)); Output: Desc emp;

2

Name

Null?

Type

--------------------------------------------------------------EMPNO NAME SAL JOB COMM NOT NULL NUMBER(5) VARCHAR2(20) NUMBER(10,2) VARCHAR2(20) NUMBER(10,2)

CREATE FOREIGN KEY: Purpose: A foreign key is a field (or fields) that points to the primary key of another table. Syntax :

Create table <table_name>(“column1” “DataType for column1” REFERENCES <table_name>(primary_key_column), (“column2” “DataType for column2”,etc.,);

Example: create table dept (deptno number(5) primary key, dept_name varchar2(20), employeeno number(5) references emp(empno));

Output: SQL> create table dept(deptno number(5) primary key,dept_name varchar2(20), employeeno number(5) references emp(empno)); Table created.

3

SQL> desc dept; Name Null? Type

---------------------------------------------------------------DEPTNO DEPT_NAME EMPLOYEENO NOT NULL NUMBER(5) VARCHAR2(20) NUMBER(5)

CREATE DEFAULT : Purpose: The DEFAULT constraint is used to insert a default value into a column. Syntax : Create table <table_name>(“column1” “Data Type for column1”, (“column2” “Data Type for column2”default(‘name’),etc.,);

Example: create table dept_defalt (deptno number(5) primary key, dept_name varchar2(20) default(‘IT’)); Output: SQL> insert into dept_defalt (deptno) values(11); 1 row created. SQL> insert into dept_defalt (deptno) values(12); 1 row created. SQL> insert into dept_defalt (deptno,dept_name) values(13,’MCA’); 1 row created.

4

SQL> select * from dept_defalt; DEPTNO DEPT_NAME ---------------------------------11 12 13 ALTER:Purpose: Once a table is created in the database ,there are many occasions where one may wish to change the structure of the table. Typical cases include the following: • • Add a column Modify the datatype for a column IT IT MCA

ALTER Table – Add a column : Purpose: To add a new column to this table. Syntax : Alter table <table_name> add(“column1” “Data Type for column1”, (“column2” “Data Type for column2”,etc.,); Example: Alter table emp add(address varchar2(20)); Output: SQL> Alter table emp add(address varchar2(20)); Table altered. SQL> Desc emp;

5

Table dropped. Result : Thus the DDL program has been successfully executed and verified. attributes and indexes will also be deleted). Output: SQL> drop table dept2.2) VARCHAR2(20) DROP: Purpose: To delete a table ( the table structure.2) VARCHAR2(20) NUMBER(10. 6 . Syntax : Drop table <table_name> Example: Drop table dept_defalt.Name Null? Type --------------------------------------------------------------EMPNO NAME SAL JOB COMM ADDRESS NOT NULL NUMBER(5) VARCHAR2(20) NUMBER(10.

SQL> insert into dept values(12. b.1101).SELECT : Purpose: The SELECT allows database users to retrieve the specific information from the table. 1 row created. Syntax: Insert into <table name> values(value list).2 . 1 row created.’IT’.1101). Example: Insert into dept values(11.’IT’. INSERT. UPDATE & DELETE COMMANDS AIM: The Data Manipulation Language (DML) is used to retrieve. Syntax:  To retrieve all attributes from the particular table.1101).INSERT : Purpose: The INSERT command in SQL is used to add records to an existing table.’IT’. DEPTNO DEPT_NAME EMPLOYEENO -------------------------------------------------------------14 15 IT IT 1101 1102 7 . select * from <table name>. insert and modify database information. a. SQL> select * from dept. SELECT COMMANDS. Output: SQL> insert into dept values(11.

DEPTNO DEPT_NAME -----------------------------------16 17 c.INSERT using Null Values : It is used to inserting the null values by creating the table itself.’1103'). SQL> select deptno. Syntax: Insert into <table name> values(NULL. Output: 1 row created. Example: SQL> insert into dept(deptno. To retrieve selected attributes from the particular table.deptname from dept.UPDATE : Purpose: The update statement used to modify the data in a table.null.EmployeeNo) values(15.NULL).dept_name. SQL> select * from dept. DEPTNO DEPT_NAME EMPLOYEENO IT IT -------------------------------------------------------------18 19 20 d. IT IT 1101 1102 1103 Syntax: 8 .

Output: SQL> Update dept set dept_name=’CSE’ where deptno=’13’. Example: Delete from emp where deptno=’13’. 1 row deleted. 9 . 1 row updated.DELETE: Purpose: The DELETE command with a WHERE clause can be used to remove his record from the personal_info table.… [where <condition>]]. SQL> select * from dept. SQL> select * from dept. Syntax: Delete from <table name> [where <condition>]]. Output: SQL> delete from emp where deptno=’13’.Update <table name> set <column name>=[expression. DEPTNO DEPT_NAME EMPLOYEENO ---------------------------------------------------------------13 14 15 CSE IT 1101 1102 1103 e. Example: Update dept set dept_name=’CSE’ where deptno=’13’.

Output: SQL> select * from dept where Dept_name=’IT’. a where clause can be added to the SELECT statement. Example: select name from dept where Dept_name=’IT’. Syntax: select <column name> from <table name> [ where <condition>]. 10 IT CSE IT 1102 1103 1104 . DEPTNO DEPT_NAME EMPLOYEENO ---------------------------------------------------------------14 15 16 Select using Order by: Purpose: Order by used to select the statement in order of that particular column. Syntax: Select <column name> from <table name> order by <column name>. SELECT with Constraints: Select using WHERE clause: Purpose: To conditionally select data from a table.DEPTNO DEPT_NAME EMPLOYEENO ---------------------------------------------------------------14 15 IT 1103 1102 f.

DEPTNO DEPT_NAME ----------------------------------15 14 16 CSE IT IT Select using Order by Descending: SQL> select deptno. DEPTNO DEPT_NAME ----------------------------------14 16 IT IT 11 . DEPTNO DEPT_NAME ----------------------------------15 14 16 CSE IT IT Select using Order by Ascending : SQL> select deptno. dept_name from dept order by dept_name desc. dept_name from dept order by dept_name asc. dept_name from dept order by dept_name. Output: SQL> select deptno.Example: SQL> select * from dept order by deptno.

The expected output should return only those strings that actually contain these character(s) at the specified places and not make use of the “special meaning” attached to them. Syntax: Select * from <table name> where <column name> like ‘<char>%’ SQL> select * from dept where dept_name like ‘%s%’. 12 . • % allows matching any string of any length (including zero length) • _ allows matching a single character  start with search using an input/search string containing % or _. These two wild card characters are used with LIKE operator. DEPTNO DEPT_NAME ----------------------------------15 CSE Result: Thus the DML program has been successfully executed and verified.15 CSE Select using LIKE operator : Purpose: % (percentage) and _ (underscore) have a special meaning.

3 . Syntax of Nested Query: SELECT <column name> from <table name> where <condition> (any query for select/update/insert/delete). MAX QTY ITEMAMT ---------. Nested Query: SQL nested query is SELECT Query that is nested inside a Select. Insert or Delete query. Update.---------.---------40 34 56 SQL> select * from itemfile where qty>all(select qty from itemfile1 where max=40). Example of Nested Queries: SQL> select * from itemfile where qty=(select qty from itemfile1 where max=40).---------50 90 70 SQL> select * from itemfile where qty=(select qty from itemfile1 where max=40) or itemamt in(select itemamt from itemfile).---------100 200 300 50 90 70 40 34 56 13 .---------.---------. MAX QTY ITEMAMT ---------. NESTED QUERIES & JOIN QUERIES AIM: To write nested queries and join queries operations in the tables. MAX QTY ITEMAMT ---------.

for which the join condition evaluates to TRUE.---------300 200 300 300 200 300 40 34 56 14 . or materialized views. Output: MAX QTY ITEMAMT ---------. Oracle combines pairs of rows.Such a condition is called a join condition. If any two of these tables have a column name in common.Join Query :     A join is a query that combines rows from two or more tables.---------. The columns in the join conditions need not also appear in the select list. Join Conditions :  Most join queries contain WHERE clause conditions that compare two columns. each containing one row from each table. query's FROM clause. Output: MAX QTY ITEMAMT ---------. each from a different table. views.---------.---------100 200 300 50 90 70 40 34 56 SQL> select * from itemfile1.  To execute a join. Oracle performs a join whenever multiple tables appear in the The query's select list can select any columns from any of these tables. you must qualify all references to these columns throughout the query with table names to avoid ambiguity. Example of Join Queries: SQL> select * from itemfile.

max from itemfile. For all rows in A that have 15 . Output: QTY MAX ---------.---------90 300 34 300 90 300 34 300 90 40 Outer join: An outer join extends the result of a simple join.max=itemfile1.Equi Join :  An equijoin is a join with a join condition containing an equality operator ( = ).max from itemfile.qty.max. or apply the outer join operator (+) to all columns of B in the join condition. An equijoin combines rows that have equivalent values for the specified columns.max.max>itemfile1.qty. An outer join returns all rows that satisfy the join condition and also returns some or all of those rows from one table for which no rows from the other satisfy the join condition.itemfile1. SQL> select itemfile. • To write a query that performs an outer join of tables A and B and returns all rows from A (a left outer join). use the ANSI LEFT[OUTER] JOIN syntax. SQL> select itemfile.itemfile1 where itemfile. Output: QTY MAX ---------.itemfile1 where itemfile.---------34 40 Non-Equi join:  Non equi joins is used to return result from two or more tables where exact join is not possible.itemfile1.

Oracle returns null for any select list expressions containing columns of B. extended with nulls if they do not satisfy the join condition (a full outer join). use the ANSI RIGHT[OUTER] syntax. To write a query that performs an outer join and and returns all rows from A and B. For all rows in B that have no matching rows in A.itemfile1. Output: QTY MAX ---------. Oracle returns null for any select list expressions containing columns of A. • To write a query that performs an outer join of tables A and B and returns all rows from B (a right outer join).max from itemfile.max(+). • SQL> select itemfile.qty.itemfile1 where itemfile. or apply the outer join operator (+) to all columns of A in the join condition.no matching rows in B.max=itemfile1. Output: 16 .---------200 34 40 90 Union: SQL> select *from itemfile union select *from itemfile1. use the ANSI FULL [OUTER] JOIN syntax.---------100 200 300 300 200 300 40 34 56 50 90 70 Union All: SQL> select * from itemfile union all select * from itemfile1.---------. Output: MAX QTY ITEMAMT ---------.

---------100 200 300 50 90 70 40 34 56 300 200 300 300 200 300 40 34 56 6 rows selected.MAX QTY ITEMAMT ---------. Intersection: SQL> select * from itemfile intersect select * from itemfile1. Output: MAX QTY ITEMAMT ---------. 17 .---------100 200 300 50 90 70 Result: Thus the Nested and Join Queries has been successfully executed and verified.---------. Output: MAX QTY ITEMAMT ---------.---------.---------.---------40 34 56 Minus: SQL> select * from itemfile minus select * from itemfile1.

Output: 18 . A view also has a set of definitions.and it does not physically store the data. A table has a set of definition. Purpose: Views can be considered as virtual tables. Output: View created. EMPNO NAME SAL JOB COMM -------------------------------------------------------------------------11 xxx 15000 SE 2258965 22 yyy 20000 DE 2245689 Example: CREATE VIEW V_ Singlecol As SELECT empno FROM EMP.4. and it physically stores the data.VIEWS AIM: To create a view for whole table or partial data in that table. Syntax: Create view <view name> AS <SQL Statement> Example: CREATE VIEW V_emp As SELECT * FROM EMP. SQL> select * from V_emp. which is build on top of table(s) or other view(s).

View created. SQL> select * from V_colEmp. EMPNO -----------11 22 Example: CREATE VIEW V_colEmp As SELECT empno. SQL> select * from V_ Singlecol. EMPNO NAME SAL -------------------------------------11 xxx 15000 22 yyy 20000 Result: Thus the view creation program has been successfully executed and verified.sal FROM EMP. Output: View created. 19 .name.

The value of the parameter can not be overwritten by the procedure or function. In general. more specific pieces of code. HIGH LEVEL PROGRAMMING LANGUAGE EXTENSIONS (CONTROL STRUCTURES. IN . When you create a procedure or function. Procedures: The procedure is a program that performs an action and does not return a value (outside of IN OUT and OUT parameters). IN OUT . 4. but the value of the parameter can be overwritten by the procedure or function. you may define parameters.The parameter can not be referenced by the procedure or function.The parameter can be referenced by the procedure or function and the value of the parameter can be overwritten by the procedure or function. OUT . Functions: The function is a program that might perform an action and does return a value. PROCEDURES AND FUNCTIONS) AIM : To write programs a High Level Language extensions with stored procedures and functions in PL/SQL statements. if you need to update the chart of 20 . 2. 3.5 . There are three types of parameters that can be declared: 1.The parameter can be referenced by the procedure or function.  Parameters are declared when a procedure or function are declared and are declared between an open and a close parenthesis (()). Parameters are optional on both procedures and functions.  Named PL/SQL programs (procedures and functions) can take parameters. Parameters are named variables that are available to a program and that modify program behavior and/or data. Procedures VS Functions: Procedures are traditionally the workhorse of the coding world and functions are traditionally the smaller.

balance in number) 21 . A few more differences between a procedure and a function: • • • A function MUST return a value. you would write a procedure.parameter]) ] AS //Variable declaration BEGIN //Executable Section [EXCEPTION exception_section] END. / Procedure/Stored Procedure Example: SQL> set serveroutput on. you would write a function. Functions are considered expressions. If you need to retrieve the organization code for a particular GL account. SQL> create or replace procedure addacc(acc_id in varchar2. procedure cannot.accounts. A procedure cannot return a value. Functions can be called from SQL. The return statement of a procedure returns control to the calling program and cannot return a value. • • • • Procedure/Stored Procedure Syntax: CREATE OR REPLACE PROCEDURE procedure_name[(parameter [.name in varchar2. (or) END procedure_name. The return statement in a function returns control to the calling program and returns the results of the function. procedure are not. Procedures and functions can both return data in OUT and IN OUT Parameters.

SQL> select *from accoun111. Procedure to update the balance when greater than 2500 SQL> create or replace procedure updacc(accno varchar2) 2 as 3 bal number(20).2 as 3 begin 4 insert into accoun111 values(acc_id.balance). 6 end addacc. 4 begin 5 select balance into bal from account111 where acc_id=accno. ACC_ID NAME BALANCE -------------------.--------a001 nipa 5000 a002 rani 3000 a003 priya 4000 a005 karti 6000 2. 9 else 10 dbms_output.'karti'.put_line('balance updated'). 11 end if. 8 dbms_output.6000). SQL> exec addacc('a005'. value added PL/SQL procedure successfully completed. 12 exception when no_data_found then 22 .name.put_line('value added'). 7 / Output: Procedure created.-------------------. 6 if bal>=2500 then 7 update account111 set balance=balance-2000 where acc_id=accno.put_line('Updated amount below account limit'). 5 dbms_output.

---------.13 dbms_output. ACC_ID a0001 a0002 a0003 NAME maha praveen anand BALANCE 3000 1000 2000 ---------.put_line('No such data found'). 23 . 14 end. ACC_ID a0001 a0002 a0003 NAME maha praveen anand BALANCE 3000 1000 4000 ---------. balance updated PL/SQL procedure successfully completed. SQL> select * from account111.---------.--------- SQL> exec updacc('a0003').--------- Function Syntax : CREATE OR REPLACE FUNCTION <function_name> RETURN <variable_type> IS | AS <variable declarations> BEGIN <code_here>. 15 / Output: Procedure created. SQL> select * from account111.

ACC_ID a0001 a0002 a0003 a0004 a0005 a0006 a0007 a0008 NAME rani radha ravi dhana praveena aaaa bbbb cccc BALANCE 100 200 600 300 400 100 100 100 ---------.END <function_name>. 5 RETURN cus_name. 7 / Output: 24 .name%type. 3 begin 4 select name into cus_name from account11 where acc_id=id.---------. SQL> create or replace function f1(id in varchar2) RETURN varchar2 IS 2 cus_name account11.--------- Function Example: SQL> set serveroutput on. / Sample table(account11) data: SQL> select * from account11. 6 end.

8 dbms_output. 11 end. 4 begin 5 no:='&account_id'.put_line('no such account id exists'). new 5: no:='a0009'. no such account id exists PL/SQL procedure successfully completed.name%type. 6 name:=f1(no). new 5: no:='a0001'.put_line('account number:'||no).Function created. 9 exception when no_data_found then 10 dbms_output. 3 name account11.acc_id%type. account number:a0001 customer name:rani PL/SQL procedure successfully completed. 25 .put_line('customer name:'||name). SQL> / Enter value for account_id: a0009 old 5: no:='&account_id'. 12 / Output: Enter value for account_id: a0001 old 5: no:='&account_id'. SQL> declare 2 no account11. 7 dbms_output.

user name and server name. 4. Form1 Employee Payroll 3.Select administrative tools option from control panel.Result: Thus the High Level Programming Language Extension has been successfully executed and verified.Basicpay and insert some record into the database. Forms & Menu Design ) AIM: To develop an employee payroll system using Oracle as a back end (database) and Microsoft Visual Basic6.Delete. 26 .Searching. Then click on Data Source(ODBC). 2.Modify and Exit.text boxes and command buttons. b. DESIGN AND IMPLEMENTATION OF PAYROLL PROCESSING SYSTEM ( Front End Tools . Design the corresponding form with labels. PROCEDURE: 1.Give a suitable data source name. Create the back with the front end using DAO method by creating a DSN as follows.which displays a dialog box named ODBC DATASOURCES ADMINISTRATOR in which click Add button. Create a employee database with the following fields in oracle namely Empno. c. Calculate the net salary of the employee.In Create New Data Source dialog box.Empname. a.0 as a front end. 5.select “Microsoft ODBC for ORACLE” and click finish button .address. Perform the required operations like Insert. 6.

Fields(10) TD.Fields(9) ADV.Fields(12) NP.Fields(13) End Sub PROGRAM TO VIEW: 27 .Recordset. TABLE DESIGN: Table Name :Employee NAME EMPNO EMPNAME DESIGNATION DA HRA ADDRESS TA PF BASICPAY TYPE NUMBER(6) VARCHAR2(30) VARCHAR2(20) NUMBER(10) NUMBER(10) VARCHAR2(20) NUMBER(10) NUMBER(10) NUMBER(8.Recordset.6.Text= adodc1.Recordset.Fields(11) GP.Text=adodc1.Text=adodc1.Text=adodc1. Execute the project.Recordset.2) LOAN.Text=adodc1.Recordset.

Enabled=False PF.Recordset.Recordset.Enabled=False GP.MOVEPREVIOUS End Sub PROGRAM TO SAVE: Private sub save_Click() Adodc1.Recordset. Recordset.Private sub view_Click() Dim a As Integer On Error Go To err a=InputBox(“enter the empno”) Adodc1.MOVEFIRST While Not Adodc1.MOVENEXT Wend err: MsgBox(“record doesnot exist”) End Sub Private sub MOVENEXT_Click() Adodc1.Enabled=False TD.Enabled=False LOAN.Enabled=False NO.Recordset.Enabled=False DESIG.Update NAME1.Enabled=False 28 .Enabled=False ADV.MOVENEXT End Sub Private sub MOVEPREVIOUS_Click() Adodc1.Enabled=False HRA.Enabled=False B1.Recordset.Enabled=False DA.Recordset.Enabled=False OA.EOF If Adodc1.Fields(0)=a Then fillt 1 Exit Sub End If Adodc1.Enabled=False TA.

Recordset.Text= adodc1.Enabled= True NO.Enabled= True HRA.Recordset.Enabled= True NP.Recordset.Fields(7) PF.Enabled= True B1. Enabled=False del.Recordset.Text=adodc1.Fields(2) MONYH.Enabled= True PF.Enabled=False 29 .Text=adodc1.Text=adodc1.Text=adodc1.Fields(0) NAME.Enabled= True DESIG.Fields(9) ADV.Enabled=True End Sub Fill function Public sub fillt() NO.Recordset.Recordset.Text=adodc1. Enabled=True NO.Text=adodc1.Fields(4) HRA.Fields(10) PROGRAM TO ADD: Private sub add_Click() NAME1.Enabled= True del.Enabled= True GP.Enabled= True LOAN.SetFocus MsgBox”new record is added” add.Enabled= True save.Recordset.Enabled= True TD.Recordset.Text= adodc1.Recordset.Fields(8) LOAN.Recordset.Enabled= True edit.Text=adodc1.Enabled= True TA.Enabled= True ADV.Enabled= True BASIC.Fields(3) DA.NP.Enabled=False add.Text=adodc1.Text= adodc1.Fields(14) B1.Fields(5) OA.Enabled= True DA.Fields(6) TA.Fields(1) DESIG.Recordset.Text=adodc1.Recordset.Enabled= True OA.

Text)<5000 Then DA.Text=Val(B1)*(5/100) Else DA.Text=Val(B1)*(5/100) End If End Sub Dim a As Integer a=InputBox(“enter the empno”) Adodc1.MOVENEXT Wend MsgBox”record modify successfully” add.Text=Val(B1)*(25/100) HRA. Enabled=False End Sub PROGRAM TO CALCULATE ALLOWANCES: Private sub B1_LostFocus() If Val(B1.MOVEFIRST While Not Adodc1.Text= Val(B1)*(15/100) TA.Enabled=False BASIC.Text=Val(B1)+Val(HRA)+Val(OA) PF.Fields(0)=a Then Fillt Exit Sub End If Adodc1.Text=Val(B1)*(20/100) HRA.Text= Val(B1)*(10/100) TA.Recordset.Enabled=False del.Recordset.Text=Val(DA)+Val(HRA)+Val(OA) PF.Text= Val(B1)*(15/100) OA. Enabled=False End Sub Private Sub exit_Click() Unload Me End Sub Private sub Form_Click() 30 .Recordset.EOF If Adodc1.Recordset.BASIC. Enabled=False edit.Text= Val(B1)*(20/100) OA. Enabled=False edit.

Enabled= False OA.Enabled= False HRA.MOVEFIRST While Not Adodc1.Recordset.Recordset.Enabled= False ADV.Recordset.Enabled= False TD.MOVELAST End Sub PROGRAM TO DELETE: Private Sub del_Click() Form.Enabled= False DESIG.Enabled= False NO.Recordset.Enabled= False GP.Delete Exit Sub End If Adodc1.MOVENEXT Wend MsgBox”record deleted” err: MsgBox”record does not exists” End Sub Private sub edit_Click() Form1.Enabled= False NP.NAME1.Recordset.Recordset.Recordset.Caption=”delete operation” Dim a As Integer On Error Go To err a=InputBox(“enter the empno”) Adodc1.Enabled= False TA.Enabled= False DA.EOF If Adodc1.Enabled= False save.MOVEFIRST End Sub Private sub MOVELAST_Click() Adodc1. Enabled=True End Sub Private sub MOVEFIRST_Click() Adodc1.Caption=”modify operation” 31 .Enabled= False B1.Fields(0)=a Then Adodc1.Enabled= False LOAN.Enabled= False PF.

Enabled= True save.Enabled=True NO.Enabled= True PF.Enabled= True TD.Enabled= True DESIG.SetFocus OUTPUT: 32 .Enabled= True ADV. Enabled=True NO.Enabled= True B1.Enabled= True OA.Recordset.Enabled= True NP.Enabled= True HRA.Enabled= True DA.Adodc1.Enabled= True GP.Enabled= True LOAN.Enabled= True TA.Update NAME1.

RESULT: Thus the employee payroll processing system has been successfully developed and verified. 33 .TRIGGERS AIM: To write programs in High Level Language extension with triggers. 7.

Triggering Action:  Before Option : Fires the trigger only once. 1 .before executing the triggering statement.Parts of Data Base Trigger: a. c.  Instead of Option: Fires the trigger only once. b. Syntax: Create or replace trigger <trigger name> Before | After Insert | Delete | Update [of <column>] ON <table name> } -> Triggering event [Referencing [old as <old>] [New as <new>]] } ->Trigger constraint Begin PL/SQL Block  Trigger body ( Trigger Action) End. Triggering Event Triggering constraint ( Optional ) Triggering Action  After Option: Fires the trigger only once . to do something else instead of performing the action that executed the trigger. SQL> create or replace trigger tro11 2 after update or insert or delete on acco111 3 for each row 4 begin 34 . Create trigger to display the message after the data insert / delete/ update operation SQL> set serveroutput on.after the execution of the triggering statement.

Inserting 1 row created. Create trigger to display the message after the data insert / delete operation SQL> set serveroutput on.2300). 7 else 8 dbms_output.’john’. 10 end.put_line(‘Deleting’). 2 .put_line(‘Updating’).5 if updating then 6 dbms_output. SQL> create or replace trigger mytrig11 2 before insert or delete or update on account11 3 for each row 4 begin 5 if to_char(sysdate.'dy')='sun'then 6 dbms_output. 9 end if. SQL> insert into acco111 values(22. 12 end.put_line(‘Inserting’). 7 elsif inserting then 8 dbms_output. 13 / Output: Trigger created. 11 end if.put_line('welcome back').put_line('today is holiday'). 11 / Output: 35 . 9 elsif deleting then 10 dbms_output.

welcome back 1 row updated. 3. 8 end. 9 / Output: Trigger created. 5 end trig4. 7 end if. Create trigger with referencing new as newrow values swapped in another table SQL> create trigger trig4 after insert on t4 referencing new as newrow 2 for each row when(newrow.balance<100 then 6 raise_application_error(-20001.'LOW BALANCE'). line 3 ORA-04088: error during execution of trigger 'SCOTT.T112' 4. update account11 set balance='90' where name='aaaa' * ERROR at line 1: ORA-20001: LOW BALANCE ORA-06512: at "SCOTT.T112".Trigger created. SQL> update account11 set balance=100 where balance=500. 6 / Output: Trigger created. 36 .a>10) 3 begin 4 insert into t5 values(:newrow.a). Trigger to create error message when balance becomes less than 2000 SQL> create or replace trigger t112 2 before update on account11 3 for each row 4 begin 5 if:new.:newrow. SQL> update account11 set balance='90' where name='aaaa'.b.

c ity varchar2(20). SQL> select * from t4.4). A B ---------.nagar ch-24 243563 c002 praveen mgr nagar ch-43 236534 c003 hema nehru street ch-93 295123 37 . C D ---------.-------------------.--------16 12 SQL> select * from t4.--------2 4 12 16 CREATE TRIGGER TO DELETE ACCOUNT DETAILS WHEN CUSTOMER GETS DELETED SQL> create table custdet(c_id varchar2(10) primary key.ph_no number(12)). A B ---------. SQL> select * from custdet.16).street_name varchar2(20). 1 row created. 1 row created.SQL> insert into t4 values(2. SQL> select * from t5. Table created. C_ID NAME STREET_NAME CITY PH_NO ---------------------------------.-------------------c001 dhana k.name varchar2(20).-------------------.k.--------2 4 SQL> insert into t4 values(12.

--------c001 dhana k. 6 end.-------------------. SQL> select * from custdet. 7 / Output: Trigger created.c_id=:old.---------. ACC_ID C_ID BALANCE ---------.k.nagar ch-24 243563 c003 hema nehru street ch-93 295123 1 row deleted. SQL> delete from custdet where c_id='c002'.c_id. C_ID NAME STREET_NAME CITY ---------.-------------------.--------a0002 c001 4000 6 . SQL> select * from acco111.'c002'. 1 row created. 1 row created. 1 row deleted. TRIGGER TO INSERT INTO SEPARATE TABLES.4000).'c001'.-------------------. SQL> insert into acco111 values('a0003'. PH_NO 38 .SQL> insert into acco111 values('a0002'. SQL> set serveroutput on. SQL> create or replace trigger tig112 2 after delete on custdet 3 for each row 4 begin 5 delete from acco111 where acco111.5000).

balance number(10). SQL> select * from acco111.deldate date).acc_id.acc_id.insertdate date).deldate) values(:old.c_id. 9 end if. SQL> create or replace trigger tro11 2 after delete or insert on acco111 3 for each row 4 begin 5 if deleting then 6 insert into acco_del111(acc_id.c_id varchar2(20).c_id varchar2(20).sysdate).balance.insertdate) Values(:new. Table created.SQL> create table acco_del111(acc_id varchar2(20).balance number(10).---------.:new. 12 / Output: Trigger created.c_id.balance. ACC_ID C_ID BALANCE ---------. Program: SQL> set serveroutput on.c_id. SQL> create table acco_ins111(acc_id varchar2(20).c_id.balance.balance.--------- 39 .:new.:old. 7 elsif inserting then 8 insert into acco_ins111(acc_id.:old.sysdate). Table created. 11 end.

SQL> select * from acco_del111.--------- SQL> delete from acco111 where acc_id='a0002'.'c003'.-------------------. 1 row created. 8.a0002 a0003 c001 c002 4000 4500 SQL> insert into acco111 values('a0004'.-------------------. REPORTS 40 .3000). ACC_ID a0004 C_ID c003 BALANCE INSERTDAT 3000 09-MAR-10 -------------------.--------- Result : Thus the Triggers has been successfully executed and verified.--------.--------. ACC_ID a0002 C_ID c001 BALANCE DELDATE 4000 09-MAR-10 -------------------. 1 row deleted. SQL> select * from acco_ins111.

BTITLE : Sets the bottom title for each page of a report.calculate sub tools SETLINESIZE : Set the maximum number of lines per page. BREAKON : Tells the sql plus how the transactions for each kind of job are grouped together under any field. SETNEWPAGE : Set the number of blank lines between pages. Commands : Remark : • • Tells SQL plus that the cords to follow are to be treated as comments & not instructions. PROGRAM: 41 . • • • • TTITLE : Sets the top title for each page of a report. SPOOL : Moves a report you would normally displayed on the screen into a file. SETHEADSEP : The Heading separator identifies the single character that tells sql plus to split into one or more lines.AIM: To generate the REPORT using SQL commands. • • • • COMPUTESUM : Makes sql plus . COLUMN : Gives sql plus a variety of instructions on the heading format and treatment of a column.

99 compute sum of amount1 on amount break on storename skip 2 set linesize 82 set pagesize 60 set newpage 0 Output: 42 .SQL> desc aa1.99 column action_da heading ‘date’ column quanty heading ‘quantity’ format 999 column amount1 format 9999.-------. Name Null? Type ------------------------------.---ACTION_DATE DATE NAME VARCHAR2(20) QUANTY NUMBER(10) STORENAME VARCHAR2(20) RATE NUMBER(10) AMOUNT NUMBER(10) SQL> rem REPORT CREATED BY HARRY rem description : report for news paper set headsep| ttitle report about the news papers in India column name heading ‘What was sold’ column name format a18 column storename heading ‘to whom sold’ format a18 word_wrapped column rate format 90.

SQL> select * from aa1. 9. MINI PROJECT(1) 43 .00 200 08-FEB-10 08-MAR-10 Economic Times GlobalNews 400 500 LogStores BloggStore 6. Report about the news papers in India ACTION_DA What was sold quantity to whom sold RATE AMOUNT ------------------------------------------------------------------------------------------------07-JAN-10 The Hindu 370 HifiStore 8.00 10.00 600 100 RESULT : Thus the report has been successfully created and verified.

Searching and Exit.address.balance and some record into the database. Form1 customer details Form2 withdraw Form3 deposit 3. PROCEDURE : 1. Create the back with the front end using DAO method by creating a dsn as follows a. 5. b.acno.Give a suitable data source name. Issue the books according to the no.user name and server name. Create a banking database with the following fields namely.of copies available. 4. Perform the required operations like Insert. Execute the project.0 as a front end.name.text boxes and command buttons.DESIGN AND IMPLEMENTATION OF BANKING SYSTEM AIM: To develop a banking system using Oracle as s back end(data base) and Microsoft Visual basic6.select “Microsoft ODBC for ORACLE” and click finish button c. TABLE DESIGN: 44 .which displays a dialog box named ODBCDATASOURCESADMINISTRATOR in which click Add button.Select administrative tools option from control panel. Then click on data source(ODBC).Delete. in oracle 2. Design the corresponding form with labels. 5.In Create New Data Source dialog box.

text=RS(1) Text3.text=”” Text3.MoveNext IfRS.PWD= .2) FORM 1: Dim DB As Database Dim RS As recordset Private Sub Form_Load() Set DB =OpenDatabase(“BANKDSN”.text=RS(0) Text2.”) 45 .text=RS(1) Text3.text=RS(0) Text2.”ODBC.text=RS(3) End Sub Private Sub CLEAR_click() Text1.text=RS(2) Text4.FALSE.DELETE MsgBox”the record is deleted” RS.text=RS(3) End If .text=”” End Sub Private sub DELETE_Click() RS.EOF Then MsgBox”no more records” Else Text1.UID= Set RS =DB.OpenRecordset(“select * from Bank”) Text1.Table Name :Banking NAME ACNO NAME ADDRESS BALANCE TYPE NUMBER(6) VARCHAR2(30) VARCHAR2(20) NUMBER(8.text=”” Text4.FALSE.text=”” Text2.text=RS(2) Text4.

Text MsgBox”record is inserted” RS.Text=RS(1) Text3.text=RS(3) End Sub Private Sub NEXT_Click() RS.Text=RS(3) End Sub Private Sub INSERT_Click() RS.text=RS(0) Text2.Text RS(1) =Text2.Text RS(2)=Text3.text=RS(1) Text3.text=RS(0) Text2.EOF Then MsgBox”no more recfords” Else Text1.text=RS(2) Text4.AddNew RS(0)=Text1.UPDATE End Sub Private Sub LAST_Click() RS.EOF Then 46 .text=RS(3) EndIf End Sub Private Sub PREVIOUS_Click() RS.Move Next If RS.Text RS(3)=Text4.Text=RS(0) Text2.text=RS(1) Text3. MoveLast Text1.MoveLast RS.Text=RS(2) Text4.Move Previous If RS.MoveFirst Text1.End Sub Private Sub EXIT Click() End End Sub Private Sub FIRST_Click() RS .text=RS(2) Text4.

Show Form2.Show End Sub Private Sub DEPOSIT_Click() Form3.Text RS.Text RS(3)=Text4.Hide End Sub 47 .MsgBox”no more recfords” Else Text1.Text RS(2)=Text3.text=RS(3) EndIf End Sub Private Sub WITHDRAW_Click() Form2.UPDATE MsgBox”record is inserted” End Sub Private Sub FIND_Click() 1=InputBox(“ENTER THE ACNO”.text=RS(0) Text2.text=RS(2) Text4.Edit RS(0)=Text1.”FIND”) rs.FindFirst”[ACNO]=”&I If rs.text=RS(1) Text3.NoMatch Then MsgBox”no such records” Else Text1.text=RS(2) Text4.Text RS(1) =Text2.text=RS(3) EndIf End Sub Private Sub UPDATE_Click() RS.Show End Sub FORM 2: Private Sub HOMEPAGE_Click() Form1.text=RS(1) Text3.text=RS(0) Text2.

Private Sub WITHDRAW_Click() Text2.Text4=Text2.Text Form1.Text Form1.Text=val(Form1.Hide End Sub 48 .text End Sub End FORM 3: Private Sub DEPOSIT_Click() Text2.Text)-Text1.text End Sub Private Sub HOMEPAGE_Click() Form1.Text=val(Form1.Text4=Text2.Show Form3.Text)+Text1.

WITHDRAW FORM: 49 .

DEPOSIT FORM: RESULT: Thus the banking system has been successfully developed in Visual Basic. 10. MINI PROJECT (2) 50 .

dateofreturn respectively and insert some record into the database.Design the corresponding form with labels. Give a suitable data source name. B .Create the back with the front end using DAO method by creating a dsn as follows A . 5.user name and server name.text boxes and command buttons. 2.which displays a dialog box named ODBC DATASOURCES ADMINISTRATOR in which click Add button. Form1 bookdetails Form2 issuedetails 3. Then click on data source(ODBC).noofcopiesavailable and Bid.select “Microsoft ODBC for ORACLE” and click finish button. C .stuname. 4.Perform the required operations like Insert.card number.Price. TABLE DESIGN: 51 .Searching and Exit.of copies available.Execute the project.Bname.Issue the books according to the no.Author.Bname.Author.Delete. PROCEDURE: 1.Create a book and issue database with the following fields in Oracle namely Bid. In Create New Data Source dialog box. 6. Select administrative tools option from control panel.DESIGN AND IMPLEMENTATION OF LIBRARY INFORMATION SYSTEM AIM: To develop a library information system using Oracle as a back end (data base)and Microsoft Visual Basic as a front end.

2) NUMBER(6) Table Name 2 : Issue NAME BID BNAME AUTHOR PRICE NO OF COPIES AVAILABLE TYPE NIMBER(6) VARCHAR2(30) VARCHAR2(20) NUMBER(8.Table Name 1 : Books BID BNAME AUTHOR CARDNUMBER STUNAME DATEOFRETURN NUMBER(6) VARCHAR2(30) VARCHAR2(20) VARCHAR2(8.2) NUMBER(3) 52 .2) VARCHAR2(8.

BOOK DETAILS FORM: 53 .

false.ISSUE DETAILS FORM: FORM 1: Dim DB As Database Dim RS As recordset Private Sub Form_Load() Set DB =OpenDatabase(“libdsn”.false.OpenRecordset(“select * from Book”) .uid= .”ODBC.”) 54 .pwd= Set RS =DB.

text=RS(1) Text3.MOVEFIRST 55 .DELETE MsgBox”the record is deleted” RS.Text RS.Text RS(2)=Text3.text=”” End Sub Private sub DELETE_Click() RS.text=”” Text4.Text1.text=”” Text2.MoveNext IfRS.text=RS(4) End Sub Private Sub CLEAR_click() Text1.text=RS(0) Text2.text=”” Text5.text=RS(2) Text4.text=RS(3) Text5.UPDATE End Sub Private Sub MOVEFIRST_Click() RS.AddNew RS(0)=Text1.text=RS(1) Text3.Text RS(1) =Text2.text=RS(3) Text5.text=RS(0) Text2.Text RS(3)=Text4.MOVELAST RS.text=RS(4) End If End Sub Private Sub EXIT Click() End End Sub Private Sub INSERT_Click() RS .text=RS(2) Text4.Text RS(4)=Text5.text=”” Text3.EOF Then MsgBox”no more records” Else Text1.

Text RS(3)=Text4.MOVEFIRST Text1.Text1.OpenRecordset(“select * from Book”) Text1.text=RS(3) Text5.Show Else MsgBox”NO BOOKS AVAILABLE” End If End Sub FORM2: Dim DB As Database Dim RS As recordset Private Sub Form_Load() Set DB =OpenDatabase(“libdsn”.text=RS(4) End Sub Private Sub ISSUE_Click() If Val(Text5.Text3 End Sub Private Sub ISSUE_Click() RS.false.text=RS(4) End Sub Private Sub SEARCH_Click() 1=InputBox(“ENTER THE BID”.pwd= Set RS =DB.Text)>=1 Then Form2.”FIND”) RS.Text RS(5)=Text6.Text .Text=Form1.Text RS(2)=Text3.text=RS(0) Text2.text=RS(2) Text4.Ttext=Form1.Text1 Text2.NoMatch Then MsgBox”no such records” Else RS.uid= .text=RS(3) Text5.false.FindFirst”[BID]-”&I If RS.”ODBC.”) 56 .text=RS(1) Text3.text=RS(0) Text2.text=RS(2) Text4.text=RS(1) Text3.AddNew RS(0)=Text1.Text2 Text3.Text RS(1) =Text2.Text=Form1.Text RS(4)=Text5.

text=RS(4) End If End Sub Private Sub UPDATE_Click() RS.Text RS(1) =Text2.text=RS(0) Text2.text=RS(3) Text5.text=RS(2) Text4.text=RS(1) Text3.EOF Then MsgBox”no more records” Else Text1.text=RS(4) End If End Sub Private sub PREVIOUS_Click() RS.Text5=val(Form1.Text RS.text=RS(4) End Sub Private sub NEXT_Click() RS.text=RS(0) Text2.Text RS(2)=Text3.RS.UPDATE RS.Text5)-1 End Sub Private Sub MOVELAST_Click() RS.EOF Then MsgBox”no more records” Else Text1.UPDATE 57 .MovePrevious IfRS.Text RS(3)=Text4.text=RS(2) Text4.text=RS(3) Text5.MOVELAST Text1.Edit RS(0)=Text1.text=RS(3) Text5.MOVELAST Form1.MoveNext IfRS.text=RS(2) Text4.text=RS(1) Text3.text=RS(1) Text3.text=RS(0) Text2.Text RS(4)=Text5.

End Sub Private Sub MAINMENU_Click() Form1. 58 .Hide End Sub RESULT : Thus the Library Information System has been successfully developed in VB.Show Form2.

Sign up to vote on this title
UsefulNot useful