EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials Oracle Tutorial Oracle Queries
Secondary Sidebar
Oracle Tutorial
  • Advanced
    • Timestamp to Date in Oracle
    • Oracle Golden Gate
    • Oracle Virtual Machine
    • Oracle Describe Table
    • Oracle Clauses
    • Oracle Having Clause
    • Oracle?Primavera
    • Oracle FOREIGN Key
    • PIVOT in Oracle
    • Oracle Alter Table
    • Oracle Queries
    • Oracle Views
    • Oracle Window Functions
    • Oracle String Functions
    • Oracle Date Functions
    • Oracle Analytic Functions
    • Oracle Aggregate Functions
    • Select in Oracle
    • INSERT in Oracle
    • DISTINCT in Oracle
    • Function in Oracle
    • Oracle GROUP_CONCAT
    • Oracle INSTR()
    • Oracle CONVERT
    • Oracle LENGTH()
    • Oracle EXISTS
    • Oracle REPLACE()
    • Oracle MERGE
    • Oracle LEAD()
    • Oracle EXTRACT()
    • Oracle LISTAGG()
    • Oracle SYS_CONTEXT()
    • Oracle COALESCE
    • Oracle NVL()
    • Oracle SYSDATE()
    • Oracle?Date Format
    • Oracle SYS_GUID()
    • Oracle WILDCARDS
    • Oracle Synonyms
    • Oracle Subquery
    • BETWEEN in Oracle
    • FETCH in Oracle
    • Oracle Index
    • Oracle Function-based Index
    • Oracle UNIQUE Index
    • Oracle Bitmap Index
    • Oracle Column
    • Oracle Triggers
    • Oracle Procedures
    • Sample Database for Oracle
    • Oracle LIKE Operator
    • ORDER BY in Oracle
    • Oracle ORDER BY DESC
    • GROUP BY in Oracle
    • Oracle GROUP BY HAVING
    • Oracle Aliases
    • Table in Oracle
    • Oracle Temporary Table
    • Oracle? Table Partition
    • Oracle rename table
    • Oracle CTE
    • Cursor in Oracle
    • Oracle LOCK TABLE
    • Oracle Tablespace
    • Oracle CARDINALITY
    • Oracle REGEXP
    • Oracle REGEXP_REPLACE
    • Oracle to_date
    • JSON in Oracle
    • Oracle COMMIT
    • Oracle GRANT
    • Oracle MD5
    • Oracle ROLLBACK
    • Oracle Users
    • Oracle TIMESTAMP
    • IF THEN ELSE in Oracle
    • Oracle While Loop
    • Oracle Clone Database
    • Oracle Backup Database
    • Oracle? XML
    • Oracle XMLAGG
    • Oracle XMLTABLE
    • Oracle Performance Tuning
    • Oracle B Tree Index
    • Oracle fusion
    • Oracle ebs
    • Oracle GRC
    • Oracle ERP
    • Oracle ASM
    • Oracle Cloud
    • Oracle HCM Cloud
    • Oracle Integration Cloud
    • Oracle Jinitiator
    • Oracle pathfinder
    • Oracle VirtualBox
    • Oracle Weblogic Server
    • Oracle decode
    • Oracle Exadata
    • Oracle ZFS
    • Oracle? utilities
    • JDBC Driver for Oracle
    • Oracle? DBA Versions
    • Oracle DBA Salary
  • Basic
    • Oracle Marketing Cloud
    • What is Oracle?
    • Career in Oracle
    • How to Install Oracle
    • Oracle Versions
    • What Is Oracle Database
    • Oracle Data Warehousing
    • Oracle Warehouse Builder
    • Career In Oracle Database Administrator
    • Career In Oracle DBA
    • What is Oracle RAC
    • Oracle DBA
    • Oracle? Vanderbilt
    • What is RMAN Oracle
    • Oracle Database Administration
    • Oracle Operators
    • Oracle Constraints
    • Oracle number
    • Oracle Data Types
    • Oracle UNIQUE Constraint
    • Oracle Check Constraint
  • Joins
    • Joins in Oracle
    • Inner Join in Oracle
    • Oracle Cross Join
    • Left Join in Oracle
    • OUTER Join in Oracle
    • Oracle Full Outer Join
    • Natural Join in Oracle
    • Oracle Self Join
    • Oracle hash join
    • Oracle? Update with Join
  • Oracle SET Operators
    • UNION in Oracle
    • Oracle UNION ALL
    • INTERSECT in Oracle
    • MINUS in Oracle
  • Interview Questions
    • Oracle Interview Questions
    • Oracle Apps Interview Questions
    • Oracle Apps Technical Interview Questions
    • Oracle Database Interview Questions
    • Oracle Forms Interview Questions
    • Oracle PL/SQL Interview Questions
    • Oracle RAC Interview Questions
    • Oracle SOA Interview Questions

Related Courses

Oracle Course Training

Oracle DBA Certification Course

MongoDB Certification Training

Oracle Queries

By Priya PedamkarPriya Pedamkar

oracle queries

Introduction to Oracle Queries

Query is a type of language used in Oracle database to retrieve data from tables, manipulate the data (insert records into the tables present in the database, update the values of column/columns of a particular table and also delete the records of the tables stored in database), also it is popularly known as SQL or Structured query language (structured query because Oracle database is structured database since data is stored in the form of rows and columns).

Types of Oracle Queries

