Admission News

Latest Admission Notifications for BA, B.Com. B.Sc, BBA, BCA, MA, M.Com, M.Sc, MBA, Other PG and UG Courses

Question Papers

Question Papers for Various Universities of India. Download 10 Year Question Paper for Free.

Placement Papers

Placement Papers for Various Companies. Download Placement Papers for Free.

Universities in India

List of Various Universities in India. Get the List of Various Universities, Deemed Universities, IITs and NITs.

Colleges in India

List of Various Colleges in India.

Tuesday, April 8, 2008

INDEXES

INDEXES
Indexing a table is an ‘access strategy’, that is, a way to sort and search records in the table. Indexes are essential to improve the speed with which the record/s can be located and retrieved from the table.
An index is a schema object
Is used by oracle server to speed up the retrieval of rows by using a pointer
Is independent of the table it indexes
Is used and maintained automatically by the oracle server.


ADDRESS FIELD IN THE INDEX

The address field of an index is called ROWID. ROWID is an internal generated and maintained, binary value, which identifies a record. The information in the ROWID columns provides Oracle engine the location of the table and a specific record in the Oracle database.
The ROWID format used by the Oracle is as follows:
BBBBBBB.RRRR.FFFF


CREATION OF SIMPLE DUPLICATE INDEX

SYNTAX: -
CREATE INDEX index_name ON tablename(columnname);

EXAMPLE: -

SQL> CREATE INDEX client_name ON banking1 (name);
Index created.

DROPING OF EXISTING INDEXES

When an index is no longer needed in the database, the developer can remove it with the use of the DROP INDEX command. If the index is used in relation to primary-key or unique constraint, then the index will no longer continue to enforce that uniqueness constraint.

SYNTAX: -
DROP INDEX index_name;
EXAMPLE: -

SQL> DROP INDEX client_name;
Index dropped.

SEQUENCE

SEQUENCE
A sequence is a database object used to generate sequence numbers for rows in the tables. It can be used for producing unique primary key values. A sequence is created using the CREATE SEQUENCE command.


A sequence is a user created database object that can be shared by multiple users to generate unique integers.
A typical usage for sequence is to create a primary key value ,which must be unique for each row. Sequence numbers are stored and generated independently of tables. Therefore, the same sequence can be used for multiple tables.
Is typically used to create primary key value.
Replaces application code


SYNTAX: -

CREATE SEQUENCE sequence_name [INCREMENT] BY integer value START WITH integer value MAXVALUE integervalue

INCREMENT BY:
Specifies the interval between sequence numbers. It can be any positive or negative value but not Zero. If this clause is omitted, the default value is 1.

MIN VALUE:

Specifies the sequence minimum value.

MAX VALUE:
Specifies the maximum value that a sequence can generate.

START WITH:

Specifies the first sequence number to be generated. The default for an ascending sequence is the sequence minimum value (1) and for a descending sequence, it is the maximum value (-1).



EXAMPLE: -
SQL> CREATE SEQUENCE empcode INCREMENT BY 2 START WITH 100;
Sequence created.

REFERENCING A SEQUENCE

Once a sequence is created SQL can be used to view the values held in the cache. To simply view sequence value use a select sentence as described below:
EXAMPLE: -

SQL> SELECT empcode.NEXTVALfrom dual;

NEXTVAL
---------
100
This will display the next value held in the cache on the VDU screen. Every time NEXTVAL references a sequence its output is automatically incremented from the old value to the new value ready for use.

VIEWS

VIEWS

To reduce redundant data to the minimum possible, Oracles allows the creation of an object called a view. A view is mapped, to SELECT sentence. The table on which the view is based is described in the FORM clause of the SELECT statement.

Views are tables whose contents are taken or derived from other tables. Views themselves do not contain data. They just act as a window through which certain contents of a table can be viewed. Also, one can manipulate the contents of the original table these views.

Views can be used to insert, update and delete table data as well as view data. If a view is used to only look at table data and nothing else the view is called a READ-ONLY view.

A view is a logical table based on a table or another view. A view contains no data of its own but is like a window through which data from tables can be viewed or changed.

We use views :
To restrict data access
To make complex queries easy
To provide data independence
To present different vies of the same data

CREATION OF VIEW

SYNTAX: -

CREATE VIEW viewname AS SELECT columnname, columnname
FROM tablename WHERE columnnmae=expression list;
GROUP BY grouping criteria HAVING predicate
EXAMPLE: -
SQL> CREATE VIEW bal_due AS SELECT * FROM banking1;
View created.

SELECTING A DATA SET FROM A VIEW

SYNTAX: -
SELECT columnname, columnname FROM viewname;
EXAMPLE: -
SQL> SELECT name,accountno,id FROM bal_due;

USES OF VIEWS

Views restrict access to the database. If you want users to see some but not all data of a table, you can create a view showing only certain fields.
Critical data in the base table is safe guarded as access to such data can be controlled using views.

SUBQUERIES

SUBQUERIES
A Sub Query is a form of an SQL statement that appears inside another SQL statement. It is also termed as NESTED QUERY. The statement containing a sub query is called a PARENT statement. The parent statement uses the rows returned by the Sub query.

It can be used by the following commands: -


To insert records in the target table.
To create tables and insert records in the table created.
To update records in a target table.
To create views.
To provide values for conditions in WHERE, HAVING, IN etc. used with SELECT, UPDATE, and DELETE statement.
Types of Sub-queries
The types of sub-queries and their description are: -
(1) Single-row sub-queries
Queries that returns only one value from the inner SELECT statement.

(2) Multiple-row sub-queries

Queries that returns more than one value from the inner SELECT statement.

(3) Multiple-column sub-queries
Queries that returns more than one column from the inner SELECT statement

(1) SINGLE ROW SUB-QUERIES
A SINGLE-ROW SUBQUERY returns one row from the inner nested query. These types of sub-queries use single-row operators (>, <, >=, <=, <>, =).

EXAMPLE: -


SQL> SELECT * FROM client_order WHERE client_no =
SELECT client_no FROM sales_order
WHERE order_date='17-Mar-05');

(2) MULTIPLE – ROW QUERIES
Sub-Queries that return more than one row are called multiple row sub-queries. We use a multiple – row operator, instead of a single – row operator, with a multiple-row sub-query. The multiple-row operator accepts one or more values.

There are following multi-row operators:
Operator Meaning

IN Equal to any value in the list.
ANY Compare value to each value returned by the sub-query.


(a) Using IN Operator in multiple-row Sub-Queries
The IN operator returns equal to any value in the list.
EXAMPLE: -
SQL>SELECT order_no,order_date,client_no,sale_amount
FROM sales_order WHERE sale_amount IN
(SELECT MIN (sale_amount)
FROM sales_order GROUP BY client_no);

(b) Using ANY operator in multiple-row Sub-Queries
The ANY operator compares a value to each value returned by a sub-query.
EXAMPLE: -
SQL> SELECT client_no,name,bal_due
FROM client_order WHERE bal_due < client_no="'C0004')">'C0004';

(3) MULTIPLE-COLUMN SUB-QUERIES


Multiple-column sub-queries enable us to combine duplicate WHERE conditions into a single WHERE clause.

SYNTAX: -
SELECT column, column…FROM table WHERE (column, column…) IN (SELECT column, column…FROM table WHERE condition);

CORRELATED SUB-QUERIES


Oracle performs a correlated sub-query when the sub-query references a column from the table referred to in the parent statement. A correlated sub-query is evaluated once for each row processed by the parent statement. The parent statement can be a SELECT, UPDATE, or DELETE statement.


EXAMPLE: -


SQL> SELECT name, address, amount, id FROM banking1 b1 WHERE amount = (SELECT MAX (amount) FROMBanking1 WHERE name=b1.name) ORDER BY name;

JOINS

JOINS

Sometimes we require treating multiple tables as though they were a single entity. Then a single SQL sentence can manipulate data from all the tables. To achieve this, we have to join tables. Tables are joined on columns that have the same data type and data width in the tables. There are various types of joins. They are: -

(1) Self joins (joining a table to itself)
(2) Equi joins/ Inner joins
(3) Outer joins
(4) Not Equi joins
(5) Cartesian joins


(1) SELF JOIN


In Self-Join, a table is joined to itself by specifying the column name in the WHERE condition. Usually using the table name and dot specifies the column name. In this table name must be same.

SYNTAX: -

SELECT * FROM tablename
WHERE =

(2) EQUI JOIN/INNER JOIN

We require treating multiple tables as though they were a single entity. Then a single SQL sentence can manipulate data from the all the tables. To achieve this, we have to join tables.
In EQUI JOIN, the tables are joined on the basis of the column having same data type and same data width. Such columns is specified in the WHERE clause. The two tables are joined using equality operator (=).

