Get the App
SLTechnology News&Howtos  ›  Database  › 

Chapter 1: select statement of oracle_sql statement

Shulou Source: shulou.com Published: 2022-06-01 09:19:57 10月01日 Update

Which tables do scott users have?

SQL > select * from tab

Query all rows and columns in the table

SQL > select * from dept

SQL > select * from emp

Save the buffer command as a script:

SQL > save 1.sql

View the contents of the script file:

SQL > get 1.sql

Run the script file:

SQL > @ 1.sql

Query the columns of interest in the table

Select ename,sal from emp

Four operations are used in query

Select ename,sal*12 from emp

Select ename,comm,sal+comm from emp

Null value (null): undefined value, uncertain value, neither zero nor space!

Null values can not directly participate in the four operations!

Name the column aliases in the query

Select ename,sal*12 as annual_salary from emp

-- as is an optional keyword that can be omitted

Select ename,sal*12 annual_salary from emp

Use special characters in aliases, and aliases should be double quoted

Select ename,sal*12 "annual salary" from emp

Join operator: combines multiple columns into one column output

Select ename,job from emp

Select ename | |'is a'| | job from emp

Compress duplicate value

Select deptno from emp

Select distinct deptno from emp

Describe the table structure

Desc emp

Exercise 1

Chapter 1 basic select statement:

1. Make a query to display all the data in the dept table

two。 Make a query to display several ename,job,sal columns in the emp table, in which the sal column is displayed as salary in the result set.

3. Make a query to display the deptno,ename, annual salary in the emp table, and alias the annual salary annual salary

4. Get the structure of the emp table

5. Make a query that displays the employee number, employee name, job, hire date in the emp table, and save the query as a script, script name p1q7.sql

6. Run p1q7.sql

7. Create a query to display the department number in the employee table, and the duplicate department number is displayed only once

8. In the result set, employee names and work connections are separated by "spaces comma spaces" and column headers are displayed as Employee and Title

Tags: Query script alias employee space and will four operations name four salary file query table structure results department work operation run statement special Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple macOS Linux Shulou Technology MySQL