Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Ex.

No : 1 Creation of a database and writing SQL queries to retrieve information from the
database.

AIM

To create a database and to retrieve the information from the database using SQL queries.

COMMANDS

SQL> create table stud (sname varchar2(30), sid varchar2(10), sage number(2), sarea varchar2(20));

Table created.

SQL> desc stud;

Name Null? Type

----------------------------------------------------- -------- --------------------------------

SNAME VARCHAR2(30)

SID VARCHAR2(10)

SAGE NUMBER(2)

SAREA VARCHAR2(20)

SQL>alter table stud modify ( sage number(10));

Table altered.

SQL> alter table stud add ( sdept varchar2(20));

Table altered.

SQL> desc stud;

Name Null? Type

----------------------------------------------------- -------- --------------------------------

SNAME VARCHAR2(30)

SID VARCHAR2(10)

SAGE NUMBER(10)

SAREA VARCHAR2(20)
SDEPT VARCHAR2(20)

SQL> alter table stud drop (sdept varchar2(20));

Table altered.

SQL> desc studs;

Name Null? Type

----------------------------------------------------- -------- ------------------------------------

SNAME VARCHAR2(30)

SID VARCHAR2(10)

SAGE NUMBER(10)

SAREA VARCHAR2(20)

SQL> truncate table studs;

Table truncated.

SQL> desc studs;

Name Null? Type

----------------------------------------------------- -------- ------------------------------------

SNAME VARCHAR2(30)

SID VARCHAR2(10)

SAGE NUMBER(10)

SAREA VARCHAR2(20)

SDEPT VARCHAR2(20)

SQL> drop table studs;

Table dropped.

RESULT

Thus the creation of database and the SQL queries to retrieve information from the database has
been implemented and the output was verified.
Ex. No: 2 Performing Insertion, Deletion, Modifying, Altering, Updating and Viewing records
based on conditions.

A. AIM

To study the various categories of DML commands such as logical operations, aggregate
functions, string functions, numeric functions, date functions, conversion functions, group functions and
set operations.

DESCRIPTION

THE ORACLE TABLE – DUAL - Dual is a small oracle table which consists of only one row
and one column and contains the value X in that column.
INSERT - This command is used to insert values into the table.
SELECT - This command is used to display the contents of the table or those of a
particular column.
RENAME - This command renames the name of the table.
ARITHMETIC OPERATIONS - Various operations such as addition, multiplication,
subtraction and division can be performed using the numbers available in the table.
DISTINCT - This keyword is used along with select keyword to display unique values from the
specified column. It avoids duplicates during display.
ORDER BY CLAUSE - The order by clause arranges the contents of the table in ascending
order (by default) or in descending order (if specified explicitly) according to the specified
column.
CONCATENATION OPERATOR - This combines information from two or more columns in a
sentence according to the format specified.

LOGICAL OPERATORS

AND : The oracle engine will process all rows in a table and displays the result only when all
of the conditions specified using the AND operator are specified.
OR : The oracle engine will process all rows in a table and displays the result only when any of
the conditions specified using the OR operators are satisfied.
NOT : The oracle engine will process all rows in a table and displays the result only when
none of the conditions specified using the NOT operator are specified.
BETWEEN : In order to select data that is within a range of values, the between operator is used.
(AND should be included)

PATTERN MATCH

LIKE PREDICATE : The use of like predicate is that it allows the comparison of one string value
with another string value, which is not identical. This is achieved by using wildcard characters
which are % and _. The purpose of % is that it matches any string and _ matches any single
character.
IN AND NOT IN PREDICATE : The arithmetic operator = compares a single value to another
single value. In case a value needs to be compared to a list of values then the in predicate is used.
The not in predicate is the opposite of the in predicate. This will select all the rows whose values
do not match all of the values in the list.
NUMERIC FUNCTIONS

ABS: It returns the absolute value of ‘n’.


POWER: It returns m raised to nth power. n must be an integer else an error is returned.
ROUND: It returns n rounded to m places right of the decimal point. If m is omitted, n is rounded
to zero places. m must be an integer.
SQRT: It returns square root of n. n should be greater than zero.

STRING FUNCTIONS

LOWER: It returns char with letters in lower case.


INITCAP: It returns char with the first letter in upper case.
UPPER: It returns char with all letters forced to upper case.
SUBSTR: It returns a portion of char beginning at character m, exceeding up to n characters. If n
is omitted result is written up to the end character. The 1stposition of char is one.
LENGTH: It returns the length of char
LTRIM: It removes characters from the left of char with initial characters removed up to the 1st
character not in set.
RTRIM: It returns char with final characters removed after the last character not in the set. Set
is optional. It defaults to spaces.
LPAD: It returns char1, left padded to length n with the sequence of characters in char2.
char2 defaults to blanks.
RPAD: It returns char1, right padded to length n with the characters in char2, replicated as
many times as necessary. If char2 is omitted, it is padded with blanks.

AGGREGATE FUNCTIONS

AVG (N): It returns average value of n ignoring null values.


MIN (EXPR): It returns minimum value of the expression.
COUNT (EXPR): It returns the number of rows where expression is not null.
COUNT (*): It returns the number of rows in the table including the duplicates and those
with null values.
MAX (EXPR): It returns maximum value of the
expression. SUM(N): It returns sum of values of n.

CONVERSION FUCTIONS

TO_NUMBER(CHAR): It converts the char value containing a number to a value of number


data type.
TO_CHAR(N,FMT): It converts a 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.
TO_CHAR(DATE, FMT): It converts a value of data type to char value. It accepts a date as well
as the format in which the date has to appear. Fmt must be a date format. If fmt is omitted, date is
the default date format.
DATE FUNCTIONS

SYSDATE : The 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.
ADD_MONTHS(D,N): It returns date after adding the number of months specified with the
function.
LAST_DAY(D): It returns the last date of the month specified with the function
MONTHS_BETWEEN(D1,D2): It returns number of months between D1 and D2.
NEXT_DAY(DATE, CHAR): It returns the date of the first week day named by char . char
must be a day of the week.

GROUP BY CLAUSE

The group by clause is another section of the select statement. This optional class tells oracle to
group rows based on distinct values that exists for specified columns.

HAVING CLAUSE

The having clause can be used in conjunction with the group by clause. Having imposes a
condition on the group by clause, which further filters the groups created by the group by clause.

SET OPERATIONS

UNION CLAUSE: Multiple queries can be put together and their output combined using the
union clause. The union clause merges the output of two or more queries into a single set of
rows and columns.
INTERSECT CLAUSE: Multiple queries can be put together and their output can be combined
using the intersect clause. The intersect clause outputs only rows produced by both the queries
intersected. The output in an intersect clause will include only those rows that are retrieved by
both the queries.

You might also like