INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and...

57
KALASALINGAM UNIVERSITY (Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER

Transcript of INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and...

Page 1: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

KALASALINGAM UNIVERSITY

(Kalasalingam Academy of Research and Education)

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

(CSE287)

IV SEMESTER

Page 2: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

EX.NO: 1

CREATING TABLES AND QUERIES USING MS-ACCESS

CREATING A TABLE IN MS ACCESS:

Open Microsoft access>click on create a new file;

Page 3: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

Choose a bank database and save it ;

Click on create table in design view;

Page 4: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

Give entries in table;

Save the table;

Specify the primary key….click on yes;

Page 5: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

Open the saved table and enter the record data in table;

Page 6: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

CREATING A QUERY IN MS ACCESS:Click on create query in design view;

Select the table from table list in order to create table;

Join the all field of tables which are used to relate;

Page 7: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

Choose the required field, table, show/hide, sort etc.;

Page 8: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

Save the query by entering your query name;

Open the query to dispay;

Page 9: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

EX.NO: 2CREATING FORMS AND REPORTS USING MS-ACCESS

CREATING A FORM IN MS ACCESS:

Open the M.S. Excess > create form > choose table/query

Page 10: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

CREATING A REPORT IN MS ACCESS:Open the M.S. Excess > create report> choose table/query

Page 11: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

INTRODUCTION

What is SQL?

SQL stands for Structured Query Language

SQL allows you to access a database

SQL is an ANSI standard language

SQL can execute queries against a database

SQL can retrieve data from a database

SQL can manipulate new records in a database

Features of Oracle 9i

* Data types: new ones (BLOB, BFILE, CLOB, etc) and larger VARCHAR (4000)

* Tables support 1000 columns

* Partitioned tables and indexes

* Better parallel processing (CREATE INDEX, CREATE TABLE AS SELECT,...)

* Object-relational features (Nested Tables, VARRAYs, object views)

* Better security (expiring passwords, password history, locking a user out if they enter 3

invalid passwords, etc.)

* Index-only tables (tables stored in B*Treive format)

* Reverse key indexes - for indexes with unevenly distributed data

* Better Cost-based optimization

* Deferred constraints

* Updatable views with INSTEAD OF Triggers

Introduction to Visual Basic:

Visual Basic makes it easy to create simple or complex Windows programs,

through a range of different project types.

Visual Basic falls into a category of programming referred to as event-driven

programming.

Event-driven programs respond to events from the computer, such as the mouse

button being pressed.

Page 12: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

The designer uses ready-made objects such as Command Buttons and Textboxes,

to build user interfaces that make up the application.

This approach to programming drastically reduces the amount of code required to

develop a Windows application.

Components of Visual Basic:

Graphical User Interface (GUI) Components

Variables

Program Flow

Events

Graphics

Working with Strings

Working with Dates and Times

Drag and Drop

Procedures and Functions

Debugging and Error Handling

File Handling and the FSO Object

Common Dialog Control

Database Connectivity

Classes and Object Oriented Programming

ActiveX Components

Page 13: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

Creating a COM Object

TCP/IP Network Programming

Internet Programming (HTTP and FTP)

The Windows API

Using XML

What is MS Access?  

Microsoft Access is another of the tools in the Office 97 Suite which enables the

user to turn data into answers and to share up-to-date information with others.

Data from Excel spreadsheets can be converted to Access databases and data from

Access can be published on the Web in HTML format. 

Access is a 32-bit program which enables the user to create a complete front-end

user application.

The program is complete integrated into the rest of the Microsoft Office Suite

which means that the user can move data into and from Word, Excel and

PowerPoint.   

Page 14: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

Ex.No:3

DDL, STATEMENTS

Aim:

To execute and verify various data definition statements in SQL.

Theory:

Structured Query Language includes:

1) DDL – Data Definition Language

2) DML– Data Manipulation Language

3) DCL – Data Control Language

1) Data Definition Language (DDL):

