UPDATE Statement in Oracle SQL | Oracle SQL Tutorials -10

Hi,

I will explain UPDATE Statement in Oracle SQL in this post of Oracle SQL Tutorial series.

Read the previous post of this tutorial series before this.

The UPDATE statement is popular command of Oracle SQL and You can modify any existing record in a table using Update Statement.

UPDATE Syntax

Update statement syntax is as follows.

 

UPDATE table_name SET column1 = value1 WHERE condition;

UPDATE table_name SET column1 = value1, column2 = value2, … WHERE condition;

UPDATEtable_name SETcolumn1 = value1, column2 = value2, … WHEREcondition;
Update employee’s First name and Last Name column which EMPLOYEE_ID=100 as follows
SQL> update hr.employees set FIRST_NAME='MEHMET SALIH', LAST_NAME='DEVECI' where EMPLOYEE_ID=100;

1 row updated.

SQL> commit;

Commit complete.

SQL> 

SQL> 
SQL> select EMPLOYEE_ID,FIRST_NAME,LAST_NAME from hr.employees where EMPLOYEE_ID=100;

EMPLOYEE_ID FIRST_NAME           LAST_NAME
----------- -------------------- -------------------------
        100 MEHMET SALIH         DEVECI

SQL>
You can update multiple records in a Update statement as follows.
Let’s raise salary of employees that salary is greater than 15000 as follows.
SQL> select EMPLOYEE_ID,FIRST_NAME,LAST_NAME,SALARY from hr.employees where salary>15000;

EMPLOYEE_ID FIRST_NAME           LAST_NAME                     SALARY
----------- -------------------- ------------------------- ----------
        100 MEHMET SALIH         DEVECI                         24000
        101 Neena                Kochhar                        17000
        102 Lex                  De Haan                        17000

SQL> 
SQL> update hr.employees set salary=salary+5000 where salary>15000;

3 rows updated.

SQL> commit;

Commit complete.

SQL> 
SQL> select EMPLOYEE_ID,FIRST_NAME,LAST_NAME,SALARY from hr.employees where salary>15000;

EMPLOYEE_ID FIRST_NAME           LAST_NAME                     SALARY
----------- -------------------- ------------------------- ----------
        100 MEHMET SALIH         DEVECI                         29000
        101 Neena                Kochhar                        22000
        102 Lex                  De Haan                        22000

SQL>
Or update employees’ commission_pct as 0.5 if commission_pct  are null.
SQL> update hr.employees set commission_pct=0.5 where commission_pct is null;

72 rows updated.

SQL> commit;

Commit complete.

SQL>

 

If you don’t use or forget to use WHERE clause, ALL records will be updated! So be carefull during update.

 

 

 

For Example, I don’t use or forget to use Where clause, then All employees’ salary raised by 1000 $ 🙂

SQL> update hr.employees set SALARY=SALARY+1000;

107 rows updated.

SQL> commit;

Commit complete.

SQL>

 

 

 

 

Do you want to learn Oracle Database for Beginners, then read the following articles.

 33 views today,  4 views in last 3 hour

Mehmet Salih Deveci

I am Founder of SysDBASoft IT and IT Tutorial and Certified Expert about Oracle & SQL Server database, Goldengate, Exadata Machine, Oracle Database Appliance administrator with 10+years experience.I have OCA, OCP, OCE RAC Expert Certificates I have worked 100+ Banking, Insurance, Finance, Telco and etc. clients as a Consultant, Insource or Outsource.I have done 200+ Operations in this clients such as Exadata Installation & PoC & Migration & Upgrade, Oracle & SQL Server Database Upgrade, Oracle RAC Installation, SQL Server AlwaysOn Installation, Database Migration, Disaster Recovery, Backup Restore, Performance Tuning, Periodic Healthchecks.I have done 2000+ Table replication with Goldengate or SQL Server Replication tool for DWH Databases in many clients.If you need Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS Consultancy and Training you can send my email adress mehmetsalih.deveci@outlook.com.-                                                                                                                                                                                                                                                 -Oracle DBA, SQL Server DBA, APPS DBA,  Exadata, Goldengate, EBS ve linux Danışmanlık ve Eğitim için  mehmetsalih.deveci@outlook.com a mail atabilirsiniz.

Leave a Reply