SYNTAX: -

SELECT * FROM
WHERE.=.


In this the tables can be different. That is both the tables are different but have one field same on the basis of which the tables are joined.

(3) OUTER JOIN


Sometimes we might want to see the data from one table, even if there is no corresponding row in the joining table. Oracle provides the outer join mechanism for this. Such rows can be forcefully selected by using the outer join symbol (+). The corresponding columns for that will have Null’s. The outer join symbol is placed on the side of the join that is deficient in information. This operator has the effect of creating one or more null rows, to which one or more rows from the no deficient table can be joined.

SYNTAX: -
SELECT * FROM
WHERE.columnname>+=.
Or
SELECT * FROM
WHERE.columnname>=.(+)

Rules to Place (+) operator


The outer join symbol (+) cannot be on both sides.

We cannot “ outer join” the same table to more than one other table in a single SELECT statement.

A condition involving an outer join may not use the IN operator or be linked to another condition by the OR operator.

(4) NON-EQUI JOIN

If any other operator instead of equality operator (=) is used to join the tables in the query, it is Non-Equi Join.

SYNTAX: -


SELECT * FROM
WHERE .
.

(5) CARTESIAN JOIN

When the join condition is omitted, the result is the Cartesian join of two or more tables in which all combinations of rows will be displayed. All the rows of the first table are joined to al rows of the second table. This kind of join tends to generate a large number of rows, as it involves no condition.

This join is useful in finding all the possible combination of rows from different tables. This join does not require the tables to have common column between them.

SYNTAX: -

SELECT columnname1, columnname2…
FROM tablename1, tablename2

ORACLE FUNCTIONS

ORACLE FUNCTIONS

Oracle functions serve the purpose of manipulating data items and returning a result. Functions are also capable of accepting user-supplied variables or constants and operating on them. Such variables or constants are called as arguments. Any number of arguments (or no arguments at all) can be passed to a function in the following format:

Function_name (argument1, argument2…)


ORACLE functions can be clubbed together depending upon whether they operate on a single row or a group of rows retrieved from a table. Accordingly, functions can be classified as follows:

Group functions (Aggregate functions)
Scalar functions (Single row functions)


GROUP FUNCTIONS (Aggregate functions)

Functions that act on a set of values are called as group functions. For example, SUM, is a function, which calculates the total of a set of numbers. A group functions returns single result row for a group of queried rows.

SCALAR FUNCTIONS (Single row functions)


Functions that act on only one value at a time are called as scalar functions. For example, LENGTH is a function, which calculates the length of one particular string value. A single row function returns one result for every row of a queried table or view.

Single row functions can be further grouped together by the data type of their arguments and return values. For example, LENGTH relates to the string data type. Functions can be classified corresponding to different data types as:


String functions : work for string data type
Numeric functions : work for number data type
Conversion functions : work for conversion of one data type to another
Date functions : work for date data type


AGGREGATE FUNCTIONS

(1) AVG

PURPOSE: -

Returns average value of ‘n’, ignoring null values.
SYNTAX: -
AVG (DISTINCT [ALL] n)

EXAMPLE: -

SQL> SELECT AVG (amount)"AVERAGE" FROM banking1;
OUTPUT: -
AVERAGE
---------
675098

(2)MIN

PURPOSE: -

Returns minimum value of ‘expr’
SYNTAX: -
MIN ([DISTINCT|ALL] expr)

EXAMPLE: -

SQL>SELECT MIN (amount)"MINIMUM BALANCE" FROM banking1;
OUTPUT: -
MINIMUM BALANCE
---------------
50000

(3) COUNT (expr)

PURPOSE: -
Returns the number of rows where ‘expr’ is not null.
SYNTAX: -
COUNT [(DISTINCT\ALL] expr)
EXAMPLE: -
SQL> SELECT COUNT (name)"name" FROM banking1;
OUTPUT: -
Name
---------
4

(4) COUNT (*)

PURPOSE: -
Returns the number of rows in the table, including duplicates and those with nulls.

SYNTAX: -

COUNT (*)

EXAMPLE: -
SQL> SELECT COUNT (*)"amount" FROM banking1;

OUTPUT: -

Amount
---------
4


(5) MAX

PURPOSE: -
Returns the maximum value of ‘expr’

SYNTAX: -
MAX [(DISTINCT | ALL] expr)

EXAMPLE: -
SQL> SELECT MAX (amount) " MAXIMUM " FROM banking1;

OUTPUT: -
MAXIMUM
---------------
90000

(6) SUM

PURPOSE: -
Returns sum of values of ‘n’

SYNTAX: -
SUM [DISTINCT | ALL] n)

EXAMPLE: -
SQL> SELECT SUM (amount) "TOTAL BALANCE" FROM banking1;

OUTPUT: -
TOTAL BALANCE
-------------
270000

NUMERIC FUNCTIONS

(1) ABS

PURPOSE: -
Returns the absolute value of ‘n’
SYNTAX: -
ABS (n)
EXAMPLE: -
SQL> SELECT ABS (-27) " ABSOLUTE" FROM dual;
OUTPUT: -
ABSOLUTE
---------
27

(2) POWER


PURPOSE: -
Returns ‘m’ raised to ‘nth’ power. ‘n’ must be an integer, else an error is returned.
SYNTAX: -
POWER (M, N)
EXAMPLE: -
SQL> SELECT POWER (7,2)"RAISED" FROM dual;
OUTPUT: -
RAISED
---------
49

(3) ROUND

PURPOSE: -
Returns ‘n’ rounded to ‘m’ places right of the decimal point. If ‘m’ is omitted, ‘n’ is returned to 0 places. ‘m’ can be negative to round off digits left of the decimal point. ‘m’ must be an integer.
SYNTAX: -
ROUND (n [, m])
EXAMPLE: -
SQL> SELECT ROUND (27.268,2) " ROUND" FROM dual;
OUTPUT: -
ROUND
---------
27.27

(4) SQRT

PURPOSE: -

Returns square root of ‘n’, if ‘n’<0, style="font-weight: bold;">SYNTAX: -
SQRT (n)

EXAMPLE: -
SQL> SELECT SQRT (900)" SQUARE ROOT" FROM dual;

OUTPUT: -

SQUARE ROOT
------------
30

(5)COS

PURPOSE: -

Returns the cosine of the ‘n’.

SYNTAX: -
COS (n)

EXAMPLE: -
SQL> SELECT COS (0) FROM dual;

OUTPUT: -
COS (0)
---------
1

(6) SIN

PURPOSE: -

Return the sin of the ‘n’.

SYNTAX: -

SIN (n)

EXAMPLE: -

SQL>SELECT SIN (0) FROM dual;

OUTPUT: -

SIN (0)
----------
0

STRING FUNCTIONS


(1) LOWER

PURPOSE: -
Returns char, with all letters in lowercase.
SYNTAX: -
LOWER (char)
EXAMPLE: -
SQL>SELECT LOWER (‘RIMS’) “LOWER” FROM dual;
OUTPUT: -
LOWER
----
rims

(2) UPPER

PURPOSE: -
Returns char, with all letters forced to uppercase.

SYNTAX: -
UPPER( char)

EXAMPLE: -

SQL> SELECT UPPER (‘Smarim’)”TITLE CASE” FROM dual;
OUTPUT: -
TITLE
------
SMARIM


(3) LENGTH

PURPOSE: -

Returns the length of character.

SYNTAX: -
LENGTH (char)

EXAMPLE: -
SQL> SELECT LENGTH (‘LOVABLE’)”LENGTH” FROM dual;
OUTPUT: -
LENGTH
---------
7

(4) LTRIM

PURPOSE: -

Removes characters from the left of char with initial characters removed up to the first character not in set.

SYNTAX: -
LTRIM (char {, set])

EXAMPLE: -
SQL> SELECT LTRIM ('ASMARAG','A')"LEFT TRIM" FROM dual;
OUTPUT: -
LEFT TRIM
------
SMARAG

(5) RTRIM

PURPOSE: -
Returns char, with final characters removed after the last character not in the set. ‘ Set’ is optional, it defaults to spaces.

SYNTAX: -

RTRIM ( char, [set])

EXAMPLE: -
SQL>SELECT RTRIM ('SMARAGA','A')"RIGTH TRIM" FROM dual;
OUTPUT: -
RIGTH TRIM
----------------
SMARAG

(6) LPAD

PURPOSE: -
Returns ‘char1’, left added to length ‘n’ with the sequences of characters in ‘char2’,’char2’ defaults to blanks.