It is a subset of SQL that is used to define, describe and change the structure of

database.

It can change and record the information in Data Dictionary

DDL Statements:

1. Create Table

2. Desc Table

3. Alter Table

4. Drop Table

1. Create Table:

This command enables the users to create their own tables.

Page 15: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

The name of the tables can be given by the users and it should begin withan

alphabet followed by a set of alphabets or numerals or special characters like

‘_’

The column names in the table must be unique

The columns may have constraints like PRIMARY KEY, UNIQUE,

FOREIGN KEY,DEFAULT, CHECK etc.,

Primary Key:

This constraint can be set for the field that acts as an identifier

A field with primary key constraint will not accept “duplicate” and NULL

values

Unique:

A field with unique constraint may have NULL values but all other values

should not be duplicated.

Foreign Key:

A foreign key field of one table may refer the primary key field of another

table in order to maintain the consistency between them.

Default:

This constraint assigns a default value to particular field if that field is

skipped during insertion.

Check:

This constraint checks whether the value of that field satisfies given

condition. It will not allow the field values that does not satisfy the

condition specified by the check constraint.

Not Null:

A field with this constraint will not accept NULL values.

Syntax to Create Table:

Page 16: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

2. Desc Table:

This command is used to describe the structure of database.

Syntax:

3. Alter Table:

This command is used to add a new column to existing database and also to

modify an existing column in the database

Syntax:

4. Drop Table:

This command is used to remove the entire schema(structure) of the

database

Syntax:

Create table <table_name>( <column-name1> <datatype1> [constraints], <column-name2> <datatype2> [constraints],

.

.

.

.

.<column-name N> <datatype-n> );

Desc <tablename>

DROP TABLE <table-name> ;

ALTER TABLE <table-name>

ADD | MODIFY (< col-name> <data-type> )

< constraints >];

Page 17: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

Ex No: 4

Implementation of DML and DCL commands in RDBMS.

Aim:

To execute and verify various data manipulation and data control languages in

SQL.

Theory:

Structured Query Language includes:

1) DDL – Data Definition Language

2) DML– Data Manipulation Language

3) DCL – Data Control Language

1.Data Manipulation Language : (DML)

DML is a subset of SQL commands and are used to manipulate the database.

DML Statements:

Page 18: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

1. Insert2. Update3. Delete4. Select

1.Insert :

This command is used to add new records to the database.

Syntax :

2.Update:

This command is used to change the already existing records in the database.

A simple update statements performs changes in all the records

Update statement with where condition changes only the records that satisfies

given where condition.

3. Delete:

This command is used to remove the records from table.

A simple delete command removes all the records in the table

Delete command with where clause removes only the records that satisfies given

where condition

4.Select:

INSERT INTO <table-name> [list of columns]

VALUES (list of values) ;

UPDATE <table-name> SET <col-name> = <new-value> [, <col-name> = <new-value>][WHERE <condition>];

DELETE FROM <table-name>

[WHERE <condition>];

Page 19: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

This command is used to retrive a single record or set of records from a table(or

set of tables)

If where clause is specified it selects a set of records that satisfies given condition

If column names are specified, it selects only that columns otherwise a ‘ * ‘

2.Data Control Languages(DCL):

DCL is used to control the database access among multiple users.

Various DCL statements are:

1. Grant

2. Revoke

3. Role

4. Commit

5. Save Point

6. Rollback

1.Grant:

Grant command is used to create users and to grant access to the database.

Syntax:

2.Revoke:

SELECT * | <column-names FROM <table-name>

[WHERE <condition>];

GRANT <database_privilege> TO

<user-name> IDENTIFIED BY <password>

Page 20: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

The DBA can revoke database privileges from any user using this command.

Syntax:

3.Role:

This is used to simplify the administrative tasks involved in the

management of privileges

Role is a collection of related system privileges

Role can be granted to users or to other role(s)

Syntax to Create Role:

Syntax to Grant Role:

