Do you want to learn Oracle Database or Oracle statement?? In this tutorial, you will learn how to write Oracle SELECT statement or query.
Database tables are consists of columns and rows. We use the oracle select statement to retrieve data from one or more columns of a table or view, with the following basic syntax:
1 2 3 4 |
SELECT column_1, column_2, ... FROM table_name; |
Note that the SELECT statement is very complex that consists of many clauses such as ORDER BY
, GROUP BY
, HAVING
, JOIN
. To make it simple, in this tutorial, we are focusing on the SELECT and FROM clauses only.
Oracle SELECT examples
For example, we use the Employees table in the sample database that has the following columns: employee_id, first_name, last_name, email, phone and hire_date, manager_id, job_title. The Employees table also has data in these columns.
Query data for a single column
To get a single column like first_name
from the Employees table, you use the following statement:
1 2 3 4 |
SELECT first_name FROM employees; |
Query data for multiple columns
To get data from multiple columns, you specify a list of comma-separated column names. The following example shows how to query data from the first_name
, last_name
, and email
columns of the Employees table.
1 2 3 4 |
SELECT first_name, last_name, email FROM employees; |
Query data for all columns of a table
The retrieves all columns of the Employees table you can write all column names. You can also use the shorthand asterisk (*) to instruct Oracle to return data from all columns of a table as follows:
1 2 3 |
SELECT * FROM employees; |
Select query from Dual table
In Oracle, the SELECT statement must have a FROM clause. However, some queries don’t require any table like UPPER()
function. Fortunately, Oracle provides you with the DUAL
table which is a special table. By using the DUAL
table, you can execute queries that contain functions that do not involve any table like the UPPER()
function as follows:
1 2 3 4 5 6 7 |
SELECT UPPER('This is a string') FROM dual; ----- or ----------- SELECT (10 + 5)/2 FROM dual; |
The article was published on July 16, 2020 @ 5:20 PM
Thanks for sharing the information Arik. Keep it up Man!