Method: 1. Use the "SELECT column name FROM table name;" statement to query the data of a single column; 2. Use the "SELECT column name 1, column name 2... FROM table name;" statement to query Query the data of multiple columns; 3. Use the "SELECT * FROM table name;" statement to query the data of all columns.
The operating environment of this tutorial: Windows 7 system, Oracle 11g version, Dell G3 computer.
In Oracle, a table is composed of columns and rows. For example, the customers
table in the sample database has the following columns: customer_id
, name
, address
, website
, and credit_limit
. customers
There is also corresponding data in these columns in the table.
To select one or more columns from the table (column_1
,column_2
,...
,column_n
) to retrieve data, please use the SELECT
statement with the following syntax:
SELECT column_1, column_2, ... FROM table_name;
In this SELECT
statement:
,
). Please note that the SELECT statement is very complex and consists of many clauses, such as ORDER BY, GROUP BY, HAVING, JOIN. For the sake of simplicity, in this tutorial, we only focus on the usage of
SELECT
andFROM
clauses.
Let us give some examples using Oracle SELECT
statements to understand how it works.
1. Query the data of a single column
To query the data from the customers (customers
) table To obtain the customer name (name
) column, please use the following statement:
SELECT name FROM customers;
Execute the above statement and return partial results as follows -
NAME ------------------------------------------------------------------------ Aetna AIG Intel Pfizer FedEx New York Life Insurance Ingram Micro American Airlines Group Johnson Controls Goldman Sachs Group Oracle 已选择319行。
2 . Query data from multiple columns
To query data from multiple columns, specify a comma-separated list of column names.
The following example shows how to query data from the customer_id
, name
and credit_limit
columns of the Customers (customers
) table .
SELECT customer_id, name, credit_limit FROM customers;
Execute the above example code and get the result
##3. Query the data of all columns in the table
The following example will retrieve data from all columns of thecustomers table, listing the names of all columns as follows:
SELECT customer_id, name, address, website, credit_limit FROM customers;Execute the above example code, the following results are obtained - For convenience, viewing all columns can use the abbreviation asterisk (
*) to instruct Oracle to return all columns from the table The data in the column is as follows:
SELECT * FROM customers;Execute the above sample code and get the following results
*)carry out testing. In practice, even if you want to retrieve data from all columns of a table, you should explicitly specify the column from which you want to query the data.
*) in your application code, it is assumed that the table has a fixed set of columns, but the application may not handle other unrelated columns or access deleted columns.
Oracle Tutorial"
The above is the detailed content of How to query column data of a table in oracle. For more information, please follow other related articles on the PHP Chinese website!