Syntax to Set Role:

4.Commit:

REVOKE <database_privilege>

FROM <user-name>

CREATE ROLE <role-name>

IDENTIFIED BY <password>

GRANT <role-name> TO <user-name>

SET ROLE <rolename>

Page 21: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

This is used to make the changes to data (insert, delete or update) permanent

Commit can be done automatically using the AUTOCOMMIT commandSyntax to set commit:

Syntax to reset commit:

Syntax to save updation:

5.Save Point:

This identifies a point in transaction to shich one can later rollback with Rollback statement

6.Rollback:

It is used to discard parts or all the work the user has done in the current transaction

Learning Outcome:

Students will be familiar with different database languages.

Method of Assessment:

SET AUTOCOMMIT ON

COMMIT

SET AUTOCOMMIT OFF

SAVEPOINT <save_point_name>

ROLLBACK <save_point_name>

Page 22: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

a)Query - 4

b)Result - 3

c)Viva - 3

REF:

DDL - www.va.pubnix.com/man/xdb/sqlref/SQLCommands_4.html

DML-www.georgehernandez.com/xDatabases/SQL/Index.htm

DCL -www.batky-howell.com/courses/datasheets/ products/o8at.html

Ex No : 5

FUNCTIONS IN SQL

Aim :

To use various built-in functions of sql and to verify the results

Theory:

Library Functions in SQL are classified into five major categories as follows:

a) Arithmetic Functionsb) Character Functionsc) Date Functionsd) General Functionse) Group Functions

a) Arithmetic Functions:

Page 23: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

1. ABS(n)2. CEIL(n)3. FLOOR(n)4. MOD(m,n)5. POWER(m,n)

6. SQRT(n)7. TRUNC(m [,n])8. ROUND(m [,n])9. EXP(n)10.SIGN(n)

b)Character Functions:

1.CHR(n)2.CONCAT(s1,s2)3.LOWER(s1)4.UPPER(s1)5.LPAD(s1,n,char1)6.RPAD(s1,n,char1)7.SOUNDEX(s1)8.LTRIM(s1,char)9.RTRIM(s1,char)10.REPLACE(s1,search_string,replace_string)11.SUBSTR(s1,m)12.TRANSLATE(s1,from_str,to_str)13.ASCII(s1)14. INSTR(s1,char1)15. LENGTH(s1)16. INITCAP(s1)

c) Date Functions

1 . SYSDATE2. ADD_MONTHS(d,n)3. ROUND (d [,format])4. TRUNC (d [,format])5. MONTHS_BETWEEN(d1,d2)6. LAST_DAY(d)7. NEXT_DAY(date , day)8. TO_CHAR(d,f)9. TO_DATE(char , ‘f’)

d) General Functions

1. GREATEST (n1,n2,…)2. LEAST (n1,n2,….)3. NVL (col , value)4. DECODE (C, V1,S1,V2,S2….D)5. UID

Page 24: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

6. USER

e) Group Functions

1. STDDEV (column_name)2. VARIANCE (column_name)3. COUNT(col_name)4. SUM(col_name)5. MAX(col_name)6. MIN(col_name)7. AVG(col_name)

Learning Outcome:

Knowledge in built-in functions of sql will be useful in preparing reports during

projects and to do mathematical calculations.

Method of Assessment:

1) Query – 42) Result -43) Viva – 2

REF: databases.about.com/library/weekly/aa040101a.htm

What is PL/SQL?

PL/SQL stands for Procedural Language extension of SQL.

PL/SQL is a combination of SQL along with the procedural features of programming languages.

It was developed by Oracle Corporation in the early 90’s to enhance the capabilities of SQL.

Each PL/SQL program consists of SQL and PL/SQL statements which from a PL/SQL block.

A PL/SQL Block consists of three sections: The Declaration section (optional). The Execution section (mandatory). The Exception (or Error) Handling section (optional).

Page 25: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

Declaration Section:

