SlideShare ist ein Scribd-Unternehmen logo
1 von 8
Downloaden Sie, um offline zu lesen
Oracle DML Statements
DML: Data Manipulation Language
Used to add, change or delete data
INSERT– add rows to a table
UPDATE – update existing rows in a table.
MERGE – update if rows exist, insert if they don’t
DELETE – delete rows from a table
http://adata.guru
Transactions
 A transaction is a sequence of SQL statements that Oracle Database treats as a single unit.
 Atomic unit of work that takes the database from one consistent state to another.
 Entire transaction succeeds or fails. No half-transactions.
 From the first DML statement to the first commit/rollback.
http://adata.guru
Transaction Control Statements
Commit
Ends your current transaction and make permanent all changes performed in the
transaction. Oracle Database issues an implicit COMMIT before and after any data
definition language (DDL) statement.
Rollback:
Undo work done in the current transaction. If you do not explicitly commit the
transaction and the program terminates abnormally, then Oracle Database rolls back
the last uncommitted transaction.
http://adata.guru
DML Statements – INSERT
 insert into <table_name> ( <column_names>)
Values (<column values>)
Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO)
values (7369,'SMITH','CLERK',7902,to_date('17-DEC-1980','DD-MON-YYYY'),800,null,20);
 Insert into table_name ( < column names >)
{ select query }
Insert into locations (loc_name)
select loc
from scott.dept
union
select state_province
from hr.locations;
http://adata.guru
DML Statements – UPDATE
UPDATE <table_name>
SET <column-value-pairs>
WHERE <conditions>;
Update based on primary key:
UPDATE oe.customers
SET account_mgr_id = 149,
credit_limit = 3000
WHERE customer_id = 240;
Update a few rows based on a condition:
UPDATE oe.warehouses
SET warehouse_name = ‘Mumbai’
WHERE warehouse_name = ‘Bombay’;
No filter conditions.. Update all rows in the table.
UPDATE oe.customers
SET cust_email = upper(cust_email);
http://adata.guru
DML Statements – MERGE/UPSERT
MERGE into tgt_table
USING (source_table/source query)
ON <matching-conditions>
WHEN MATCHED then
update <column-value pairs>
WHEN NOT MATCHED then
INSERT <column-value pairs>
http://adata.guru
DML Statements – DELETE
Syntax :
DELETE from <table_name>
WHERE <conditions>;
Delete (one row) based on primary key:
DELETE from oe.customers
WHERE customer_id = 240;
DELETE a few rows based on a condition:
DELETE from oe.warehouses
WHERE warehouse_name = ‘Bombay’;
No filter conditions.. DELETE all rows in the table.
DELETE from oe.customers;
http://adata.guru
Delete v/s Truncate
http://adata.guru
HWM
HWM
HWM
HWM
HWM
Initial table creation. Full table scans are pretty
quick, since there are no blocks to scan
One million rows inserted (for example). High
water mark is advanced and oracle scans blocks
till HWM during a full scan. Inevitable.
Half a million rows deleted. HWM remains
unchanged, oracle still scans all the blocks during
a full table scan.
All rows are deleted using “delete” command.
HWM still at the same location, makes oracle still
do full table scans. Returns no data though.
TRUNCATE resets high water mark causing full-
scans and other operations to perform much
faster.

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (19)

SQL Data Manipulation
SQL Data ManipulationSQL Data Manipulation
SQL Data Manipulation
 
Oracle Database DML DDL and TCL
Oracle Database DML DDL and TCL Oracle Database DML DDL and TCL
Oracle Database DML DDL and TCL
 
Data Manipulation Language
Data Manipulation LanguageData Manipulation Language
Data Manipulation Language
 
DDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and JoinsDDL,DML,SQL Functions and Joins
DDL,DML,SQL Functions and Joins
 
Creating database using sql commands
Creating database using sql commandsCreating database using sql commands
Creating database using sql commands
 
Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)Database Systems - SQL - DDL Statements (Chapter 3/2)
Database Systems - SQL - DDL Statements (Chapter 3/2)
 
Sql basics and DDL statements
Sql basics and DDL statementsSql basics and DDL statements
Sql basics and DDL statements
 
