Basic Learning for Oracle (ii)-Basic query

Source: Internet
Author: User
Tags define null

First, the basic query statement


(1) View Current user

Show user;

(2) View the table under the current user

SELECT * from tab;

(3) View the structure of the employee table

DESC EMP;

(4) Select all Columns

SELECT * from EMP;

(5) Select a specific column

SELECT Empno,ename,sal,comm,deptno from EMP;

(6) Define null values

A: null value is not valid, unspecified, unknown value.

B: null value is not a space or 0.

C: The value of a data expression that contains a null value is null.

--null value differs from 0, all null values are null--select employee_id,       last_name,       salary,       commission_pct,       salary * (1 + commission_pct) from  employees;

After rewriting:

--NVL function----Format: NVL (e1,e2)----Explanation: If E1 is null, the function returns E2, otherwise it returns E1. --select employee_id,       last_name,       salary,       commission_pct,       salary * (1 + NVL (commission_pct,0))  From employees;

(7) using aliases

A: Write directly after the column name.

B: Add the keyword as between the column name and the alias.

C: Use double quotation marks.

--use alias--select employee_id ID,       last_name as name,       12*salary "Annual_sal" from employees;

(8) Delete duplicate rows

--Use the keyword "DISTINCT" To remove duplicate lines--select DISTINCT department_id from employees;

Second, filtering and sequencing

(1) WHERE clause

A: Use the WHERE clause to filter out rows that do not meet the criteria.

The B:where clause follows the FROM clause.

Select Employee_id,last_name,salaryfrom employeeswhere employee_id > 200;

(2) characters and dates

A: The characters and dates are enclosed in single quotes.

B: Character case sensitive, date format sensitive.

C: The default date format is: Dd-mm month-yyyy.

Select employee_id, last_name, salary, hire_date from  employees where hire_date= ' 1 July-September-1987 ';

This is inconvenient to write, we usually write:

Select employee_id, last_name, salary, hire_date from  employees where TO_CHAR (hire_date, ' yyyy-mm-dd ') = ' 1987-09-17 ‘;

Basic Learning for Oracle (ii)-Basic query

Related Article

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.