The Declaration section of a PL/SQL Block starts with the reserved keyword DECLARE. This section is optional and is used to declare any placeholders like variables, constants, records and cursors, which are used to manipulate data in the execution section. Placeholders may be any of Variables, Constants and Records, which stores data temporarily. Cursors are also declared in this section. 

Execution Section:

The Execution section of a PL/SQL Block starts with the reserved keyword BEGIN and ends with END. This is a mandatory section and is the section where the program logic is written to perform any task. The programmatic constructs like loops, conditional statement and SQL statements form the part of execution section. 

Exception Section:

The Exception section of a PL/SQL Block starts with the reserved keyword EXCEPTION. This section is optional. Any errors in the program can be handled in this section, so that the PL/SQL Blocks terminates gracefully. If the PL/SQL Block contains exceptions that cannot be handled, the Block terminates abruptly with errors. 

Every statement in the above three sections must end with a semicolon ; . PL/SQL blocks can be nested within other PL/SQL blocks. Comments can be used to document code. 

This is how a sample PL/SQL Block looks.DECLARE      Variable declarationBEGIN      Program Execution EXCEPTION      Exception handlingEND;

PL/SQL Variables

These are placeholders that store the values that can change through the PL/SQL Block.

The General Syntax to declare a variable is:

Page 26: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

variable_name datatype [NOT NULL := value ]; variable_name is the name of the variable. datatype is a valid PL/SQL datatype. NOT NULL is an optional specification on the variable. value or DEFAULT valueis also an optional specification, where you can

initialize a variable. Each variable declaration is a separate statement and must be terminated by a

semicolon.

For example, if you want to store the current salary of an employee, you can use a variable.

DECLAREsalary number (6);

* “salary” is a variable of datatype number and of length 6.

When a variable is specified as NOT NULL, you must initialize the variable when it is declared.

For example: The below example declares two variables, one of which is a not null.

DECLAREsalary number(4);dept varchar2(10) NOT NULL := “HR Dept”;

The value of a variable can change in the execution or exception section of the PL/SQL Block. We can assign values to variables in the two ways given below.

1) We can directly assign values to variables.     The General Syntax is:         

  variable_name:= value;

2) We can assign values to variables directly from the database columns by using a SELECT.. INTO statement. The General Syntax is:SELECT column_nameINTO variable_name FROM table_name [WHERE condition];

Example: The below program will get the salary of an employee with id '1116' and display it on the screen.

Page 27: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

DECLARE  var_salary number(6);  var_emp_id number(6) = 1116; BEGIN SELECT salary  INTO var_salary  FROM employee  WHERE emp_id = var_emp_id;  dbms_output.put_line(var_salary);  dbms_output.put_line('The employee ' || var_emp_id || ' has salary ' || var_salary); END; /NOTE: The backward slash '/' in the above program indicates to execute the above PL/SQL Block. 

Scope of Variables

PL/SQL allows the nesting of Blocks within Blocks i.e, the Execution section of an outer block can contain inner blocks. Therefore, a variable which is accessible to an outer Block is also accessible to all nested inner Blocks. The variables declared in the inner blocks are not accessible to outer blocks. Based on their declaration we can classify variables into two types.

Local variables - These are declared in a inner block and cannot be referenced by outside Blocks.

Global variables - These are declared in a outer block and can be referenced by its itself and by its inner blocks.

For Example: In the below example we are creating two variables in the outer block and

assigning thier product to the third variable created in the inner block. The variable 'var_mult' is

declared in the inner block, so cannot be accessed in the outer block i.e. it cannot be accessed

after line 11. The variables 'var_num1' and 'var_num2' can be accessed anywhere in the block.

1> DECLARE2> var_num1 number; 3>  var_num2 number; 4> BEGIN 5>  var_num1 := 100; 6>  var_num2 := 200; 7>  DECLARE 8>   var_mult number;

Page 28: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