SYNTAX: -
LPAD (char1, n, [, char2])

EXAMPLE: -
SQL> SELECT LPAD ('SMAR', 10,'*')"LPAD" FROM dual;
OUTPUT: -
LPAD
-----------------
******SMAR

(7) RPAD

PURPOSE: -

Returns ‘char1’, right-padded to length ‘n’ with the characters. In ‘char2’, replicated as many times as necessary. If ‘char2’, is omitted, right-pad is with blanks.
SYNTAX: -
RPAD (char1, n [char2])

EXAMPLE: -
SQL> SELECT RPAD ('SMAR', 10,'^')"RPAD" FROM dual;
OUTPUT: -
RPAD
----------------
SMAR^^^^^^

CONVERSION FUNCTIONS


(1) TO_NUMBER

PURPOSE: -
Converts ‘char’ a CHARACTER value containing a number, to a value of NUMBER data type.

SYNTAX: -
TO_NUMBER (char)

EXAMPLE: -

SQL>UPDATE banking1
SETamount=amount +
TO_NUMBER (SUBSTR ('$100',2,3));

(2) TO_CHAR

PURPOSE: -
Converts the value of NUMBER data type to a value of CHAR data type, using the optional format string. It accepts a number (n) and a numeric format (fmt) in which the number has to appear. If (fmt) is omitted, ‘n’ is converted to a char value exactly long enough to hold significant digits.

SYNTAX: -
TO_CHAR (n [, fmt])

EXAMPLE: -
SQL> SELECT TO_CHAR (17145,'$099,999')"CHAR" FROM dual;

OUTPUT: -

CHAR
---------
$017,145

(3) TO_CHAR (Date Conversion)


PURPOSE: -

Converts the value of DATE data type to CHAR value. It accepts date (date), as well as the format (fmt) in which the date has to appear. ‘fmt’ must be a date format. If ‘fmt’ is omitted, ‘date’ is converted to a character value in the default date format, i.e. “DD-MON-YY”.

SYNTAX: -

TO_CHAR (date [, fmt])

EXAMPLE: -

SQL> SELECT TO_CHAR (SYSDATE,'Month DD, YYYY’)
"NEW DATE FORMAT" FROM dual;

OUTPUT: -
NEW DATE FORMAT
-----------------
March 25,2008

DATE CONVERSION FUNCTIONS


The DATE data type is used to store date and time format. The DATE data type has special properties associated with it. It stores information about century, year, month, day, hour, minute and second for each date value.


The value in the column of a DATE data type is always stored in a specific DEFAULT format. This default format is ‘DD-MM-YY HH:MM: SS’. Hence, when a date has to be inserted in the date field, its value has to be specified in the same format. Also, values of DATE columns are displayed in the default format when retrieved from the table.


The same function can be used for inserting a date into a DATE field in a particular format. This can be achieved by specifying the date value, along with the format in which it is to be inserted. This function also allows part insertion of a DATE, for example, only the day and month portion of the value.


To enter the time portion of a date, the TO_DATE function must be used with a FORMAT MASK indicating the time portion.

(1)TO_DATE


PURPOSE: -

Converts a character field to a date field.

SYNTAX: -

TO_DATE ( char [, fmt ])

EXAMPLE: -
SQL> SELECT TO_DATE ('20-MAR-06','DD-MM-YY')"DISPLAY”
FROM dual;

OUTPUT: -

DISPLAY
---------
20-MAR-08

DATE FUNCTIONS

To manipulate and extract values from the date column of a table some date functions have been provided by ORACLE. These are: -

(1) ADD_MONTHS

PURPOSE: -
Returns date after adding the number of months specified with the functions.

SYNTAX: -
ADD_MONTHS (d,n)

EXAMPLE: -

SQL> SELECT ADD_MONTHS (SYSDATE, 4) FROM dual;

OUTPUT: -
ADD_MONTH
---------
25-JUL-06

(2) LAST_DAY


PURPOSE: -

Return the last date of the month specified with the function.

SYNTAX: -
LAST_DAY (d)

EXAMPLE: -
SQL> SELECT SYSDATE, LAST_DAY (SYSDATE) "LAST DAY"
FROM dual;
OUTPUT: -
SYSDATE LAST DAY
------------- -------------
25-MAR-06 31-MAR-06

DUAL TABLE

DUAL TABLE
Dual is a small Oracle worktable, which consists of only one row and one column, and contains the value X in that column. Besides arithmetic calculations, it also supports date retrieval and it’s formatting.
Often a simple calculation needs to be done, for example, 4*4. The only SQL verb to cause an output to be written to a VDU screen is SELECT. However, a SELECT must use a table name in its FROM clause, otherwise the SELECT fails.

When an arithmetic exercise is to be performed such as 4*4 or $/2 etc, there really is no table being referenced, only numeric literals are being used.

To facilitates such calculations via a SELECT, Oracle provides a dummy table called DUAL, against which SELECT statements that are required to manipulate numeric literals can be fired, and output obtained.

EXAMPLE: -
SQL> SELECT 16/2 from DUAL;

OUTPUT: -
16/2
---------
8
SYSDATE
SYSDATE is a pseudo column that contains the current date and time. It requires no arguments when selected from the table DUAL and returns the current date.
EXAMPLE: -
SQL> SELECT sysdate from DUAL;

SYSDATE
---------
20-April-05

ARITHMETIC OPERATORS

ARITHMETIC OPERATORS

Oracle allows arithmetic operators to be used while viewing records from the table or while performing Data Manipulations operations such as Insert, Update, and Delete.

These are: -

+ Addition
* Multiplication
- Subtraction
** Exponentiation
/ Division
( ) Enclosed operation


LOGICAL OPERATOR


Logical operators that can be used in SQL sentences are: -

The AND operator:
The Oracle engine will process all rows in a table and display the result only when all of the conditions specified using the AND operator are satisfied.
EXAMPLE: -
SQL> SELECT order_no, client_no, order_date, sale_amount
FROM sales_order
WHERE sale_amount>=10000 AND sale_amount<=50000;

The OR operator:
The Oracle engine will process all rows in a table and display the result only when any of the conditions specified using the OR operator are satisfied.

EXAMPLE: -

SQL> SELECT order_no, client_no, order_date, sale_amount
FROM sales_order
WHERE (client_no=C0003 OR client_no=C0005);


The NOT operator:

The Oracle engine will process all rows in table and display the result only when none of the conditions specified using the NOT operator are satisfied.
EXAMPLE: -

SQL>SELECT order_no, client_no, sale_amount
FROM sales_order
WHERE NOT (sale_amount=20000 OR sale_amount=50000);


RANGE SEARCHING

In order to select data that is within range of values, the BETWEEN operator is used. The BETWEEN operator allows the selection of rows that contains values within a specified lower and upper limit. The range coded after the word BETWEEN in inclusive.
The lower value must be coded first. The two values in between the range must be linked with the keyword AND. A BETWEEN operator can be used with both character, numeric data types. However, one cannot mix the data types i.e. the lower value of the range of values from character column and the other from a numeric column.
EXAMPLE: -
SQL> SELECT order_no, client_no, sale_amount
From sales_order
WHERE order_noBETWEEN'O191002' and 'O191005';

CONSTRAINTS

CONSTRAINTS

The oracle server uses constraints to prevent invalid data entry into tables. Constraints prevent the deletion of a table if there are dependencies. The following constraints types are valid :
(1) NOT NULL
(2) UNIQUE
(3) PRIMARY KEY
(4) FOREIGN KEY
(5) CHECK


DATA CONSTRAINTS


Rules which are enforced on data being entered, and prevents the user from entering invalid data into tables are called CONSTRAINTS. Thus, constraints super control data being entered in tables for permanent storage.

Oracle permits data constraints to be attached to table columns via SQL syntax that will check data for integrity. Once data constraints are part of a table column construction, the Oracle engine checks the data being entered into a table column against the data constraints. If the data passes this check, it is stored in the table fails a constraint, the entire record is rejected and not stored in the table.

Once a constraint is attached to a table column, any SQL insert or update statement causes these constraints to be applied to the data prior to it being inserted into the tables for storage.

TYPES OF DATA CONSTRAINTS

I / O CONSTRAINTS

This data constraint determines the speed at which data can be inserted or extracted from an Oracle table.

The input / output constraint, is further divided into two distinctly different constraints.
Primary Key Constraint
Foreign Key Constraint
In addition to primary and foreign key, Oracle has NOT NULL and UNIQUE as column constraints.

Constraints can be connected to a column or a table by the CREATE TABLE or ALTER TABLE command.

Oracle allows programmers to define constraints at:
Column level
Table level

COLUMN LEVEL CONSTRAINT

If data constraints are defined along with the column definition when creating or altering a table structure, they are column level constraints.

Column level constraints are applied to the current column. The current column is the column that immediately precedes the constraint i.e. they are local to a specific column. A column level constraint cannot be applied if the data constraint spans across multiple columns in a table.

TABLE LEVEL CONSTRAINT

If data constraints are defined after defining all the table columns when creating or altering a table structure, it is a table level constraint.

Table level constraint must be applied if the data constraint spans across multiple columns in a table. Constraints are stored as a part of the global table definition by the Oracle engine in its system tables.

NULL VALUE CONCEPT

The NULL values are clubbed at the top of the column in the order in which they were entered into the table. A NULL value is different from a blank or a zero.
NULL values are treated specially by Oracle. A NULL value can be inserted into the columns of any data type.

NOT NULL CONSTRAINT
When a column is defined as NOT NULL, then that column becomes a mandatory column. It implies that a value must be entered into the column if the record is to accept for storage in the table.
The NOT NULL constraint can only be applied at column level. Although NOT NULL can be applied as be check constraint, however Oracle recommends that this be not done.

SYNTAX: -
Columnname datatype (size) NOT NULL

EXAMPLE: -
Create a table Emp with the following mandatory Fields:
Empno,Ename,job,sal and deptno columns.
SQL> CREATE TABLE Emp
(Empno number(4) NOT NULL,
Ename varchar2(10),
job varchar2(9),
sal number(7,2),
deptno number(2));


Table created.

THE UNIQUE CONSTRAINT

The purpose of a unique key is to ensure that information in the column(s) is unique, i.e. a value entered in column(s) defined in the unique constraint must not be repeated across the column(s). A table may many UNIQUE KEYS.

The UNIQUE COLUMN constraint permits multiple entries on the NULL value into the column.

UNIQUE constraint defined at the column level

SYNTAX: -
Columnname datatype(size) UNIQUE

THE PRIMARY KEY CONSTRAINT


A primary key is one or more column(s) in a table used to uniquely identify each row in the table.
A primary key column in a table has special attributes:
It defines the column, as a mandatory column i.e. the column cannot be left blank. The NOT NULL attributes are active.
The data held across the column MUST be UNIQUE.


A single column primary key is called as simple key. A multicolumn primary key is called a composite primary key. The only function of a primary key in a table is to uniquely identify a row. Only when a record cannot be uniquely identified using the value in a single column, will a composite primary key be defined.

The data constraint attached to a table column (or columns) ensure:
That the data entered in the table column (or columns) is unique across the entire column (or columns).

PRIMARY KEY constraint defined at the column level


SYNTAX: -

Columnname datatype (size) PRIMARY KEY

PRIMARY KEY constraint defined at the table level

SYNTAX: -

PRIMARY KEY (columnname[, columnname,……])

THE FOREIGN KEY CONSTRAINT


Foreign key represent relationships between tables. A Foreign key is a column whose values are derived from the PRIMARY KEY or UNIQUE KEY of some other table.
The table in which the foreign key is defined is called a FOREIGN TABLE or DETAIL TABLE. The table that defines a PRIMARY KEY or UNIQUE KEY and is referenced by the foreign key is called PRIMARY TABLE or MASTER TABLE.
This constraint establishes a relationship between records across a Master and Detail table.
This relationship ensure:
Records cannot be inserted into a detailed table if corresponding records in the master table do not exist.
Records of the master table cannot be deleted if corresponding records in the detail table exist.
The existence of a foreign key implies that the table with the foreign key is related to the Master table from which the foreign key is derived. A foreign key must have a corresponding PRIMARY KEY or UNIQUE KEY value in the master table.

FOREIGN KEY constraint defined at the column level


SYNTAX: -

Columnname datatype (size) REFERENCES Tablename[(columnname)]
[ON DELETE CASCADE]

FOREIGN KEY constraint defined at the table level

SYNTAX: -
FOREIGN KEY (columnname [, columnname])
REFERENCES tablename [(columnname [, columnname])

DROPPING INTEGRITY CONSTRAINT


We can drop an integrity constraint if the rule that if enforces is no longer true or if the constraints is no longer needed. Drop the constraint using the ALTER TABLE command with DROP clause.

EXAMPLE: -

Drop the PRIMARY KEY constraint from friend

ALTER TABLE friend
DROP PRIMARY KEY;

Drop FOREIGN KEY constraint on column city in table friend.

ALTER TABLE friend
DROP CONSTRAINT city;

DELETE OPERATIONS used in SQL

DELETE OPERATIONS
The verb DELETE in SQL is used to remove rows from table.

To remove
All the rows from a table. Or
A select set of rows from a table.

1) Delete all rows from the table

SYNTAX: -
DELETE FROM tablename;
EXAMPLE: -
SQL> delete from banking;


2) Removal of specified rows from the table.

