Professional Documents
Culture Documents
Dbms-Exno 1,2
Dbms-Exno 1,2
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.
SNAME VARCHAR2(30)
SID VARCHAR2(10)
SAGE NUMBER(2)
SAREA VARCHAR2(20)
Table altered.
Table altered.
SNAME VARCHAR2(30)
SID VARCHAR2(10)
SAGE NUMBER(10)
SAREA VARCHAR2(20)
SDEPT VARCHAR2(20)
Table altered.
SNAME VARCHAR2(30)
SID VARCHAR2(10)
SAGE NUMBER(10)
SAREA VARCHAR2(20)
Table truncated.
SNAME VARCHAR2(30)
SID VARCHAR2(10)
SAGE NUMBER(10)
SAREA VARCHAR2(20)
SDEPT VARCHAR2(20)
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
STRING FUNCTIONS
AGGREGATE FUNCTIONS
CONVERSION FUCTIONS
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.