9>   BEGIN 10>    var_mult := var_num1 * var_num2; 11>   END; 12> END; 13> /  

PL/SQL Constants

As the name implies a constant is a value used in a PL/SQL Block that remains unchanged throughout the program. A constant is a user-defined literal value. You can declare a constant and use it instead of actual value.

For example: If you want to write a program which will increase the salary of the employees by 25%, you can declare a constant and use it throughout the program. Next time when you want to increase the salary again you can change the value of the constant which will be easier than changing the actual value throughout the program.

The General Syntax to declare a constant is:

constant_name CONSTANT datatype := VALUE; constant_name is the name of the constant i.e. similar to a variable name. The word CONSTANT is a reserved word and ensures that the value does not

change. VALUE - It is a value which must be assigned to a constant when it is declared.

You cannot assign a value later.

For example, to declare salary_increase, you can write code as follows:

DECLARE salary_increase CONSTANT number (3) := 10;

You must assign a value to a constant at the time you declare it. If you do not assign a value to a constant while declaring it and try to assign a value in the execution section, you will get a error. If you execute the below Pl/SQL block you will get error.

Page 29: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

Conditional Statements in PL/SQL

As the name implies, PL/SQL supports programming language features like conditional statements, iterative statements.

The programming constructs are similar to how you use in programming languages like Java and C++.

In this section I will provide you syntax of how to use conditional statements in PL/SQL programming.

Conditional Statements in PL/SQL

IF THEN ELSE STATEMENT1)IF condition THEN  statement 1; ELSE  statement 2; END IF; 2)IF condition 1 THEN  statement 1;  statement 2; ELSIF condtion2 THEN  statement 3; ELSE  statement 4; END IF

3)IF condition 1 THEN  statement 1;  statement 2; ELSIF condtion2 THEN  statement 3; ELSE  statement 4; END IF; 

Page 30: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

4)IF condition1 THEN ELSE  IF condition2 THEN  statement1;  END IF; ELSIF condition3 THEN   statement2; END IF;

Iterative Statements in PL/SQL

An iterative control Statements are used when we want to repeat the execution of one or more statements for specified number of times. These are similar to those in 

There are three types of loops in PL/SQL: • Simple Loop• While Loop• For Loop

1) Simple Loop

A Simple Loop is used when a set of statements is to be executed at least once before the loop terminates. An EXIT condition must be specified in the loop, otherwise the loop will get into an infinite number of iterations. When the EXIT condition is satisfied the process exits from the loop.

The General Syntax to write a Simple Loop is: 

LOOP statements; EXIT; {or EXIT WHEN condition;}END LOOP; These are the important steps to be followed while using Simple Loop.

1) Initialise a variable before the loop body.2) Increment the variable in the loop.3) Use a EXIT WHEN statement to exit from the Loop. If you use a EXIT statement without WHEN condition, the statements in the loop is executed only once.

Page 31: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

2) While Loop

A WHILE LOOP is used when a set of statements has to be executed as long as a condition is true. The condition is evaluated at the beginning of each iteration. The iteration continues until the condition becomes false.

The General Syntax to write a WHILE LOOP is:WHILE <condition> LOOP statements; END LOOP; Important steps to follow when executing a while loop: 

1) Initialise a variable before the loop body.2) Increment the variable in the loop.3) EXIT WHEN statement and EXIT statements can be used in while loops but it's not done oftenly.

3) FOR Loop

A FOR LOOP is used to execute a set of statements for a predetermined number of times. Iteration occurs between the start and end integer values given. The counter is always incremented by 1. The loop exits when the counter reachs the value of the end integer.

The General Syntax to write a FOR LOOP is: 

FOR counter IN val1..val2 LOOP statements; END LOOP;

val1 - Start integer value. val2 - End integer value.

Important steps to follow when executing a while loop: 

1) The counter variable is implicitly declared in the declaration section, so it's not necessary to declare it explicity.2) The counter variable is incremented by 1 and does not need to be incremented explicitly.3) EXIT WHEN statement and EXIT statements can be used in FOR loops but it's not done oftenly.