SQL Tutorial - How To Create, Drop, and Truncate Table
SQL Tutorial - How To Create, Drop, and Truncate TableSQL Tutorial - How To Create, Drop, and Truncate Table
SQL Tutorial - How To Create, Drop, and Truncate Table
 
Oracle: DDL
Oracle: DDLOracle: DDL
Oracle: DDL
 
SQL Tutorial - Basic Commands
SQL Tutorial - Basic CommandsSQL Tutorial - Basic Commands
SQL Tutorial - Basic Commands
 
Database Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and deleteDatabase Management - Lecture 2 - SQL select, insert, update and delete
Database Management - Lecture 2 - SQL select, insert, update and delete
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
SQL DDL
SQL DDLSQL DDL
SQL DDL
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)Database Systems - SQL - DDL Statements (Chapter 3/3)
Database Systems - SQL - DDL Statements (Chapter 3/3)
 
SQL-Alter Table, SELECT DISTINCT & WHERE
SQL-Alter Table, SELECT DISTINCT & WHERESQL-Alter Table, SELECT DISTINCT & WHERE
SQL-Alter Table, SELECT DISTINCT & WHERE
 
SQL
SQLSQL
SQL
 
Dml and ddl
Dml and ddlDml and ddl
Dml and ddl
 
SQL
SQLSQL
SQL
 

Ähnlich wie Oracle SQL DML Statements (20)

Sql DML
Sql DMLSql DML
Sql DML
 
Les08 (manipulating data)
Les08 (manipulating data)Les08 (manipulating data)
Les08 (manipulating data)
 
Les08
Les08Les08
Les08
 
Les09
Les09Les09
Les09
 
Les08
Les08Les08
Les08
 
Les09 Manipulating Data
Les09 Manipulating DataLes09 Manipulating Data
Les09 Manipulating Data
 
e computer notes - Manipulating data
e computer notes - Manipulating datae computer notes - Manipulating data
e computer notes - Manipulating data
 
Les09.ppt
Les09.pptLes09.ppt
Les09.ppt
 
SQL Query
SQL QuerySQL Query
SQL Query
 
Intro to tsql unit 9
Intro to tsql   unit 9Intro to tsql   unit 9
Intro to tsql unit 9
 
Manipulating data
Manipulating dataManipulating data
Manipulating data
 
Sql
SqlSql
Sql
 
Les03
Les03Les03
Les03
 
Ddl &amp; dml commands
Ddl &amp; dml commandsDdl &amp; dml commands
Ddl &amp; dml commands
 
Structured query language constraints
Structured query language constraintsStructured query language constraints
Structured query language constraints
 
Ms sql server ii
Ms sql server  iiMs sql server  ii
Ms sql server ii
 
Data integrity
Data integrityData integrity
Data integrity
 
sql language
sql languagesql language
sql language
 
Oracle - Program with PL/SQL - Lession 03
Oracle - Program with PL/SQL - Lession 03Oracle - Program with PL/SQL - Lession 03
Oracle - Program with PL/SQL - Lession 03
 
Les21
Les21Les21
Les21
 

Kürzlich hochgeladen

Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...Boston Institute of Analytics
 
Decoding Movie Sentiments: Analyzing Reviews with Data Analysis model
Decoding Movie Sentiments: Analyzing Reviews with Data Analysis modelDecoding Movie Sentiments: Analyzing Reviews with Data Analysis model
Decoding Movie Sentiments: Analyzing Reviews with Data Analysis modelBoston Institute of Analytics
 
Presentation of project of business person who are success
Presentation of project of business person who are successPresentation of project of business person who are success
Presentation of project of business person who are successPratikSingh115843
 
Digital Marketing Plan, how digital marketing works
Digital Marketing Plan, how digital marketing worksDigital Marketing Plan, how digital marketing works
Digital Marketing Plan, how digital marketing worksdeepakthakur548787
 
Role of Consumer Insights in business transformation
Role of Consumer Insights in business transformationRole of Consumer Insights in business transformation
Role of Consumer Insights in business transformationAnnie Melnic
 
English-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdf
English-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdfEnglish-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdf
English-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdfblazblazml
 
why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...
why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...
why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...Jack Cole
 