SYNTAX: -
DELETE FROM tablename WHERE search condition;

EXAMPLE: -
SQL> delete from banking where amount<80000;


UPDATING THE CONTENTS OF A TABLE

The UPDATE command is used to change or modify data values in a table.

To update
All the rows from the table Or
A select set of rows from a table.

Updating of all rows:

SYNTAX: -
UPDATE tablename
SET columnname=expression, columnname=expression;

Updating records conditionally:


SYNTAX: -

UPDATE tablename
SET columnname=expression, columnname=expression…….
WHERE columnname=expression;

MODIFYING THE STRUCTURE OF THE TABLE
This command is used to add new columns or to change the data type and size of columns.
The verb ALTER in SQL is used to modify the table structure.
Adding new columns:

SYNTAX: -
ALTER TABLE tablename
ADD(new columnname datatype(size),new columnname datatype(size));

EXAMPLE: -
SQL> alter table banking add(branchno number(10,0),fathername varchar2(20));

Table altered.

Modifying existing columns:


SYNTAX: -
ALTER TABLE tablename
MODIFY (columnname new datatype (newsize));

EXAMPLE: -
SQL> alter table banking modify (branchno varchar2(10));


RENAMING TABLE


This command is used to rename the table.
SYNTAX: -
RENAME oldtablename TO newtablename;
EXAMPLE: -
SQL> rename banking to banking1;

Table renamed.

DESTROYING TABLES
This command is used to destroy the table.

SYNTAX: -
DROP TABLE tablename;
EXAMPLE: -
SQL> drop table banking1;

Table dropped.

COMMANDS USED IN A TABLE

COMMANDS USED IN A TABLE:-

CREATE TABLE COMMAND
The CREATE TABLE command includes a single clause for the column definition. Each column is a parameter for the clause and thus it is separated by comma.

SYNTAX: -
CREATE TABLE tablename
( columnname datatype(size), columnname datatype (size));
EXAMPLE: -
SQL>CREATE table banking(name varchar2(10), address archar2(20), accountno number(10,0), amount number(10,0),id varchar2(10));

Table created.

INSERTION OF DATA INTO TABLES

Once a table is created the most natural thing to do is load this table with data to be manipulated later.
When inserting a single row of data into the table, the insert operation: -
Creates a new row in the database table
Loads the values passed into all the columns specified.

SYNTAX: -

INSERT INTO tablename(columnname, columnname)
VALUES (expression, expression);

EXAMPLE: -

SQL> insert into banking(name,address,accountno,amount,id) values ('ABC','899-House',27207,90000,'10900');
1 row created.

VIEWING DATA IN THE TABLE
Once data has been inserted into a table, the next most logical operation would be to view what has been entered. The ‘SELECT’ SQL verb is used to achieve this.

(1) All rows and all columns:

When data from certain rows and column from table is to be viewed.

SYNTAX: -

SELECT (columnname1……….columnname n) FROM tablename;

EXAMPLE: -
SQL> select name, address,id from banking;


(2) When data from all rows and columns from table are to be viewed.


SYNTAX: -
SELECT * FROM tablename;

EXAMPLE: -
SQL> select * from employee;

3)With Where Condition
SYNTAX: -

SELECT * FROM tablename WHERE search conditions;

EXAMPLE: -
SQL> select * from banking where accountno > 290;


4) SYNTAX: -
SELECT columnname, columnname
FROM tablename
WHERE search condition;

EXAMPLE: -
SQL> select accountno, amount,id from banking where amount>60000;

Categories of SQL statements

Categories of SQL statements:-

SQL is a simple and powerful language used to create, access, and manipulate data and structure in the database. SQL statements into various categories, which are:

Data Definition Language
Data Manipulation Language
Transaction Control Statements
Data Control Language


DATA RETRIEVAL:- SELECT