Page 32: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

PL/SQL Exercise

1. Write a PL/SQL program to swap two numbers.

2. Write a PL/SQL program to find greatest among three numbers.

3. Write a PL/SQL program to find the sum of digits

4. Write a PL/SQL program to find the factorial of a given number.

5. Write a PL/SQL program to find the reverse of a given number.

6. Write a PL/SQL program to find the average of a given number.

7. Write a PL/SQL program to print the multiplication table.

8. Write a PL/SQL program to find the Armstrong of a given number.

9. Write a PL/SQL program to print the Fibonacci series.

Page 33: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

Ex.No:7 CURSORS

Aim:To implement cursor concept in manipulating the employee database

Theory:Cursors are special work area in sql.

The work area contains specific set of rows that are selected by select statements.

These work areas are referred by the name of cursors.

A cursor usually stores a set of rows that are selected by select statements and it is

used to manipulate those records by fetching them one by one.

Cursor program includes four sub parts namely,

1.Cursor declaration

2.Opening a Cursor

3.Fetching

4.Closing a Cursor

1.Cursor Declaration:

A cursor variable is declared in the declaration part of PL/SQL block.

Syntax:

2.Opening a Cursor:

Before using a cursor it should be opened.

The open statement should be given in the BEGIN – END construct.

Cursor <cursor_name> is

<select statement>

Page 34: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

A cursor when opened, will point to the first row by default.

Syntax:

3.Fetching:

The set of rows held by a cursor can be fetched (read) row by row.

A single fetch statement moves the cursor pointer by one row.

Syntax:

4.Closing a Cursor:

After processing all the records , the cursor can be closed.

Syntax:

Algorithm:

1.Declare a cursor to select all the tuples of employee relation2.Open cursor3.Fetch the current record. Initially it fetches first record and the pointer is forwarded to next record automatically4.Check the job of the employee record that is currently pointed by the cursor variable5.If job =’manager’

Provide 20 % bonus Or if job = ‘clerk’

Provide 15% bonus Otherwise

Provide 10% bonus.6.Update the salary as salary + bonus 7.Repeat steps 3 – 6 until all records are manipulated.8.Close the cursor.

Sample Input:

SQL> select * from bonus;

Open <cursor_name>

Fetch <cursor_name> into <variable_list>

Close <cursor_name>

Page 35: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

ENAME JOB SAL COMM---------- --------- --------- ---------Fatima Engineer 10000 200Meera Manager 10000 500Abishek Clerk 1000 100Vishnu Analyst 5000 100

Expected Output:

ENAME JOB SAL COMM---------- --------- --------- ---------Fatima Engineer 11000 200Meera Manager 12000 500Abishek Clerk 1150 100Vishnu Analyst 5500 100

Learning Outcome :

Programmers can implement cursor as a simple tool for database manipulation

Method of Assessment:

a)Program Logic:3

b)Coding Style :3

c)Result :2

d)Viva :2

REF:www.adp-gmbh.ch/ora/plsql/cursor.html

www.springhouse.com/Courses/Descriptions/ Oracle/oracle8.asp

Page 36: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

Ex.No:8TRIGGERS

Aim:

To trigger an action automatically on the occurrence of particular event

Theory:

A database trigger is a stored PL / SQL program unit associated with a specific

database table.

No need to call the trigger explicitly. Triggers are fired automatically, during the

occurrence of particular event.

Parts of Trigger:

1) Triggering Event

2) Trigger Restriction

3) Trigger Action

1.Triggering event:

A triggering event is the SQL statement that causes a trigger to be fired.

Eg)insert, delete, update.

2.Trigger Restriction:

A trigger restriction is a Boolean expression that must be true to trigger an action.

A triggering event causes triggering restriction to get true.

3.Trigger Action:

A trigger action is the procedure that contains the SQL statements and PL / SQL

scode to be executed

