Home  >  Article  >  Database  >  How to query column data of a table in oracle

How to query column data of a table in oracle

青灯夜游
青灯夜游Original
2022-01-25 18:00:5310330browse

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.

How to query column data of a table in oracle

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. customersThere is also corresponding data in these columns in the table.

How to query column data of a table in oracle

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:

  • First, you need to specify the name of the table to query data.
  • Secondly, specify the column in which you want to return data. If you need to return multiple columns, you need to separate these columns with commas (, ).

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 and FROM clauses.

Oracle SELECT Examples

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

How to query column data of a table in oracle

##3. Query the data of all columns in the table

The following example will retrieve data from all columns of the

customers 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 -

How to query column data of a table in oracle

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


How to query column data of a table in oracle

Please note that only asterisks (

*)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.

This is because of business changes, the table may have more or fewer columns in the future. If you use asterisks (

*) 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.

Recommended tutorial: "

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn