Oracle Database SQL --- select Query

Source: Internet
Author: User
The best way to learn is practice! Therefore, my learning is based on practice. The most basic SQL statement is the query statement.

The best way to learn is practice! Therefore, my learning is based on practice. The most basic SQL statement is the query statement.

Preface

The best way to learn is practice! Therefore, my learning is based on practice. The most basic SQL statement is the query statement. Therefore, I also learned from the select statement. (In fact, this part of the author) has been mastered, but it is still necessary to grasp it again.

For the previous study, we mainly used some existing tables in the Oracle database. Here I use Scott as a classic user to perform related exercises and operations! Start!

A simple query:

Select * from emp; -- Query all the information of the emp table.

Use expressions in queries

Select emp. sal * 12 from emp; -- query the annual salary of all employees (assuming so)
Select emp. ename, sal * 12 + 500 from emp;

Aliases for columns (required)

Select emp. ename "name" from emp; -- alias usage

Processing of null values

First of all, we must understand that when we take values from the database, it is possible that the value of this field is not "NULL". However, this is unreasonable in some arithmetic expressions, therefore, the NVL function must be used for processing:

Select emp. ename, emp. sal + emp. sal * NVL (NULL, 0) from emp; -- processing of NULL values

NVL: replace null with the specified value.

Remove duplicate rows

In reality, we do not need to count the items that have appeared multiple times.

1. do not duplicate the demo:

Select emp. sal from emp order by sal asc; -- in ascending order

2. Remove the two repeated items in the above list

Select distinct emp. sal from emp; -- use the distinct keyword to repeat

3. How can I remove multiple repeated columns of rows?

Select distinct ename, emp. sal from emp order by sal asc;

Well, the basic usage of the select statement is here. I certainly haven't summarized some details.

But the most basic is enough.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.