0% found this document useful (0 votes)
5 views

DBMS LAB MANUAL(1)

The document outlines the use of Data Control Language (DCL) and Transaction Control Language (TCL) commands for managing database transactions and privileges. It details TCL commands such as Commit, Rollback, and Savepoint, as well as DCL commands like GRANT and REVOKE. Additionally, it covers SQL functions, categorizing them into Aggregate and Scalar functions, and provides examples of their usage.

Uploaded by

navisan949
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

DBMS LAB MANUAL(1)

The document outlines the use of Data Control Language (DCL) and Transaction Control Language (TCL) commands for managing database transactions and privileges. It details TCL commands such as Commit, Rollback, and Savepoint, as well as DCL commands like GRANT and REVOKE. Additionally, it covers SQL functions, categorizing them into Aggregate and Scalar functions, and provides examples of their usage.

Uploaded by

navisan949
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

EX.

NO:3
DATE:

DATA CONTROL LANGUAGE COMMANDS AND TRANSACTION CONTROL


COMMANDS

AIM:

To create a database using Data Control Commands and Transaction Control Commands to
manage transactions in the database.

DESCRIPTION:

Transaction Control statements

Transaction Control Language (TCL) commands are used to manage transactions in the database.
These are used to manage the changes made by DML-statements. It also allows statements to be
grouped together into logical transactions.

Examples of TCL:

(i) Commit
(ii) Rollback
(iii) Savepoint

(i) Commit: Commit command saves all the work done.

Syntax: commit;
(ii) Rollback: Rollback Command restores database to original since the last Commit.

Syntax: ROLLBACK TO SAVEPOINT <savepoint_name>;

(iii) Savepoint:

SAVEPOINT command is used to temporarily save a transaction so that you can rollback to that
point whenever required.
In short, using this command we can name the different states of our data in any table and then
rollback to that state using the ROLLBACK command whenever required.

Syntax: SAVEPOINT <savepoint_name>;


Data Control Language

Data Control Language (DCL) is used to control privileges in Database. To perform any
operation in the database, such as for creating tables, sequences or views, a user needs privileges.
Privileges are of two types,

• System: This includes permissions for creating session, table, etc. and all types of other
system privileges.
• Object: This includes permissions for any command or query to perform any operation on
the database tables.

In DCL we have two commands,

• GRANT: Used to provide any user access privileges or other privileges for the database.

• REVOKE: Used to take back permissions from any user.


RESULT:

Thus, the Data Control Language (DCL) and Transaction Control Language (TCL) commands
were executed successfully.
EX. NO: 4
Date:
SQL FUNCTIONS

AIM:

To study the various SQL functions and their operations on the database.

DESCRIPTION:

What are functions?

Functions are methods used to perform data operations. SQL has many in-built functions used to
perform string concatenations, mathematical calculations etc.

SQL functions are categorized into the following two categories:

1. Aggregate Functions
2. Scalar Functions

Let us look into each one of them, one by one.

AGGREGATE SQL FUNCTIONS

The Aggregate Functions in SQL perform calculations on a group of values and then return a
single value. Following is a few of the most commonly used Aggregate Functions:

Function Description
SUM() Used to return the sum of a group of values.
COUNT() Returns the number of rows either based on a condition, or without a condition.
AVG() Used to calculate the average value of a numeric column.
MIN() This function returns the minimum value of a column.
MAX() Returns a maximum value of a column.
FIRST() Used to return the first value of the column.
LAST() This function returns the last value of the column.

SCALAR SQL FUNCTIONS

The Scalar Functions in SQL are used to return a single value from the given input
value. Following is a few of the most commonly used Aggregate Functions:

Function Description
LCASE() Used to convert string column values to lowercase
UCASE() This function is used to convert a string column values to Uppercase.
LEN() Returns the length of the text values in the column.
MID() Extracts substrings in SQL from column values having String data type.
ROUND() Rounds off a numeric value to the nearest integer.
NOW() This function is used to return the current system date and time.
FORMAT() Used to format how a field must be displayed.

EXAMPLE:
CHARACTER/STRING FUNCTION:

SQL> select upper('welcome') from dual;

SQL> select upper('hai') from dual;

SQL> select lower('HAI') from dual;

SQL> select initcap(‘hello world') from dual;

SQL> select ltrim('hello world',’hell’) from dual;

SQL> select rtrim(''hello world',’ld’')from dual;

SQL> select concat('SRM',' University')from dual;

SQL> select length('Welcome’) from dual;

SQL> select replace('SRM University', 'University','IST')from dual;

SQL> select lpad('SRM University',20,'*')from dual;

SQL> select rpad('SRM University',15,'$')from dual;

SQL> select substr('Welcome to SRM University', 4,7)from dual;

SQL> select replace('COMPUTER','O','AB')from dual;

SQL> select replace('University','city’,'Inter')from dual;

SQL> select translate('cold','ld','ol')from dual;


OUTPUT:
DATE & TIME FUNCTION

SQL> select sysdate from dual;


SQL> select round(sysdate)from dual;
SQL> select add_months(sysdate,3)from dual;
SQL> select last_day(sysdate)from dual;
SQL> select sysdate+20 from dual;
SQL> select next_day(sysdate,'tuesday')from dual;

OUTPUT:
NUMERIC FUNCTION

SQL> select round(15.6789)from dual;


SQL> select ceil(23.20)from dual;
SQL> select floor(34.56)from dual;
SQL> select trunc(15.56743)from dual;
SQL> select sign(-345)from dual;
SQL> select abs(-70)from dual;

OUTPUT:
MATH FUNCTION:

SQL> select power(10,12) from dual;


SQL> select power(5,6) from dual;
SQL> select mod(11,5) from dual;
SQL> select exp(10) from dual;
SQL> select sqrt(225) from dual;

RESULT:

Thus, the SQL Functions have been executed successfully.

You might also like