IBEF report on the Insurance market in India
IBEF report on the Insurance market in IndiaIBEF report on the Insurance market in India
IBEF report on the Insurance market in IndiaManalVerma4
 
DATA ANALYSIS using various data sets like shoping data set etc
DATA ANALYSIS using various data sets like shoping data set etcDATA ANALYSIS using various data sets like shoping data set etc
DATA ANALYSIS using various data sets like shoping data set etclalithasri22
 
Bank Loan Approval Analysis: A Comprehensive Data Analysis Project
Bank Loan Approval Analysis: A Comprehensive Data Analysis ProjectBank Loan Approval Analysis: A Comprehensive Data Analysis Project
Bank Loan Approval Analysis: A Comprehensive Data Analysis ProjectBoston Institute of Analytics
 
Statistics For Management by Richard I. Levin 8ed.pdf
Statistics For Management by Richard I. Levin 8ed.pdfStatistics For Management by Richard I. Levin 8ed.pdf
Statistics For Management by Richard I. Levin 8ed.pdfnikeshsingh56
 
Digital Indonesia Report 2024 by We Are Social .pdf
Digital Indonesia Report 2024 by We Are Social .pdfDigital Indonesia Report 2024 by We Are Social .pdf
Digital Indonesia Report 2024 by We Are Social .pdfNicoChristianSunaryo
 
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...Dr Arash Najmaei ( Phd., MBA, BSc)
 
Non Text Magic Studio Magic Design for Presentations L&P.pdf
Non Text Magic Studio Magic Design for Presentations L&P.pdfNon Text Magic Studio Magic Design for Presentations L&P.pdf
Non Text Magic Studio Magic Design for Presentations L&P.pdfPratikPatil591646
 

Kürzlich hochgeladen (17)

Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
Data Analysis Project Presentation: Unveiling Your Ideal Customer, Bank Custo...
 
Decoding Movie Sentiments: Analyzing Reviews with Data Analysis model
Decoding Movie Sentiments: Analyzing Reviews with Data Analysis modelDecoding Movie Sentiments: Analyzing Reviews with Data Analysis model
Decoding Movie Sentiments: Analyzing Reviews with Data Analysis model
 
Presentation of project of business person who are success
Presentation of project of business person who are successPresentation of project of business person who are success
Presentation of project of business person who are success
 
Digital Marketing Plan, how digital marketing works
Digital Marketing Plan, how digital marketing worksDigital Marketing Plan, how digital marketing works
Digital Marketing Plan, how digital marketing works
 
Role of Consumer Insights in business transformation
Role of Consumer Insights in business transformationRole of Consumer Insights in business transformation
Role of Consumer Insights in business transformation
 
English-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdf
English-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdfEnglish-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdf
English-8-Q4-W3-Synthesizing-Essential-Information-From-Various-Sources-1.pdf
 
why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...
why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...
why-transparency-and-traceability-are-essential-for-sustainable-supply-chains...
 
2023 Survey Shows Dip in High School E-Cigarette Use
2023 Survey Shows Dip in High School E-Cigarette Use2023 Survey Shows Dip in High School E-Cigarette Use
2023 Survey Shows Dip in High School E-Cigarette Use
 
IBEF report on the Insurance market in India
IBEF report on the Insurance market in IndiaIBEF report on the Insurance market in India
IBEF report on the Insurance market in India
 
Data Analysis Project: Stroke Prediction
Data Analysis Project: Stroke PredictionData Analysis Project: Stroke Prediction
Data Analysis Project: Stroke Prediction
 
DATA ANALYSIS using various data sets like shoping data set etc
DATA ANALYSIS using various data sets like shoping data set etcDATA ANALYSIS using various data sets like shoping data set etc
DATA ANALYSIS using various data sets like shoping data set etc
 
Bank Loan Approval Analysis: A Comprehensive Data Analysis Project
Bank Loan Approval Analysis: A Comprehensive Data Analysis ProjectBank Loan Approval Analysis: A Comprehensive Data Analysis Project
Bank Loan Approval Analysis: A Comprehensive Data Analysis Project
 