Syntax:CREATE OR REPLACE TRIGGER <trigger_name>

BEFORE | AFTER | INSTEAD OF

INSERT | DELETE | UPDATE [OF column_name]

ON <table_name>

BEGIN

<pl/sql statements>END;

Page 37: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

Learning Outcome :

Consistency between related databases are maintained in a better way by

implementing triggers.

Method of Assessment :

1.Program logic-3

2.Coding Style -3

3.Result -2

4.Viva -2

REF:

www.dba-oracle.com/cou_plsql.htm

www.angelfire.com/me/davidsonderek/resume.html

ihome.ust.hk/~shirleya/COMP231-02/lab4.ppt

Page 38: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

Ex.No:9 PROCEDURES

Aim:

To implement procedures in database manipulation

Thoery:

Procedure is a sub program that performs specific action

A procedure can be called from any PL / SQL program

Procedures are named PL / SQL blocks that can take arguments if needed.

Advantages:

Extensibility

Modularity

Reusability and Maintainablity

Abstraction

Syntax:

Algorithm:

1.Get the option 2.Get the values for name, rollno, avg3.If option=1 then

Insert the values into stud table Else if option = 2 then

CREATE OR REPLACE PROCEDURE <procedure_name> [argument_list] IS

<declaration of local variables>

BEGIN

<pl/ sql statements>

END

Page 39: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

Update the record specified by rollno with new values Else if option=3 then

Delete the record specified by rollno4.Terminate the Procedure

Sample Input:

Enter the Option:1Enter the name : vijayEnter the rollno: 2KCS98Enter the averg : 78

pl / sql procedure completed successfully

Expected Output:

Exec p1;

SQL>Select * from stud;

NAME RNO AVERAGE-------------------- -------- --------------Aarthi 01CS01 56Raja 01CS43 93vijay 2KCS98 78 Learning Outcome :

Procedures can be used for efficient programming because, repetition of code can

be avoided by creating subprograms.

Method of Assessment :

a)Program Logic:3

b)Coding Style :3

c)Result :2

d)Viva :2

REF:www.cs.utah.edu/~cs5530/lectures/lecture11x2.pdf

Page 40: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

classweb.gmu.edu/nnada/infs614/lecture7x2.pdf

www.orafaq.com/msgboard/newbies/messages/2256.htm

Ex.No:11

PROGRAM USING DATACONTROL(VB with MS-Access)

Aim:

To link databases with application programs using datacontrol

Theory:

Setting Properties of datacontrol:

Connect:

MS-Access

Database Name:

Specify the database to which you want to gain access by setting the database

name of the database(select the mdb file accordingly)

Record Source:

To specify from which records you want to retrieve the data , set the recordsource

property to the name of the table within the database.

Setting Properties of Text Boxes:

Data Source:

Data control acts as source for the data

Data Field:

Select the field to be displayed in this textbox

Methods available for datacontrol:

1) Recordset Addnew Method:

It is used to add new records to a recordset.

Eg) Data1.Recordset.Addnew

2) Recordset Edit Method:

Page 41: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

It is used to modify the record in the recordset.

Eg) Data1.Recordset.Edit

3)Recordset Update Method:

It is used to save the modification of the record in the recordset.

Eg) Data1.Recordset.Update

4)Recordset Delete Method:

It is used to delete the record in the recordset.

Eg) Data1.Recordset.Delete

Learning Outcome:

The datacontrol in VB provides the user with the ability to write powerful

database applications with very little code.

Method of Assessment :

1.Settings – 4

2.Usage of Methods - 4

3.Viva - 2

REF:

1.mcsehelp.com/70-165/mao.htm

2.www.experts-exchange.com/Programming/Programming_Languages/

visual_Basic/Q_10229113.html

Page 42: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

Ex.No:12

PROGRAM USING DATACONTROL(VB with Oracle)

Aim:

To link databases with application programs using datacontrol

Theory:

