Oracle SELECT Statement
Summary: in this tutorial, you will learn how to use the Oracle SELECT
statement to query data from a single table.
In Oracle, tables are consists of columns and rows. For example, the customers
the table in the sample database has the following columns: customer_id
, name
, address
, website
and credit_limit
. The customers
the table also has data in these columns.
To retrieve data from one or more columns of a table, you use them SELECT
the statement with the following syntax:
1 2 3 4 5 6 | SELECT column_1, column_2, ... FROM table_name; |
In this
SELECT
statement:- First, determine the table name from which you need to inquire about the data.
- Second, demonstrate the columns from which you need to restore the data. If you have more than one column, you have to isolate each by a comma (,).
Note that the SELECT
the 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
How about we take some examples of utilizing the Oracle SELECT statement to see how it functions.
1) query data from a single column
To get the customer names from the customers
table, you use the following statement:
1 2 3 4 | SELECT name FROM customers; |
The accompanying picture outlines the outcome:
2) Querying data from multiple columns
To question information from various columns, you indicate a list of comma-isolated column names.
The following example shows how to query data from the customer_id
, name
, and credit_limit
columns of the customer
table.
1 2 3 4 5 6 | SELECT customer_id, name, credit_limit FROM customers; |
The following shows the result:
3) Querying data from all columns of a table
The accompanying example recovers all rows from all columns of the customer’s table:
1 2 3 4 5 6 7 8 | SELECT customer_id, name, address, website, credit_limit FROM customers; |
Here is the result:
To make it handy, you can use the shorthand asterisk (*) to instruct Oracle to return data from all columns of a table as follows:
1 | SELECT*FROM customers; |
Note that you should just utilize the reference asterisk (*) for testing purposes. By and by, you ought to expressly indicate the columns from which you need to inquiry data notwithstanding when you want to recover data from all segments of a table.
This is because a table may have more or fewer columns in the future due to the business changes. If you use the asterisk (*) in the application code and assume that the table has a fixed set of columns, the application may either not process the additional columns or access the deleted columns.
In this tutorial, you have learned how to use Oracle SELECT
statement to retrieve data from one or more columns of a table.