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

Introduction to data manipulation language DML

data manipulation language DML

Uploaded by

Anithadevi N
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Introduction to data manipulation language DML

data manipulation language DML

Uploaded by

Anithadevi N
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 9

https://www.tutorialspoint.com/oracle_terminal_online.

php

CREATE TABLE newDEPTfresh

(DEPTNO NUMBER(2) ,

DNAME VARCHAR2(14) ,

LOC VARCHAR2(13) )

Introduction to DML

 DML stands for Data Manipulation Language.


 It is a language used for selecting, inserting, deleting and updating data
in a database.
 It is used to retrieve and manipulate data in a relational database.
DDL commands are as follows,
1. SELECT
2. INSERT
3. UPDATE
4. DELETE
 DML performs read-only queries of data.

1. SELECT COMMAND

 SELECT command is used to retrieve data from the database.


 This command allows database users to retrieve the specific information
they desire from an operational database.
 It returns a result set of records from one or more tables.
SELECT Command has many optional clauses are as stated below:

Clause Description

WHERE It specifies which rows to retrieve.

GROUP BY It is used to arrange the data into groups.


HAVING It selects among the groups defined by the GROUP BY clause.

ORDER BY It specifies an order in which to return the rows.

AS It provides an alias which can be used to temporarily rename tables or columns.

Syntax:
SELECT * FROM <table_name>;

Example : SELECT Command

SELECT * FROM employee;

OR

SELECT * FROM employee


where salary >=10,000;

2. INSERT COMMAND

 INSERT command is used for inserting a data into a table.


 Using this command, you can add one or more records to any single table
in a database.
 It is also used to add records to an existing code.
Syntax:
INSERT INTO <table_name> (`column_name1` <datatype>, `column_name2`
<datatype>, . . . , `column_name_n` <database>) VALUES (`value1`,
`value2`, . . . , `value n`);

Example:
INSERT INTO employee (`eid` int, `ename` varchar(20), `city` varchar(20))
VALUES (`1`, `ABC`, `PUNE`);

3. UPDATE COMMAND

 UPDATE command is used to modify the records present in existing


table.
 This command updates existing data within a table.
 It changes the data of one or more records in a table.
Syntax:
UPDATE <table_name>
SET <column_name = value>
WHERE condition;

Example : UPDATE Command

UPDATE employee
SET salary=20000
WHERE ename='ABC';

4. DELETE COMMAND

 DELETE command is used to delete some or all records from the


existing table.
 It deletes all the records from a table.

Syntax:
DELETE FROM <table_name> WHERE <condition>;

Example : DELETE Command

DELETE FROM employee


WHERE emp_id = '001';

CREATE TABLE newEmployee_Info

EmployeeID int,

EmployeeName varchar(255),

PhoneNumber int,

Address varchar(255),

City varchar(255),

Country varchar(255)

);
INSERT INTO newEmployee_Info

(EmployeeID,EmployeeName,PhoneNumber,Address,City,Country)

VALUES

('06','Sanjana','9921321141','Camel Street House No 12','Chennai','India');

INSERT INTO newEmployee_Info

(EmployeeID,EmployeeName,PhoneNumber,Address,City,Country)

VALUES

('07','anu','7821321141','North Street House No 12','Cbe','India');

select *from newEmployee_Info;

UPDATE newEmployee_Info

SET EmployeeName = 'Aahana', City= 'Ahmedabad'

WHERE EmployeeID = 7;

select *from newEmployee_Info;

DELETE FROM newEmployee_Info

WHERE EmployeeName='Aahana';

Aggregate Functions
Aggregate functions return a single value based on groups of rows, rather than single value
for each row. You can use Aggregate functions in select lists and in ORDER BY and
HAVING clauses. They are commonly used with the GROUP BY clause in a SELECT
statement, where Oracle divides the rows of a queried table or view into groups.

The important Aggregate functions are :

Avg Sum Max Min Count Stddev Variance

AVG
AVG( ALL /DISTINCT expr)

Returns the average value of expr.

Example

The following query returns the average salary of all employees.

select avg(sal) “Average Salary” from emp;

Average Salary
------------------------
2400.40

SUM
SUM(ALL/DISTINCT expr)

Returns the sum value of expr.

Example

The following query returns the sum salary of all employees.

select sum(sal) “Total Salary” from emp;

Total Salary
------------------------
26500

MAX
MAX(ALL/DISTINCT expr)

Returns maximum value of expr.

Example

The following query returns the max salary from the employees.

select max(sal) “Max Salary” from emp;

Maximum Salary
------------------------
4500
MIN
MIN(ALL/DISTINCT expr)

Returns minimum value of expr.

Example

The following query returns the minimum salary from the employees.

select min(sal) “Min Salary” from emp;

Minimum Salary
------------------------
1200

COUNT
COUNT(*) OR COUNT(ALL/DISTINCT expr)

Returns the number of rows in the query. If you specify expr then count ignore nulls. If you
specify the asterisk (*), this function returns all rows, including duplicates and nulls. COUNT
never returns null.

Example

The following query returns the number of employees.

Select count(*) from emp;

COUNT
------
14

The following query counts the number of employees whose salary is not null.

Select count(sal) from emp;

COUNT
------
12

STDDEV
STDDEV(ALL/DISTINCT expr)
STDDEV returns sample standard deviation of expr, a set of numbers.

Example

The following query returns the standard deviation of salaries.

select stddev(sal) from emp;

Stddev
-------
1430

VARIANCE
VARIANCE(ALL/DISTINCT expr)

Variance returns the variance of expr.

Example

The following query returns the variance of salaries.

select variance(sal) from emp;

Variance
-------
1430
DML QUERIES

CREATE TABLE
CREATE TABLE empdetsales

( id number(10) NOT NULL,

name varchar2(50) NOT NULL,

city varchar2(50),

salary number(10) NOT NULL,

CONSTRAINT empdetsales_pk PRIMARY KEY (id)

);

INSERT
INSERT INTO empdetsales

(id,Name,City,salary)

VALUES

('03','mini','salem',30000);

select

select *from empdetsales;

SELECT salary, name

FROM empdetsales

WHERE salary > 50000;


UPDATE
UPDATE empdetsales

SET Name = 'Aahana', City= 'Ahmedabad'

WHERE id =1;

select *from empdetsales;

DELETE
DELETE FROM empdetsales

WHERE name = 'mini'

AND id > 2;

Aggregate Functions

select min(salary) "Min Salary" from empdetsales;

select min(salary) "Min Salary" from empdetsales;

select sum(salary) "Total Salary" from empdetsales;

select max(salary) "Max Salary" from empdetsales;

Select count(salary) from empdetsales;

Select count(*) from empdetsales;

You might also like