oracle database study notes (c)

1. Scheduling
default collation: according to the order of the physical storage.
Specify a collation: order by keyword
position: select query into the rearmost statement.
Syntax: select..from ... order by field ordering rules;
field is used to declare sorted according to which field.
Collation:
1) in ascending order from small to large asc
2) in descending order from largest to smallest desc
example: query id for all employees, salary
requirements are arranged in descending order of salary?
the above mentioned id the SELECT, salary
from s_emp
the Order by salary desc;

specify multiple sorting rules:
grammar: the SELECT ..
from ...
the Order by field 1 collation 1,
Field 2 2 ...... collation;
for example: all queries employee id, salary
arranged in ascending and descending order id wages?
the above mentioned id the SELECT, salary
from s_emp
the Order by salary desc, the above mentioned id asc;

Handling null values:
commission_pct - commission
at the time of ordering, null values are considered infinite.
In descending order, the null at the top.
In ascending order, the null at the bottom surface.

2. limiting the query / query condition
specified query conditions in the query,
to remove a portion of the screen unwanted data.
Keywords: where
position: from behind into the clause.
select ... from ... where .... order by ...;
Syntax: select..from..where judgment conditions;

1) Analyzing the equivalent and non-equivalent determination
field value is equal to or not equal to a specific value.
For example:
query employee information 41 department?
Field: the dept_id
SELECT ID, last_name, the dept_id
from s_emp
WHERE = 41 is the dept_id;

How to represent not equal to
three kinds of writing:
writing a:! =
Writing II: ^ =
written three: <>

handle null values:
null: is null
is not empty: is not null
For example:
query all the employee information does not take commission ?
ID SELECT, last_name, the salary
from s_emp
WHERE IS a commission_pct null;

? Inquiry commission to take all the employee information
the SELECT ...
from ..
the WHERE IS commission_pct not null;

2) determines the range of
greater than>
Less than <
greater than or equal to> =
Less than or equal <=

example:
Search paid more than $ 1100 employee information?
SELECT ID, last_name, the salary
from s_emp
WHERE the salary> 1100 is;

All inquiries wage of not less than 1,100 yuan employee information?
The SELECT the above mentioned id, last_name, salary
from s_emp
the WHERE salary> = 1100;

3) conditions tied
a) logic and
use and connections must meet all the conditions
of the will of the record queried out.
b) or an OR logic
using all of the conditions or connected only need to meet one,
this data will be check out.

For example:
Query No. 41 sector wages greater than $ 1400 employee information?
ID SELECT, last_name, the dept_id
from s_emp
WHERE = 41 is the dept_id and the salary> 1400;

All inquiries staff numbers 41, 42 sectors?
ID SELECT, last_name, the dept_id
from s_emp
WHERE = 41 is the dept_id or = 42 is the dept_id;

Queries paid more than 1,400 yuan, and work in 41 or 42 department
employee information?
ID SELECT, last_name, the salary
from s_emp
WHERE the salary> 1400
and (41 is the dept_id = or = 42 is the dept_id);

Priority issues:
and a higher priority than or.

4) Comparison of logical operators
to simplify conditions for parallel
BETWEEN given value from the minimum and maximum range
syntax: where field BETWEEN smaller value and a larger value;
WHERE the salary BETWEEN 1000 and 1500;
equivalent to:
WHERE the salary> = 1000 and salary <= 1500;
Note: must take a small value written before and,
to a larger value after the write and.

in from a given fixed value takes a few
syntax: where field in (value 1, value 2 and value 3 .....);

For example:
query basic information numbers 1,3,5,7,9 employees?
ID SELECT, last_name
from s_emp
WHERE ID or ID. 1 = = =. 5. 3 or ID
or ID or ID = =. 7. 9;

SELECT ID, last_name
from s_emp
WHERE ID in (1,3,5,7,9);

query wages employee information beyond the scope of 1000-1500?
the above mentioned id the SELECT, last_name
from s_emp
the WHERE salary not the BETWEEN 1000 and 1500;

Query employee information other than No. 41, 42 department?
... SELECT
from ...
! = 41 is the dept_id WHERE and 42 is the dept_id =!;

select ..
from ...
where dept_id not in(41,42);

3. Fuzzy query / keyword query
syntax: where fields like fuzzy value;

wildcards:
1)% percent sign represents any number of any characters
can not be a can have more than
2) _ underscore represents an arbitrary character. - placeholder
must have one and only one character.

For example: query contains all last_name 'n' employee information?
ID SELECT, last_name
from s_emp
WHERE last_name like '% n-%';

Escape character:
first insert a piece of data:
INSERT INTO s_emp (the above mentioned id, last_name)
values (999, '_ briup');
the commit;

for example:
query all the names with '_' employee information beginning?
ID SELECT, last_name
from s_emp
WHERE last_name like '/ _%' Escape '/';

Step escaped:
1) at the front to add an escape character identification.
Logo can be any character.
like 'A_%';
2) the use of escape characters is declared which identifies character
like 'a_%' escape 'a ';

 

 

Guess you like

Origin www.cnblogs.com/DennySmith/p/12153549.html