Oracle Database-Basic SELECT statement

Source: Internet
Author: User

1. Basic SELECT statement

1) View Current user
Show User
USER is "SCOTT"
2) Query the table under the current user
Sql> select * from tab;

Tname Tabtype Clusterid
------------------------------ ------- ----------
DEPT TABLE
EMP TABLE
BONUS TABLE
Salgrade TABLE

3) View the structure of the employee table
Sql> desc EMP
is the name empty? Type
----------------------------------------- -------- ----------------------------
EMPNO not NULL number (4)
Ename VARCHAR2 (10)
JOB VARCHAR2 (9)
MGR Number (4)
HireDate DATE
SAL Number (7,2)
COMM Number (7,2)
DEPTNO Number (2)

4) Clear Screen
Sql> Host CLS

5) Check all employee information
Sql> select * from EMP;

6) Set the line width
Sql> Show Linesize
Linesize 80
Sql> Set Linesize 120
7) Set the column width
Sql> Col ename for A8
Sql> Col Sal for 9999
Sql>/

 8) By Column name
Sql> Select Empno,ename,job,mgr,hiredate,sal,comm,deptno
2 from EMP;

  

  Principles of SQL Optimization:
1. Use column names as much as possible

9) Query Employee information: Employee Number name monthly salary
Sql> Select Empno,ename,sal

C command change
   

 11) Query Employee Information: Employee Number name monthly salary
Sql> Select Empno,ename,sal,sal*12
2 from EMP;

  12) Query Employee information: Employee Number name salary annual salary bonus annual income
  Sql> Select Empno,ename,sal,sal*12,comm,sal*12+comm
2 from EMP;

  

  NULL in SQL
1. An expression that contains null is NULL
2, NULL forever! =null

NVL (A, b) nvl2 when A is null and the value is
  

 NULL in SQL

2, NULL forever! =null
  15) search for employees with bonus null
  Sql> SELECT *
2 from EMP
3 where comm=null;

   

 Sql> SELECT *
2 from EMP
3 where comm is null;

  

  16) Alias of column

  Select Empno as "employee number", ename "name", Sal "Monthly Salary", SAL*12,COMM,SAL*12+NVL (comm,0)
From EMP
  

  Distinct remove duplicate records

Sql> select Deptno from emp;

  Sql> SELECT DISTINCT deptno from EMP;

  Sql> Select Job from EMP;

  Sql> SELECT distinct job from EMP;

sql> SELECT distinct deptno,job from EMP;

  Distinct acts on all subsequent columns

18) connector | |

concat function

  Sql> Select Concat (' Hello ', ' World ') from EMP;

  

  Sql> Select Concat (' Hello ', ' world ') from dual;

Dual table: Pseudo table
Pseudo-Column
Select ' Hello ' | | ' World ' string from dual;

  

  Query Employee Information: * * * Salary is * * * *
Sql> Select Ename| | ' The salary is ' | | Sal information from EMP;

  

Oracle Database-Basic SELECT statement

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.