DATA MANIPULATION LANGUAGE (DML):- INSERT, UPDATE, DELETE, MERGE

DATA DEFINITION LANGUAGE (DDL):- CREATE, ALTER, DROP , RENAME, TRUNCATE

TRANSACTION CONTROL:- COMMIT, ROLLBACK ,SAVEPOINT

DATA CONTROL LANGUAGE (DCL):- GRANT,
REVOKE

(1) DATA DESCRIPTION LANGUAGE (DDL) STATEMENTS


DDL statements are used to define, alter or drop database objects. The following table gives an overview about usage of DDL statements in ORACLE.
The commands used are: -

CREATE:- Used to create table having rows and columns
ALTER:- Used to alter the structure of the database object
DELETE:- Used to delete the database objects.
RENAME:- Used to rename the database objects.

DATA MANIPULATION LANGUAGE (DML) STATEMENTS

DML statements enable users to query or manipulate data in existing objects. DML statements are normally the most commonly used commands.
The commands used are: -

DELETE:- It removes rows from the database objects
INSERT:- It adds new rows of data to database objects.
SELECT:- It retrieves data from one or more tables.
UPDATE:- It changes column values in existing rows of database objects.

DATA CONTROL LANGUAGE (DCL) STAEMENTS


The SQL sentences used to control the behavior of objects are called data control statements.
The commands used are:

GRANT:- Grant statements provide access to various tables.
REVOKE:- Revoke statement is used to deny the grant.

TRANSACTION CONTROL LANGUAGE (TCL) STATEMENTS

TCL statements manage the change made by DML statements and group DML statements into transactions. The SQL statements used to control various transactions are called transaction control statement.
The commands used are: -

COMMIT:- Make a transaction’s changes permanent.
ROLLBACK:- Undo changes in a transaction, either since the transaction started or since a save point.

DATA TYPES THAT A CELL CAN HOLD

DATA TYPES THAT A CELL CAN HOLD

Data Types:-

CHAR (Size):- This data type is used to store character strings values of fixed length. The size in brackets determines the number of characters the cell can hold. The maximum number of characters this data type can hold is 255 characters

VARCHAR (size) / VARCHAR2 (size):-
This data type is used to store variable length alphanumeric data. The maximum this data type can hold is 2000 characters

NUMBER (P,S):-
The NUMBER data type is used to store numbers. Numbers of virtually any magnitude maybe stored up to 38 digits. The precision (P), determines the maximum length of the data, whereas the scale (S), determines the number of places to the right of the decimal. If scale is omitted then the default is zero.If the values are stored with their original precision up to the maximum of 38 digits.

DATE:- This data type is used to represent date and time.

STRUCTURED QUERY LANGUAGE

SQL (STRUCTURED QUERY LANGUAGE)

SQL is an ANSI (American National Standards Institution) standard for accessing database system. SQL is a simple and powerful language used to create, access, and manipulate data and structure in the databases. SQL is like plain English, easy to write and understands. SQL statements are used to retrieve and update data in a database.
SQL works with database programs like MS Access, DB2, Informix, MS SQL Server, Oracle, Sybase, etc.

FEATURES OF THE SQL


SQL stands for Structured Query Language.
SQL allows you to access a database.
SQL is an ANSI standard.
SQL can execute queries against the database.
SQL can retrieve data from the database.
SQL can insert new records in the database.
SQL can delete records from the database.
SQL can update the records in the database.
SQL is easy to learn.

Addition of polynomials

// Addition of polynomials //

#include
#include
#define NULL 0
struct list
{
int coeff ;
int power ;
struct list *next;
};
typedef struct list poly;
void create(poly *t)
{
cout<<"Enter coeff :";
cin>>t->coeff;
if(t->coeff==0)
{
t->next=NULL;
}
else
{
cout<<"Enter power:";
cin>>t->power;
t->next=new poly;
create(t->next);
}
return;
}
void display(poly *t)
{
if(t->next!=NULL)
{
cout<coeff<<"X^"<power<display(t->next);
}
return;
}
poly *add(poly *t1,poly *t2)
{
poly *r=new poly;
poly *st=r;
poly *addcreate(int,int,poly *);
while(t1->next!=NULL && t2->next!=NULL)
{
if(t1->power==t2->power)
{
if(t1->coeff>coeff!=0)
{
r=addcreate(t1->power,t1->coeff>coeff,r);
t1=t1->next;
t2=t2->next;
}
}
else if(t1->power>t2->power)
{
r=addcreate(t1->power,t1->coeff,r);
t1=t1->next;
}
else
{
t=addcreate(t2->power,t2->coeff,r);
t2=t2->next;
}
}
if(t1->next!=NULL && t2->next==NULL)
while(t1->next!=NULL)
{
r=addcreate(t1->power,t1->coeff,r);
t1=t1->next;
}
if(t1->next==NULL&&t2->next!=NULL)
while(t1->next!=NULL)
{
r=addcreate(t2->power,t2->coeff,r);
t2=t2->next;
}
r->next=NULL;
return(st);
}
poly *addcreate(int n,int c,poly *t)
{
t->power=n;
t->coeff=c;
t->next-new poly;
return(t->next);
}
int main()
{
poly *p1,*p2,*result;
void create(poly *);
void display(poly *);
poly *add(poly *,poly *);
clrscr();
cout<<"\nEnter the first polynomial\n";
p1=new poly;
create(p1);
cout<<"\nEnter the second polynomial\n";
p2=new poly;
create(p2);
cout<<"\nThe first polynomial is\n";
display(p1);
cout<<"\nThe second polynomial is\n";
display(p2);
result=add(p1,p2);
cout<<"\nAddition of two polynomial is \n";
display(result);
getch();
return(0);
}

Binary search

// Binary search //

