Oracle database query select-day01

Oracle Knowledge Command Daquan-day01

web version sqlplus

http://localhost:5560/isqlplus/workspace.uix

Ordinary user login

sqlplus scott/11

Super user login

sqlplus /nolog
connect /as sysdba

See what tables are under the user

desc employees; --(->表名)

Query all formats

select * from employees; --(->表名)

Query employee ID, surname, Email

select employees_id, last_name, email from employees;

Addition, subtraction, multiplication and division of numbers in query statements

select last_name, salary, salary * 12 + 1000;

Addition and subtraction of query dates
Multiplication and division of dates has no practical meaning

select sysdate, sysdate + 1, sysdate - 2 from dual;

Null value problem

select * from employees;
--凡是空值参与运算,结果都为空
select employee_id, salary, commission_pct, salary*(1 + commission_pct) from employees;

Alias

--annual_sal 是别名
select employee_id, last_name, 12*salary annual_sal from employees;

The alias is generally used as but as can be omitted. At the same time, double quotation marks are generally used. However, if the upper and lower case is used or is composed of two words, double quotation marks must be used.

The concatenator ||
puts the column in the column, and the column and the string together,

select last_name || '`s job is '|| job_id as "dettails" from employees;
select last_bane || '`s email is' || email as "dettails" from employees;

String A
string can be a character, number, or date in the select list.
Whenever a row is returned, the string is output once, and the date is connected with single quotes

select last_name|| '`s hire_date is '|| hire_date as "dettials" from employees;

Delete duplicate rows

select last_name, department_id from employees;
select  distinct department_id from employees;

How to view the information of the table
desc employees;

Exercises:
1. Display the structure of the employees in the table, and query all the data in it
2. Display all the job_id of the employees in the table (cannot be repeated)
3. First output all the columns of the employees in the table, connect each column with a comma, and the column header Show OUT_PUT

The Practice Answer

--显示表结构
desc employees;
--查询全部数据
select * from employees;
--显示出表employees的全部不重复job_id
select distinct job_id from employees;
--输出表employees的全部列
desc employees;
--各个列之间用逗号连接 列头显示出OUT_PUT
select employee_id || ',' || last_name || ',' || first_name || ',' || email as "OUT_PUT"  from employees

Guess you like

Origin blog.csdn.net/god953/article/details/109306084