SQL not between usage

Source: Internet
Author: User

Whether the result value of the expression is within the specified range. Entity SQL between expressions have the same functions as transact-SQL between expressions.

Expression
You need to test whether any valid expression is within the range defined by begin_expression and end_expression. Expression must be of the same type as begin_expression and end_expression.

Begin_expression
Any valid expression. Begin_expression must be of the same type as expression and end_expression. Begin_expression should be smaller than end_expression; otherwise, the return value will be reversed.

End_expression
Any valid expression. End_expression must be of the same type as expression and begin_expression.

Not
Returns the result of.

And
Used as a placeholder to indicate that expression should be within the range specified by begin_expression and end_expression.

 

SQL> -- create demo table
SQL> create table employee (
2 id varchar2 (4 byte) not null,
3 first_name varchar2 (10 byte ),
4 last_name varchar2 (10 byte ),
5 start_date date,
6 end_date date,
7 salary number (8, 2 ),
8 city varchar2 (10 byte ),
9 description varchar2 (15 bytes)
10)
11/

Table created.

SQL>
SQL> -- prepare data
SQL> insert into employee (id, first_name, last_name, start_date, end_date, salary, city, description)
2 values ('01 ', 'jason', 'martin ', to_date ('20170101', 'yyyymmdd'), to_date ('20170101', 'yyyymmdd'), 19960725, 'toronto ', 'programmer ')
3/

1 row created.

SQL> insert into employee (id, first_name, last_name, start_date, end_date, salary, city, description)
2 values ('02 ', 'alison', 'mathews ', to_date ('20170101', 'yyyymmdd'), to_date ('20170101', 'yyyymmdd'), 19760321, 'vancouver ', 'tester ')
3/

1 row created.

SQL> insert into employee (id, first_name, last_name, start_date, end_date, salary, city, description)
2 values ('03', 'James ', 'Smith', to_date ('20170101', 'yyyymmdd'), to_date ('20170101', 'yyyymmdd'), 19781212, 'vancouver ', 'tester ')
3/

1 row created.

SQL> insert into employee (id, first_name, last_name, start_date, end_date, salary, city, description)
2 values ('04 ', 'cela', 'Rice', to_date ('20170101', 'yyyymmdd'), to_date ('20170101', 'yyyymmdd'), 19821024, 'vancouver ', 'manager ')
3/

1 row created.

SQL> insert into employee (id, first_name, last_name, start_date, end_date, salary, city, description)
2 values ('05 ', 'Robert', 'black', to_date ('000000', 'yyyymmdd'), to_date ('20140901', 'yyyymmdd'), 19840115, 'vancouver ', 'tester ')
3/

1 row created.

SQL> insert into employee (id, first_name, last_name, start_date, end_date, salary, city, description)
2 values ('06', 'linda ', 'green', to_date ('20170101', 'yyyymmdd'), to_date ('20170101', 'yyyymmdd'), 19870730, 'New york ', 'tester ')
3/

1 row created.

SQL> insert into employee (id, first_name, last_name, start_date, end_date, salary, city, description)
2 values ('07 ', 'David', 'Larry', to_date ('123', 'yyyymmdd'), to_date ('123456', 'yyyymmdd'), 19901231, 'New york ', 'manager ')
3/

1 row created.

SQL> insert into employee (id, first_name, last_name, start_date, end_date, salary, city, description)
2 values ('08', 'James ', 'cat', to_date ('20170101', 'yyyymmdd'), to_date ('20170101', 'yyyymmdd'), 19960917, 'vancouver ', 'tester ')
3/

1 row created.

SQL>
SQL>
SQL>
SQL> -- display data in the table
SQL> select * from employee
2/

Id first_name last_name start_dat end_date salary city description
-----------------------------------------------------------------------------
01 jason martin 25-jul-96 25-jul-06 1234.56 toronto programmer
02 alison mathews 21-mar-76 21-feb-86 6661.78 vancouver tester
03 james smith 12-dec-78 15-mar-90 6544.78 vancouver tester
04 celia rice 24-oct-82 21-apr-99 2344.78 vancouver manager
05 robert black 15-jan-84 08-aug-98 2334.78 vancouver tester
06 linda green 30-jul-87 04-jan-96 4322.78 new york tester
07 david larry 31-dec-90 12-feb-98 7897.78 new york manager
08 james cat 17-sep-96 15-apr-01232.78 vancouver tester

8 rows selected.

SQL>
SQL>
SQL> select * from employee where id not between 1 and 3;

Id first_name last_name start_dat end_date salary city description
-----------------------------------------------------------------------------
04 celia rice 24-oct-82 21-apr-99 2344.78 vancouver manager
05 robert black 15-jan-84 08-aug-98 2334.78 vancouver tester
06 linda green 30-jul-87 04-jan-96 4322.78 new york tester
07 david larry 31-dec-90 12-feb-98 7897.78 new york manager
08 james cat 17-sep-96 15-apr-01232.78 vancouver tester

SQL>
SQL>
SQL>
SQL> -- clean the table
SQL> drop table employee

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.