Now let us look at the types of Oracle Queries. We will go through each one of them one by one.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (85,992 ratings)

1. SELECT Query

This query is used when we want to retrieve the data from one or more tables. There is no data manipulation done when we execute this query. Let us understand the syntax with example.

SELECT expressions
FROM tables
[Where conditions]

Parameters:

  • Expressions: It represents the columns that we want to retrieve. If we want all the columns we can use *
  • Tables: Here we provide the name of the table or tables from where we want the data.
  • Where Condition: This is optional. It is used when we want data to be retrieved based on certain conditions. If we use where condition then the data will be retrieved only if the condition is satisfied.

Example:

SELECT * FROM employees WHERE age > 32;

In this example, we are selecting all fields (as we have used *) where the age is greater than thirty-two (the where condition states that age should be greater than thirty-two).

Now we will see how to select from multiple tables the first example was to select from only one table.

SELECT employees.employeeid, vehicles.name FROM employees INNER JOIN vehicles ON employees.vehicleid = vehicles.vehicleid ORDER BY employeeid;

In the second example, the select statement joins two tables and gives us the employee id from table employees and vehicle names from table vehicles based on the vehicle id.

2. INSERT Query

As the name suggests this query is used to add single or multiple records in the table. It causes data manipulation in the table. Let us understand by syntax and example.

Single Record

INSERT INTO
Table (column1, column2, …., columnn1)
VALUES (value 1, value 2, …., value n1)

Multiple Records

INSERT INTO
Table (column1, column2, …., columnn1)
SELECT(value 1, value 2, …., value n1)
FROM source table
WHERE condition

Parameters

  • table: Name of the table in which data is to insert
  • column1, column2, …., column1: These are the name of columns in which values are to be inserted.
  • value 1, value 2, …., value n: Values or expressions to be inserted in the aforementioned columns.
  • source table: The table from where data will be inserted
  • WHERE condition: Optional clause, It is required if data is to be inserted based on some condition.
Example:

Now let us go through some examples.

Single Record

INSERT INTO employees
(employeeid, name, age)
VALUES(“AB005”, ”Nilanjan”, 27);

In the above example, we are inserting a single record into the already created employe table.

Multiple Records

INSERT INTO CUSTOMERS
(customerid, name, age)
SELECT employeeid, name, age
FROM employees WHERE age>25;

In the above example, we are inserting records into the customer’s table from the employee table where age in employees table is greater than 25.

3. UPDATE Query

This query is used to update existing records in a table that is present in the oracle database. We can use this query two ways either directly giving the value to update or using a select statement to get the value and then update. We will understand it further using syntax and examples.

Syntax:

UPDATE table
SET column1 = expression1,
column2 = expression2,
column3 = expression3,
……
columnn1 = expressionn1
[WHERE condition];

Using Select Statement

UPDATE table
SET column1 = SELECT expression1,
FROM table2 [where conditions])
[WHERE condition];

Parameters

  • [Column1…columnn1]: It represents the columns whose values we want to update.
  • [expression1…..expressionn1]: It represents the values that we want to assign to the respective columns.
  • WHERE conditions: It specifies the condition which has to be fulfilled for the update to take place.

Example #1:

UPDATE employees
SET name=”Rajesh”
WHERE employeeid=”AB003”;

In this first example, we are directly providing the value to be updated in the column based on a condition.

Example #2:

UPDATE employees
SET vehicle= (SELECT name FROM vehicles
WHERE vehicleid =”1254”)
WHERE employeeid=”AD003”;

In this second example, we are providing the value by retrieving it from another table using a select query.

4. DELETE Query

This query is used to delete existing records from the table. One important point to keep in mind here is that if you want to delete records or record based on condition then we have to use WHERE clause or else it will delete all the records from the table.

Syntax:

DELETE FROM table
WHERE [condition]

Parameters

  • Table: It is for the name of the table
  • [Condition]: The records which satisfy this condition will get deleted.

Example #1:

DELETE FROM employees
WHERE employeeid=’AD003’;

Example #2:

DELETE FROM employees;

In the first example, only the record with id ‘AD003’ gets deleted while in the second example the employees’ table would not have any record.

5. TRUNCATE Query

This query is also used to delete records from an existing table. The difference between delete and truncate is DELETE is DML command whereas TRUNCATE is DDL which means TRUNCATE query upon execution cannot be rolled back. It can be rolled back only if it is wrapped in a transaction.

Syntax:

TRUNCATE TABLE table name;

Example:

TRUNCATE table employees;

Once we execute the above TRUNCATE query it deletes all records from the existing employees’ table.

Recommended Articles

This is a guide to Oracle Queries. Here we discuss what is a query in general with respect to database operations. The different types of oracle queries that are present and how to use them. You may also look at the following articles to learn more –

  1. Oracle Database Architecture
  2. Education Required For Career in Oracle
  3. Top 10 Oracle Apps Interview Questions
  4. Difference Between MySQL vs Oracle
  5. Guide to the Top 9 Oracle Clauses (Example)
  6. Examples of Inner Join in Oracle
  7. Guide to INSERT Statement in Oracle
Popular Course in this category
Oracle Training (14 Courses, 8+ Projects)
  14 Online Courses |  8 Hands-on Projects |  120+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Oracle DBA Database Management System Training (2 Courses)4.9
All in One Financial Analyst Bundle- 250+ Courses, 40+ Projects4.8
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more