Statistics For Management by Richard I. Levin 8ed.pdf
Statistics For Management by Richard I. Levin 8ed.pdfStatistics For Management by Richard I. Levin 8ed.pdf
Statistics For Management by Richard I. Levin 8ed.pdf
 
Digital Indonesia Report 2024 by We Are Social .pdf
Digital Indonesia Report 2024 by We Are Social .pdfDigital Indonesia Report 2024 by We Are Social .pdf
Digital Indonesia Report 2024 by We Are Social .pdf
 
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...
6 Tips for Interpretable Topic Models _ by Nicha Ruchirawat _ Towards Data Sc...
 
Insurance Churn Prediction Data Analysis Project
Insurance Churn Prediction Data Analysis ProjectInsurance Churn Prediction Data Analysis Project
Insurance Churn Prediction Data Analysis Project
 
Non Text Magic Studio Magic Design for Presentations L&P.pdf
Non Text Magic Studio Magic Design for Presentations L&P.pdfNon Text Magic Studio Magic Design for Presentations L&P.pdf
Non Text Magic Studio Magic Design for Presentations L&P.pdf
 

Oracle SQL DML Statements

  • 1. Oracle DML Statements DML: Data Manipulation Language Used to add, change or delete data INSERT– add rows to a table UPDATE – update existing rows in a table. MERGE – update if rows exist, insert if they don’t DELETE – delete rows from a table http://adata.guru
  • 2. Transactions  A transaction is a sequence of SQL statements that Oracle Database treats as a single unit.  Atomic unit of work that takes the database from one consistent state to another.  Entire transaction succeeds or fails. No half-transactions.  From the first DML statement to the first commit/rollback. http://adata.guru
  • 3. Transaction Control Statements Commit Ends your current transaction and make permanent all changes performed in the transaction. Oracle Database issues an implicit COMMIT before and after any data definition language (DDL) statement. Rollback: Undo work done in the current transaction. If you do not explicitly commit the transaction and the program terminates abnormally, then Oracle Database rolls back the last uncommitted transaction. http://adata.guru
  • 4. DML Statements – INSERT  insert into <table_name> ( <column_names>) Values (<column values>) Insert into EMP (EMPNO,ENAME,JOB,MGR,HIREDATE,SAL,COMM,DEPTNO) values (7369,'SMITH','CLERK',7902,to_date('17-DEC-1980','DD-MON-YYYY'),800,null,20);  Insert into table_name ( < column names >) { select query } Insert into locations (loc_name) select loc from scott.dept union select state_province from hr.locations; http://adata.guru
  • 5. DML Statements – UPDATE UPDATE <table_name> SET <column-value-pairs> WHERE <conditions>; Update based on primary key: UPDATE oe.customers SET account_mgr_id = 149, credit_limit = 3000 WHERE customer_id = 240; Update a few rows based on a condition: UPDATE oe.warehouses SET warehouse_name = ‘Mumbai’ WHERE warehouse_name = ‘Bombay’; No filter conditions.. Update all rows in the table. UPDATE oe.customers SET cust_email = upper(cust_email); http://adata.guru
  • 6. DML Statements – MERGE/UPSERT MERGE into tgt_table USING (source_table/source query) ON <matching-conditions> WHEN MATCHED then update <column-value pairs> WHEN NOT MATCHED then INSERT <column-value pairs> http://adata.guru
  • 7. DML Statements – DELETE Syntax : DELETE from <table_name> WHERE <conditions>; Delete (one row) based on primary key: DELETE from oe.customers WHERE customer_id = 240; DELETE a few rows based on a condition: DELETE from oe.warehouses WHERE warehouse_name = ‘Bombay’; No filter conditions.. DELETE all rows in the table. DELETE from oe.customers; http://adata.guru
  • 8. Delete v/s Truncate http://adata.guru HWM HWM HWM HWM HWM Initial table creation. Full table scans are pretty quick, since there are no blocks to scan One million rows inserted (for example). High water mark is advanced and oracle scans blocks till HWM during a full scan. Inevitable. Half a million rows deleted. HWM remains unchanged, oracle still scans all the blocks during a full table scan. All rows are deleted using “delete” command. HWM still at the same location, makes oracle still do full table scans. Returns no data though. TRUNCATE resets high water mark causing full- scans and other operations to perform much faster.