#include
#include
#define NULL 0
struct rec
{
int num;
struct rec *left;
struct rec *right;
};
typedef struct rec node;
node *insert(node *,int);
void search(node *,int);
void preorder(node *);
void inorder(node *);
void postorder(node *);
int select()
{
int selection;
do
{
clrscr();
cout<<"--> MENU <--" << endl;
cout<<"1->Insert a node in BST" << endl;
cout<<"2->Search a node in BST" << endl;
cout<<"3->Preorder traversal of BST" << endl;
cout<<"4->Inorder traversal of BST"<< endl;
cout<<"5->Postorder traversal of BST"<< endl;
cout<<"6->Delete a node in BST"<< endl;
cout<<"Enter ur choice:"; cin>>selection;
if(selection<1||selection>7)
{
cout<<"Invalid choice.\nTryagain.";
getch();
}
}
while(selection<1||selection>7);
return(selection);
}
node *insert(node *tree,int digit)
{
if(tree==NULL)
{
tree=new node;
tree->left=tree->right=NULL;
tree->num=digit;
}
else if(digitnum)
tree->left=insert(tree->left,digit);
else if(digit>tree->num)
tree->right=insert(tree->right,digit);
else {
cout<<"Duplicate node not allowed";
getch();
}
return(tree);
}
void inorder(node *tree)
{ if(tree!=NULL)
{ inorder(tree->left);
cout <<>num;
inorder(tree->right);
}
return;
}
void preorder(node *tree)
{
if(tree!=NULL)
{
cout<<>num;
preorder(tree->left);
preorder(tree->right);
}
return;
}
void postorder(node *tree)
{
if(tree!=NULL)
{
postorder(tree->left);
postorder(tree->right);
cout <<>num;
}
return;
}
void search(node *tree,int digit)
{
if(tree==NULL)
{
cout<<"The node doesn't exist"; }
else if(digit==tree->num)
{
cout<<"The node exists:"; }
else if(digitnum)
search(tree->left, digit);
else
search(tree->right, digit);
getch();
return;
}
void locate(node *root,node **par,node **cur,int x,int *found)
{
*found=1;
if(x==root->num)
{
*cur=root;
*found=0;
return;
}
*par=root;
if(xnum)
locate(root->left, &(*par), &(*cur),x,found);
else
locate(root->right, &(*par), &(*cur),x,found);
return;
}
void del(node *tree,int x)
{
node *par,*cur, *xsucc;
int found;
if(tree==NULL)
{
cout<<"Tree is empty (UNDERFLOW)";
getch();
return;
}
locate(tree, &par, &cur,x,&found);
if(found==1)
{
cout<<"Node doesn't exist"; getch(); return;
}
if(cur->left!=NULL && cur->right!=NULL)
{
par=cur;
xsucc=cur->right;
while(xsucc->left!=NULL)
{
par=xsucc;
xsucc=xsucc->left;
}
cur->num=xsucc->num;
cur=xsucc;
}
if(cur->left==NULL && cur->right!=NULL)
{
if(par->left==cur)
par->left=cur->right;
else
par->right=cur->right;
delete cur;
return;
}
if(cur->left!=NULL && cur->right==NULL)
{
if(par->left==cur)
par->left=cur->left;
else
par->right=cur->left;
delete cur;
return;
}
if(cur->left==NULL && cur->right==NULL)
{
if(par->left==cur)
par->left=cur->left;
else
par->right=cur->right;
delete cur;
return;
}
}
int main()
{
node *tree=NULL;
int temp,choice;
do
{
choice=select();
switch(choice)
{
case'1':
cout<<"Enter the value for node:"; cin>>temp;
tree=insert(tree,temp);
break;
case'2':
cout<<"Enter node to search:"; cin>>temp;
search(tree,temp);
break;
case'3':
preorder(tree);
getch();
break;
case'4':
inorder(tree);
getch();
break;
case'5':
postorder(tree);
getch();
break;
case'6':
cout<<"Enter the node to delete:";
cin>>temp;
del(tree,temp);
break;
case'7':
cout<<"Exiting";
break;
}
{
while(choice!=7);
getch();
return(0);
}

Program to implement stack using linked list

//Program to implement stack using linked list//

#include "stdio.h"
#include "conio.h"
#include "alloc.h"
struct stack
{
int info;
struct stack *next;
};
typedef struct stack node;
class stlink
{
node *start;
public:
stlink()
{
start=NULL;
}
void display(void);
void push(int);
int pop(void);
};
void stlink::push(int term)
{
node *p,*s;
s=start;
if(s==NULL||s!=NULL)
{
p=(node *)malloc(sizeof(node));
p->info=term;
p->next=s;
s=p;
}
start=s;
return;
}
void stlink::display(void)
{
node *temp;
if(start==NULL)
{
cout << endl<<"UNDERFLOEW";
}
temp=start; while(temp!=NULL)
{ cout <<>info;
temp=temp->next;
}
return;
}
int stlink::pop(void)
{
int term;
if(start==NULL)
{
cout<<"UNDERFLOW"; return(-1); } else { node *p; term=start->info;
p=start;
free(start);
start=p->next;
return(term);
}
}
int main()
{
stlink s1;
int ch,temp;
do
{
clrscr();
cout<<"1->Push\n";
cout<<"2->Display\n";
cout<<"3->Pop\n";
cout<<"4->Exit\n";
cout<<"Enter your choice:"; cin>>ch;
switch(ch)
{
case'1':
cout<<"Enter the term to push:"; cin>>temp;
s1.push(temp);
break;
case'2':
cout << endl<<"Stack";
s1.display();
getch();
break;
case'3': temp=s1.pop();
if(temp!=-1) cout<<"Popped term is " << temp;
getch();
break; case'4': cout<<"Exiting";
getch();
break; default: cout<<"Invalid choice";
getch();
break; }
}
while(ch!=4); return(0);
}

To implement stacks using array

//To implement stacks using array//

#include "iostream.h"
#include"conio.h"
#include"ctype.h"
#define SIZE 10
class stack
{
private:
int stck[SIZE];
int top;
public:
stack()
{
top=-1;
}
void push(int);
int pop(void);
int IsEmpty(void);
};
void stack:: push(int term)
{
if(top==SIZE-1)
{
cout<<"OVERFLOW";
getch();
} else stck[++top]=term;
}
int stack::pop(void)
{ return(stck[top--]);
}
int stack::IsEmpty(void)
{ if(top==-1) return(1);
else return(0); }
int main(void)
{ stack s; char choice; int term;
do
{ clrscr();
cout<<"-> MENU <-" <<> Push" <<> Pop" <<> Exit" <<>>choice;
choice=toupper(choice);
clrscr();
switch(choice)
{
case 'P':
cout<<"Enter the term to push:"; cin>>term;
s.push(term);
break;
case 'O':
if(s.IsEmpty())
cout<<"UNDERFLOW";
else cout<<"Popped term is " << s.pop();
getch();
break;
case 'E': cout<<"Exiting";
getch();
break;
default:
cout<<"Not a valid choice";
getch();
break; }
}
while(choice!='E');
return(0);
}

Program of tower of Hanoi

// Program of tower of Hanoi //

#include"iostream.h"
#include"conio.h"
int main()
{
int n;
char beg='a',aux='b',end='c';
void tower(int,char,char,char);
clrscr();
cout<<"Enter the no. of disks:"; cin>>n;
tower(n,beg,aux,end);
getch();
return(0);
}
void tower(int n,char beg,char aux,char end)
{
if(n==1)
{
cout <<>" << end<<"\t"; return;
}
tower(n-1,beg,end,aux);
cout <<>" << end<<"\t";
tower(n-1,aux,beg,end);
}

Implementing queue with arrays

//Implementing queue with arrays//

#include"iostream.h"
#include"conio.h"
#define NIL -1
#define MAX 10
typedef struct
{
int terms[MAX];
int front,rear;
}que;
class queue
{
que *q;
public:
queue()
{
q->front=NIL;
q->rear=NIL;
}
void create(int);
int del(void);
void display(void);
};
void queue::create(int x)
{
int i;
que *t=q;
if((t->front==0) && (t->rear==MAX-1))
{
cout<<"OVERFLOW"; getch(); return; } if(t->front==NIL)
t->front=t->rear=0;
else if(t->rear==MAX-1)
{
for(i=t->front;i<=t->rear;i++)
t->terms[i-t->front]=t->terms[i];
t->rear=t->rear-t->front+1;
t->front=0;
}
else
t->rear++;
t->terms[t->rear]=x;
return;
}
void queue::display(void)
{
if((q->front==NIL)&&(q->rear==NIL))
{
cout<<"UNDERFLOW"; return; } for(int i=q->front;i<=q->rear;i++)
cout <<>terms[i];
return;
}
int queue::del(void)
{
int n;
que *t=q;
if((q->front==NIL)&&(q->rear==NIL))
{
cout<<"UNDERFLOW"; return(-1); } n=t->terms[t->front];
if(t->front==t->rear)
t->front=t->rear=NIL;
else
t->front++;
return(n);
}
int main()
{
int ch,n,x,i;
queue qt;
do
{
clrscr();
cout<<"1->Insert \n";
cout<<"2->Delete \n";
cout<<"3->Display \n";
cout<<"4->Exit\n";
cout<<"Enter your choice:"; cin>>ch;
switch(ch)
{
case '1':
cout<<"Enter the term to insert:"; cin>>x;
qt.create(x);
getch();
break;
case '2':
x=qt.del();
if(x!=-1)
cout<<"Deleted term is " << x; getch(); break; case '3':
cout<<"Queue" << endl; qt.display();
getch(); break; case '4': cout<<"Exiting";
getch(); break; default:
cout<<"Not a valid choice"; getch(); break; } }while(ch!=4);
getch();
return(0);
}

Circular linked list

// Circular linked list //

#include
#include
#define NULL 0
struct list
{
int data;
struct list *next;
};
typedef struct list node;
node *find(node *,int);
node *start;
int main()
{
int menu(void);
void create(node *);
void display(node *);
void insert(node *,int,int);
void del(node *,int);
int choice,ch;
int data,tar;
node *newrec;
node *t;
start=NULL;
do{
clrscr();
choice=menu();
switch(choice)
{
case'1':
cout<<"\nCreating the list"; cout<<"\nEnter the terms(type 0 to end)\n"; start=new node; start->data=9999;
start->next=new node;
create(start->next);
break;
case'2':
if(start==NULL)
cout<<"\nList does not exist"; else { cout<<"\nDisplay the list\n"; display(start->next);
}
getch();
break;
case'3':
if(start==NULL)
{
cout<<"\nList does not exist"; getch(); } else { cout<<"\nEnter the term to insert:"; cin>>data;
cout<<"\nEnter the target term:"; cin>>tar;
insert(start,data,tar);}
break;
case'4':
if(start==NULL)
{
cout<<"\nList does not exist:"; getch(); } else { cout<<"\nEnter the term to delete:"; cin>>data;
del(start,data);
}
break;
case'5':
cout<<"\nExiting"; break; default: cout<<"\nNot valid choice"; getch(); break; } }while(choice!=5); getch(); return(0); } int menu(void) { int ch; cout<<"\n 1->Creation of the list";
cout<<"\n 2->Displaying the list";
cout<<"\n 3->Creation in the list";
cout<<"\n 4->Deletion in the list";
cout<<"\n 5->Exit";
cout<<"\nEnter your choice:"; cin>>ch;
return(ch);
}
void create(node *record)
{
cin>>record->data;
if(record->data==0)
record->next=start;
else
{
record->next=new node;
create(record->next);
}
return;
}
void display(node *record)
{
if(record->next!=start)
{
cout<data<next);
}
return;
}
void insert(node *record,int data,int target)
{
node *tag,*newrec;
newrec=new node;
tag=new node;
if(record->data==target)
{
newrec->next=start->next;
start->next=newrec;
}
else
{
tag=find(record,target);
newrec->next=tag->next;
tag->next=newrec;
}
if(tag==NULL)
{
cout<<"Target item not present in the list\n"; getch(); return; } newrec->data=data;
return;
}
void del(node *record,int target)
{
node *tag,*temp;
temp=new node;
tag=new node;
record=record->next;
if(record->data==target)
{
temp=record;
start->next=temp->next;
}
else
{
tag=find(record,target);
temp=tag->next;
tag->next=temp->next;
}
if(tag==NULL)
{
cout<<"Target item not present in the list\n"; getch(); return; } return; } node *find(node *record,int target) { if(record->next->data==target)
{
return(record);
}
else if(record->next==start)
return(NULL);
else
find(record->next,target);
}

Merge sort

// Merge sort //

#include
#include
#define SIZE 10
class int_list
{
private:
int arr[SIZE];
int no;
public:
int_list()
{
no=0;
}
void getdata(void);
void putdata(void);
void sort(void);
int_list merge(int_list);
};
void int_list::getdata(void)
{
cout<<"Enter the no. of elements:"; cin>>no;
if(no<=SIZE) { cout<<"Enter the terms:\n"; for(int i=0;i>arr[i];
}
else
{
cout<<"No.of elements should be<="<getdata();
}
}
void int_list::putdata(void)
{
if(no==0)
cout<<"U N D E R F L O W\n"; else { cout<<"Terms are:\n"; for(int i=0;i < i="0;i" j="i+1;j < no;j++)" > arr[j])
{
int temp;
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
int_list int_list::merge(int_list a)
{
int_list n;
n.no=-1;
int i,j;
for(i=0,j=0;i < no && j < a.no;)
n.arr[++n.no]=(arr[i]< a.arr[j])?arr[i++]:a.arr[j++];
if(i < no)
{
for(int l=i;l < no;l++)
n.arr[++n.no]= arr[l];
}
if(j<=a.no)
for(int l=j;l < a;l++)
n.arr[++n.no]=a.arr[l];
n.no++;
return(n);
}
int main()
{
int_list a;
clrscr();
a.getdata();
int_list b;
b.getdata();
a.sort();
b.sort();
int_list c=a.merge(b);
c.putdata();
getch();
return(0);
}

Quick sort

// Quick sort //

#include
#include
#define SIZE 10
int main()
{
void quick(int [],int,int,int);
clrscr();
int i,n,arr[SIZE];
cout<<"Enter the no. of terms:";
cin>>n;
cout<<"Enter the list:\n";
for(i=0;icin>>arr[i];
quick(arr,n,0,n-1);
cout<<"The sorted list is:\n";
for(i=0; i < n; i++)
cout << arr[i] << endl;
getch();
return(0);
}
void quick(int a[],int n,int lb,int ub)
{
void split(int [],int,int,int *);
int loc;
if (lb{
split(a,lb,ub,&loc);
quick(a,n,lb,loc-1);
quick(a,n,loc+1,ub);
}
return;
}
void split(int a[],int beg,int end,int *loc)
{
int left=beg,right=end,temp,i;
*loc=beg;
for(i=right;i>=left;i--)
{
while(a[*loc] <=a[right] && *loc!=right)
right=right-1;
if(a[*loc]>a[right])
{
temp=a[*loc];
a[*loc]=a[right];
a[right]=temp;
}
}
for(i=left; i < right; i++)
{
while(a[left]<=a[*loc]&&*loc!=left)
left=left+1;
if(a[left]>a[*loc])
{
temp=a[*loc];
a[*loc]=a[left];
a[left]=temp;
}
}
return;
}

Heap sort

// Heap sort //

#include"iostream.h'
#include"conio.h"
#define SIZE 30
int main()
{
int a[SIZE],heap[SIZE];
int i,n,count,temp;
void makeheap(int a[],int);
void heapsort(int a[],int);
clrscr();
cout<<"Enter the no. of terms:";
cin>>n;
cout<<"Enter the list:\n";
for(i=0;icin>>a[i];
makeheap(a,n);
cout<<"\nHeap is:\n";
for(i=0;i < n;i++)
cout << a[i] << endl;
getch();
return(0);
}
void makeheap(int a[],int n)
{
int i,son,fat,value;
for(i=1;i{
value=a[i];
son=i;
fat=(son-1)/2;
while(son>0 && a[fat]< value)
{
a[son]=a[fat];
son=fat;
fat=(son-1)/2;
}
a[son]=value;
}
return;
}

Implement queue as linked list

// Implement queue as linked list //

#include"iostream.h"
#include"conio.h"
#include'alloc.h"
#define NULL 0
#define MAX 5
struct que
{
int info;
struct que *next;
};
class qlink
{
struct que *f,*r;
public:
qlink()
{
f=r=NULL;
}
void display(void);
void insert(void);
void del (void);
};
void qlink::insert (void)
{
int item;
cout<<"Enter the term to insert:";
cin>>item;
if(f==NULL)
{
f=(struct que *)malloc(sizeof(struct que));
f->info=item;
f->next=r;
r=f;
}
else
{
r->next=(struct que *)malloc(sizeof(struct que));
r=r->next;
r->info=item;
r->next=NULL;
}
return;
}
void qlink::display(void)
{
struct que *t;
if(f==NULL)
{
cout << endl <<"UNDERFLOW";
}
t=f;
while(t!=NULL)
{
cout << endl <info;
t=t->next;
}
return;
}
void qlink::del(void)
{
struct que *t;
if(f==NULL)
cout<<"UNDERFLOW";
else
{
t=f->next;
cout<<"Deleted term is"<info;
free(f);
f=t;
}
return;
}
int main()
{
qlink q1;
int ch;
do
{
clrscr();
cout<<"1->Insert\n";
cout<<"2->Display\n";
cout<<"3->Delete\n";
cout<<"4->EXIT\n";
cout<<"Enter your choice:";
cin>>ch;
switch(ch)
{
case '1':
q1.insert();
break;
case '2':
cout<<"Queue\n";
q1.display();
getch();
break;
case '3':
q1.del();
getch();
break;
case '4':
cout<<"Exiting";
getch();
break;
default:
cout<<"Invalid choice";
getch();
break;
}
}while(ch!=4);
return(0);
}

Program To circular Queue using C++

//circular Queue//

#include
#include
#define NIL -1
#define MAX 5
typedef struct
{
int terms[MAX];
int front,rear;
}que;
class queue
{
que *q;
public:
queue()
{
q->front=NIL;
q->rear=NIL;
}
void create(int);
int del(void);
void display(void);
};
void queue::create(int x)
{
int i;
que *t=q;
if(((t->front==0) && (t->rear==MAX-1))||(t->front==t->rear+1))
{
cout<<"OVERFLOW";
getch();
return;
}
if(t->front==NIL)
t->front=t->rear=0;
else if(t->rear==MAX-1)
t->rear=0;
else
t->rear++;
t->terms[t->rear]=x;
return;
}
int queue::del(void)
{
int n;
que *t=q;
if((q->front==NIL)&&(q->rear==NIL))
{
cout<<"UNDERFLOW";
return(-1);
}
n=t->terms[t->front];
if(t->front==t->rear)
t->front=t->rear=NIL;
else if(t->front==MAX-1)
t->front=0;
else
t->front++;
return(n);
}
int main()
{
int ch,n,x,i;
queue qt;
do
{
clrscr();
cout<<"1->Insert \n";
cout<<"2->Delete \n";
cout<<"3->Exit\n";
cout<<"Enter your choice:";
cin>>ch;
switch(ch)
{
case '1':
cout<<"Enter the term to insert:";
cin>>x;
qt.create(x);
getch();
break;
case '2':
x=qt.del();
if(x!=-1)
cout << "Deleted term is " << x;
getch();
break;
case '3':
cout<<"Exiting";
getch();
break;
default:
cout<<"Not a valid choice";
getch();
break;
}
}while(ch!=3);
getch();
return(0);
}

Program to sort the nos using radix sort using C++

// Program to sort the nos using radix sort//

#include"iostream.h"
#include"conio.h"
#include"math.h"
#define SIZE 10
#define DIGIT 3

int main()

{
int a[SIZE],n,i,j,p,temp;
clrscr();
cout<<"Enter the no. of terms:";
cin>>n;
cout<<"Enter the terms:\n";
for(i=0;icin>>a[i];
for(p=1;p<=DIGIT;p++)
for(i=0; i< n-1; i++)
for(j=0;jif((a[j] % (int) pow(10,p))>(a[j+1]%(int) pow(10,p)))
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
cout <<"The sorted array is\n";
for (i=0 ; i < n; i++)
cout << endl << a[i];
getch();
return(0);
}

Program of Circular linked list using C++

// Circular linked list //

#include"iostream.h"
#include"conio.h"
#define NULL 0
struct list
{
int data;
struct list *next;
};
typedef struct list node;
node *find(node *,int);
node *start;
int main()
{
int menu(void);
void create(node *);
void display(node *);
void insert(node *,int,int);
void del(node *,int);
int choice,ch;
int data,tar;
node *newrec;
node *t;
start=NULL;
do{
clrscr();
choice=menu();
switch(choice)
{
case'1':
cout<<"\nCreating the list";
cout<<"\nEnter the terms(type 0 to end)\n";
start=new node;
start->data=9999;
start->next=new node;
create(start->next);
break;
case'2':
if(start==NULL)
cout<<"\nList does not exist";
else
{
cout<<"\nDisplay the list\n";
display(start->next);
}
getch();
break;
case'3':
if(start==NULL)
{
cout<<"\nList does not exist";
getch();
}
else
{
cout<<"\nEnter the term to insert:";
cin>>data;
cout<<"\nEnter the target term:";
cin>>tar;
insert(start,data,tar);}
break;
case'4':
if(start==NULL)
{
cout<<"\nList does not exist:";
getch();
}
else
{
cout<<"\nEnter the term to delete:";
cin>>data;
del(start,data);
}
break;
case'5':
cout<<"\nExiting";
break;
default:
cout<<"\nNot valid choice";
getch();
break;
}
}while(choice!=5);
getch();
return(0);
}
int menu(void)
{
int ch;
cout<<"\n 1->Creation of the list";
cout<<"\n 2->Displaying the list";
cout<<"\n 3->Creation in the list";
cout<<"\n 4->Deletion in the list";
cout<<"\n 5->Exit";
cout<<"\nEnter your choice:";
cin>>ch;
return(ch);
}
void create(node *record)
{
cin>>record->data;
if(record->data==0)
record->next=start;
else
{
record->next=new node;
create(record->next);
}
return;
}
void display(node *record)
{
if(record->next!=start)
{
cout<data<display(record->next);
}
return;
}
void insert(node *record,int data,int target)
{
node *tag,*newrec;
newrec=new node;
tag=new node;
if(record->data==target)
{
newrec->next=start->next;
start->next=newrec;
}
else
{
tag=find(record,target);
newrec->next=tag->next;
tag->next=newrec;
}
if(tag==NULL)
{
cout<<"Target item not present in the list\n";
getch();
return;
}
newrec->data=data;
return;
}
void del(node *record,int target)
{
node *tag,*temp;
temp=new node;
tag=new node;
record=record->next;
if(record->data==target)
{
temp=record;
start->next=temp->next;
}
else
{
tag=find(record,target);
temp=tag->next;
tag->next=temp->next;
}
if(tag==NULL)
{
cout<<"Target item not present in the list\n";
getch();
return;
}
return;
}
node *find(node *record,int target)
{
if(record->next->data==target)
{
return(record);
}
else if(record->next==start)
return(NULL);
else
find(record->next,target);
}

Program of Doubly linked list using C++

// Doubly linked list //

#include
#include
#define NULL 0
struct list
{
int data;
struct list*next;
struct list *prev;
};
typedef struct list node;
node *find(node *,int);
node *pre=NULL;
node *fin=NULL;
node *start;
int main()
{
int menu(void);
void create(node *);
void display(node *);
void insert(node *,int,int);
void revdisplay(node *);
void del(node *,int);
int choice,ch;
int data,tar;
node *newrec;
start=NULL;


do
{
clrscr();
choice=menu();
switch(choice)
{
case '1':
cout<<"\nCreating the list"; cout<<"Enter the terms(type 0 to end)\n"; start=new node; create(start); break; case '2': if (start==NULL) cout<<"\nList does not exist"; else { cout<<"\nDisplaying the list\n"; display(start); } getch(); break; case '3': if (start==NULL) { cout<<"\nList does not exist"; getch(); } else { cout<<"\nDisplaying the list:"; revdisplay(fin); case '4': if(start==NULL) { cout<<"\nList does not exist"; getch(); } else { cout<<"\nEnter the term to insert:"; cin>>data;
cout<<"\nEnter target term:"; cin>>tar;
insert(start,data,tar);
}
break;
case '5':
if(start==NULL)
cout<<"\nlist does not exist:"; getch(); } else { cout<<"\nEnter the term to delete:"; cin>>data;
del(start,data);
break;
case '6':
cout<<"\nExiting"; break; default: cout<<"\nNot a valid choice"; getch(); break; } }while(choice!=6); getch(); return(0); } int menu(void) { int ch; cout<<"\n1->Creation of the list";
cout<<"\n2->Displaying of the list";
cout<<"\n3->Displaying the list";
cout<<"\n4->Insertion of the list";
cout<<"\n5->Deletion of the list";
cout<<"\n6->Reverse of the list";
cout<<"\n7->Exit";
cout<<"\nEnter your choice:"; cin>>ch;
return(ch);
}
void create(node *record)
{
cin>>record->data;
if(record->data==0)
{
record->next=NULL;
record->prev=pre;
fin=record->prev;
pre=NULL;
else
{
record->prev=pre;
record->next=new node;
pre=record;
create(record->next);
}
return;
}
void display(node *record)
{
if(record->next!=NULL)
{
cout<data<next);
}
return;
}
void reverse(node *record)
{
if(record!=NULL)
{
cout<data<prev);
}
return;
void insert(node *record,int data,int target)
{
node *tag,*newrec,*temp;
newrec=new node;
if(record->data==target)
{
newrec->next=record;
newrec->prev=NULL;
record->prev=newrec;
start=newrec;
}
else
{
tag=find(record,target);
temp=tag->prev;
tag->prev=newrec;
newrec->next=tag;
temp->next=newrec;
}
if(tag==NULL)
{
cout<<"Target item not present in the list\n"; getch(); return; } newrec->data=data;
return;
}
void del(node *record,int target)
{
node *tag,*temp;
if(record->data==target)
{
temp=record;
start=start->next;
start->prev=NULL;
delete temp;
}
else
{
tag=find(record,target);
if(tag->next->next==NULL)
{
fin=fin->prev;
fin->next=tag->next;
}
if(tag==NULL)
{
cout<<"Target item not present in the list\n"; getch(); return; } return; } node *find(node *record,int target) { if(record->next->data==target)
{
return(record);
}
else if(record->next==NULL)
return(NULL);
else
find(record->next,target);
}
}

Admission Notice 2008-09 of PONDICHERRY UNIVERSITY

PONDICHERRY UNIVERSITY

(A Central University)

Admission Notice 2008-09


(1) P.G. Programmes (M.A./M.Sc.)

(2) P.G. Diploma Programmes

(3) Five Year Integrated M.Sc. Programmes for +2 students. (All students admitted will be paid stipend of Rs.750/- per month, during first three years).

(4) M.Phil. & Ph.D. Programmes. (All students admitted will be paid scholarship of Rs.3000/- and Rs.5000/- per month respectively).

(5) M.Ed., M.P.Ed., M.L.I.S. & M.Com. (Business Finance) Programmes.

(6) M.Tech. & M.C.A. Programmes.

(7) M.B.A. Programmes (Banking Technology/ International Business/ Tourism).

Entrance examinations will be held in various Centres spread all over India. Reservations for SC/ST/PH, etc. will be provided as per Government of India Rules.

Applications can be submitted ONLINE. The application forms can also be obtained by post by written to “The Deputy Registrar (Academic II) Pondicherry University, R.V. Nagar, Kalapet, Puducherry 605014” along with the Bank Demand Draft towards the cost of the application form and self addressed envelope with postal stamps worth Rs.40/-. For details refer to University website or contact on telephone numbers 0413-2654229/ 2654470.

IMPORTANT DATES:


Date of Issue of application forms: 03.04.2008 onwards.

Last Date for issue of application forms by post: 25.04.2008

Last Date for issue of application forms in person: 05.05.2008

Last Date for submission of the filled in application forms: 05.05.2008

Date of Entrance Examination: 24.05.2008 & 25.05.2008

For More Details CLICK HERE

Recent Educational News