Introduction to data manipulation language DML
Introduction to data manipulation language DML
php
(DEPTNO NUMBER(2) ,
DNAME VARCHAR2(14) ,
LOC VARCHAR2(13) )
Introduction to DML
1. SELECT COMMAND
Clause Description
Syntax:
SELECT * FROM <table_name>;
OR
2. INSERT COMMAND
Example:
INSERT INTO employee (`eid` int, `ename` varchar(20), `city` varchar(20))
VALUES (`1`, `ABC`, `PUNE`);
3. UPDATE COMMAND
UPDATE employee
SET salary=20000
WHERE ename='ABC';
4. DELETE COMMAND
Syntax:
DELETE FROM <table_name> WHERE <condition>;
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
(EmployeeID,EmployeeName,PhoneNumber,Address,City,Country)
VALUES
UPDATE newEmployee_Info
WHERE EmployeeID = 7;
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.
AVG
AVG( ALL /DISTINCT expr)
Example
Average Salary
------------------------
2400.40
SUM
SUM(ALL/DISTINCT expr)
Example
Total Salary
------------------------
26500
MAX
MAX(ALL/DISTINCT expr)
Example
The following query returns the max salary from the employees.
Maximum Salary
------------------------
4500
MIN
MIN(ALL/DISTINCT expr)
Example
The following query returns the minimum salary from the employees.
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
COUNT
------
14
The following query counts the number of employees whose salary is not null.
COUNT
------
12
STDDEV
STDDEV(ALL/DISTINCT expr)
STDDEV returns sample standard deviation of expr, a set of numbers.
Example
Stddev
-------
1430
VARIANCE
VARIANCE(ALL/DISTINCT expr)
Example
Variance
-------
1430
DML QUERIES
CREATE TABLE
CREATE TABLE empdetsales
city varchar2(50),
);
INSERT
INSERT INTO empdetsales
(id,Name,City,salary)
VALUES
('03','mini','salem',30000);
select
FROM empdetsales
WHERE id =1;
DELETE
DELETE FROM empdetsales
AND id > 2;
Aggregate Functions