ODBC – Open Data Base Connectivity

A standard protocol that permits applications to connect to a variety of external

database servers or files . ODBC drivers used by Microsoft Jet databasse engine permit

access to Microsoft SQL server and several other external databases.

Creating ODBC Connection:

Steps:

1.Goto Control Panel -> Administrative tools -> ODBC data sources

2.Add a user dsn

3.Create a user dsn for the category Microsoft ODBC for oracle.

4.Give a datasource name and set userid as scott, password as tiger

Setting Properties of datacontrol:

Connect:

Odbc;dsn=aa;uid=scott;pwd=tiger

Default Type:

Change the default type property of data1 as UseODBC

Record Source:

To specify from which records you want to retrieve the data , set the recordsource

property to the name of the table within the database.

Setting Properties of Text Boxes:

Page 43: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

Data Source:

Data control acts as source for the data

Data Field:

Select the field to be displayed in this textbox

Methods available for datacontrol:

1) Recordset Addnew Method:

It is used to add new records to a recordset.

Eg) Data1.Recordset.Addnew

2) Recordset Edit Method:

It is used to modify the record in the recordset.

Eg) Data1.Recordset.Edit

3)Recordset Update Method:

It is used to save the modification of the record in the recordset.

Eg) Data1.Recordset.Update

4)Recordset Delete Method:

It is used to delete the record in the recordset.

Eg) Data1.Recordset.Delete

Learning Outcome:

The datacontrol in VB provides the user with the ability to write powerful

database applications with very little code.

Method of Assessment :

1.Settings – 4

2.Usage of Methods - 4

3.Viva - 2

REF:

1.www.eduscape2000.com/public_html/protect/vb/Section_2/

Seven_Common_Controls/seven_common_controls.html

Page 44: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

Ex.No:13

PROGRAM USING DAO(VB with Ms-Access)

Aim:

To connect Ms-Access with VB without using datacontrol

Theory:

DAO – Data Access Object

DAO enables user to use a programming language to access and manipulate data

in local or remote databases and to manage databases, their objects and their

structures.

DAO can be included by adding references in the project

Various Data Access Objects:

DB Engine :

It is a top level database object and corresponds to the jet database engine. This

object is used to set database engine system parameters and default workspace

Data Base:

It corresponds to a jet native or external database or a direct ODBC connection.

This is used to define the database tables, relations , stored queries and to open

recordset objects.

Query Def:

It is a stored query definition, which is a precompiled SQL statement.

Methods related to DAO:

Open Data Base Method:

Page 45: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

Opens a specified database in a workspace object and returns a referencee to the

database object.

Syntax:

Open Record Set Method:

Creates a new record set object and appends it to the record set collection

Syntax:

CreateQueryDef Method

Creates a new querydef object in a specified database object

Syntax:

Methods in Recordset object:

Addnew: Creates a new record for an updatable recordset object.

Syntax:

Edit: Copies current record from an updatable recordset object to the copy buffer

for subsequent editing

Syntax:

Update: Saves the contents of copy buffer to an update recordset object

Syntax:

Set databaseobject=opendatabase(dbname, options, read-only, connect)

Set recordsetobject =object.openrecordset(source, type,options,lockedits)

Set querydefobject = object . createquerydef (name, sqltext)

Recordset . Addnew

Recordset.Update

Recordset . Edit

Page 46: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .

Delete: Deletes the current record in updatable recordset object

Syntax:

Learning Outcome:

Programmer will improve their skills in develping projects in VB and MS-Access.

Method of Assessment:

1)Usage of Methods - 4

2)Results - 3

3)Viva - 3

REF:

1.builder.com.com/article.jhtml?id=u00820011012med01.htm

2.www.microsoft.com/accessdev/articles/av9709.htm

Recordset . Delete

Page 47: INTRODUCTION - ssncse.files.wordpress.com€¦  · Web view(Kalasalingam Academy of Research and Education) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING (CSE287) IV SEMESTER .