过滤和排序·上

SQL> --查询10号部门的所有员工信息
SQL> select *
  2  from emp
  3  where empno = 10;

未选定行

SQL> ed
SP2-0110: 无法创建保存文件 "afiedt.buf"
SQL> 3
  3* where empno = 10
SQL> c /empno/deptno;
  3* where deptno = 10
SQL> /

EMPNO ENAME                JOB                       MGR HIREDATE         
---------- -------------------- ------------------ ---------- --------------   
       SAL       COMM     DEPTNO                                               
---------- ---------- ----------                                               
      7782 CLARK                MANAGER                  7839 09-6月 -81       
      2450                    10                                               
                                                                               
      7839 KING                 PRESIDENT                     17-11月-81       
      5000                    10                                               
                                                                               
      7934 MILLER               CLERK                    7782 23-1月 -82       
      1300                    10

SQL> set linesize 120l
SP2-0268: linesize 选项的编号无效
SQL> set linesize 120;
SQL> /

EMPNO ENAME                JOB                       MGR HIREDATE              SAL       COMM     DEPTNO          
---------- -------------------- ------------------ ---------- -------------- ---------- ---------- ----------          
      7782 CLARK                MANAGER                  7839 09-6月 -81           2450                    10          
      7839 KING                 PRESIDENT                     17-11月-81           5000                    10          
      7934 MILLER               CLERK                    7782 23-1月 -82           1300                    10

SQL> -- 查询名字为KING的员工信息
SQL> select *
  2  from emp
  3  where ename = ‘KING‘;

EMPNO ENAME                JOB                       MGR HIREDATE              SAL       COMM     DEPTNO          
---------- -------------------- ------------------ ---------- -------------- ---------- ---------- ----------          
      7839 KING                 PRESIDENT                     17-11月-81           5000                    10

SQL> 3
  3* where ename = ‘KING‘
SQL> c /KING/King;
  3* where ename = ‘King‘
SQL> /

未选定行

SQL> --在oracle中字段的名称是不区分大小写的,但是字段里面的值是区分大小的
SQL> --查询入职日期是81-11-17号的员工信息
SQL> select *
  2  from emp
  3  where hiredate = ‘17-11月-81‘;

EMPNO ENAME                JOB                       MGR HIREDATE              SAL       COMM     DEPTNO          
---------- -------------------- ------------------ ---------- -------------- ---------- ---------- ----------          
      7839 KING                 PRESIDENT                     17-11月-81           5000                    10

SQL> -- 在oracle中时间的表示格式是 DD-MON-RR
SQL> select * from
  2  emp
  3  where hiredate = ‘1981-11-17‘;
where hiredate = ‘1981-11-17‘
                 *
第 3 行出现错误:
ORA-01861: 文字与格式字符串不匹配

SQL> --查询oracle中的一般常亮设置
SQL> select * from v$nls_paramters;
select * from v$nls_paramters
              *
第 1 行出现错误:
ORA-00942: 表或视图不存在

SQL> select * from v$nls_parameters;

PARAMETER                                                                                                              
------------------------------------------------------------------------------------------------------------------------
VALUE                                                                                                                  
------------------------------------------------------------------------------------------------------------------------
NLS_LANGUAGE                                                                                                           
SIMPLIFIED CHINESE                                                                                                     
                                                                                                                       
NLS_TERRITORY                                                                                                          
CHINA                                                                                                                  
                                                                                                                       
NLS_CURRENCY                                                                                                           

PARAMETER                                                                                                              
------------------------------------------------------------------------------------------------------------------------
VALUE                                                                                                                  
------------------------------------------------------------------------------------------------------------------------
NLS_ISO_CURRENCY                                                                                                       
CHINA                                                                                                                  
                                                                                                                       
NLS_NUMERIC_CHARACTERS                                                                                                 
.,                                                                                                                     
                                                                                                                       
NLS_CALENDAR                                                                                                           
GREGORIAN

PARAMETER                                                                                                              
------------------------------------------------------------------------------------------------------------------------
VALUE                                                                                                                  
------------------------------------------------------------------------------------------------------------------------
NLS_DATE_FORMAT                                                                                                        
DD-MON-RR                                                                                                              
                                                                                                                       
NLS_DATE_LANGUAGE                                                                                                      
SIMPLIFIED CHINESE                                                                                                     
                                                                                                                       
NLS_CHARACTERSET                                                                                                       
AL32UTF8

PARAMETER                                                                                                              
------------------------------------------------------------------------------------------------------------------------
VALUE                                                                                                                  
------------------------------------------------------------------------------------------------------------------------
NLS_SORT                                                                                                               
BINARY                                                                                                                 
                                                                                                                       
NLS_TIME_FORMAT                                                                                                        
HH.MI.SSXFF AM                                                                                                         
                                                                                                                       
NLS_TIMESTAMP_FORMAT                                                                                                   
DD-MON-RR HH.MI.SSXFF AM

PARAMETER                                                                                                              
------------------------------------------------------------------------------------------------------------------------
VALUE                                                                                                                  
------------------------------------------------------------------------------------------------------------------------
NLS_TIME_TZ_FORMAT                                                                                                     
HH.MI.SSXFF AM TZR                                                                                                     
                                                                                                                       
NLS_TIMESTAMP_TZ_FORMAT                                                                                                
DD-MON-RR HH.MI.SSXFF AM TZR                                                                                           
                                                                                                                       
NLS_DUAL_CURRENCY                                                                                                      

PARAMETER                                                                                                              
------------------------------------------------------------------------------------------------------------------------
VALUE                                                                                                                  
------------------------------------------------------------------------------------------------------------------------
NLS_NCHAR_CHARACTERSET                                                                                                 
AL16UTF16                                                                                                              
                                                                                                                       
NLS_COMP                                                                                                               
BINARY                                                                                                                 
                                                                                                                       
NLS_LENGTH_SEMANTICS                                                                                                   
BYTE

PARAMETER                                                                                                              
------------------------------------------------------------------------------------------------------------------------
VALUE                                                                                                                  
------------------------------------------------------------------------------------------------------------------------
NLS_NCHAR_CONV_EXCP                                                                                                    
FALSE

已选择19行。

SQL> set linesize 200;
SQL> /

PARAMETER                                                                                                                                                                                              
--------------------------------------------------------------------------------------------------------------------------------                                                                       
VALUE                                                                                                                                                                                                  
--------------------------------------------------------------------------------------------------------------------------------                                                                       
NLS_LANGUAGE                                                                                                                                                                                           
SIMPLIFIED CHINESE                                                                                                                                                                                     
                                                                                                                                                                                                       
NLS_TERRITORY                                                                                                                                                                                          
CHINA                                                                                                                                                                                                  
                                                                                                                                                                                                       
NLS_CURRENCY                                                                                                                                                                                           

PARAMETER                                                                                                                                                                                              
--------------------------------------------------------------------------------------------------------------------------------                                                                       
VALUE                                                                                                                                                                                                  
--------------------------------------------------------------------------------------------------------------------------------                                                                       
NLS_ISO_CURRENCY                                                                                                                                                                                       
CHINA                                                                                                                                                                                                  
                                                                                                                                                                                                       
NLS_NUMERIC_CHARACTERS                                                                                                                                                                                 
.,                                                                                                                                                                                                     
                                                                                                                                                                                                       
NLS_CALENDAR                                                                                                                                                                                           
GREGORIAN

PARAMETER                                                                                                                                                                                              
--------------------------------------------------------------------------------------------------------------------------------                                                                       
VALUE                                                                                                                                                                                                  
--------------------------------------------------------------------------------------------------------------------------------                                                                       
NLS_DATE_FORMAT                                                                                                                                                                                        
DD-MON-RR                                                                                                                                                                                              
                                                                                                                                                                                                       
NLS_DATE_LANGUAGE                                                                                                                                                                                      
SIMPLIFIED CHINESE                                                                                                                                                                                     
                                                                                                                                                                                                       
NLS_CHARACTERSET                                                                                                                                                                                       
AL32UTF8

PARAMETER                                                                                                                                                                                              
--------------------------------------------------------------------------------------------------------------------------------                                                                       
VALUE                                                                                                                                                                                                  
--------------------------------------------------------------------------------------------------------------------------------                                                                       
NLS_SORT                                                                                                                                                                                               
BINARY                                                                                                                                                                                                 
                                                                                                                                                                                                       
NLS_TIME_FORMAT                                                                                                                                                                                        
HH.MI.SSXFF AM                                                                                                                                                                                         
                                                                                                                                                                                                       
NLS_TIMESTAMP_FORMAT                                                                                                                                                                                   
DD-MON-RR HH.MI.SSXFF AM

PARAMETER                                                                                                                                                                                              
--------------------------------------------------------------------------------------------------------------------------------                                                                       
VALUE                                                                                                                                                                                                  
--------------------------------------------------------------------------------------------------------------------------------                                                                       
NLS_TIME_TZ_FORMAT                                                                                                                                                                                     
HH.MI.SSXFF AM TZR                                                                                                                                                                                     
                                                                                                                                                                                                       
NLS_TIMESTAMP_TZ_FORMAT                                                                                                                                                                                
DD-MON-RR HH.MI.SSXFF AM TZR                                                                                                                                                                           
                                                                                                                                                                                                       
NLS_DUAL_CURRENCY                                                                                                                                                                                      

PARAMETER                                                                                                                                                                                              
--------------------------------------------------------------------------------------------------------------------------------                                                                       
VALUE                                                                                                                                                                                                  
--------------------------------------------------------------------------------------------------------------------------------                                                                       
NLS_NCHAR_CHARACTERSET                                                                                                                                                                                 
AL16UTF16                                                                                                                                                                                              
                                                                                                                                                                                                       
NLS_COMP                                                                                                                                                                                               
BINARY                                                                                                                                                                                                 
                                                                                                                                                                                                       
NLS_LENGTH_SEMANTICS                                                                                                                                                                                   
BYTE

PARAMETER                                                                                                                                                                                              
--------------------------------------------------------------------------------------------------------------------------------                                                                       
VALUE                                                                                                                                                                                                  
--------------------------------------------------------------------------------------------------------------------------------                                                                       
NLS_NCHAR_CONV_EXCP                                                                                                                                                                                    
FALSE

已选择19行。

SQL> col parameter for a50;
SQL> /

PARAMETER                                          VALUE                                                                                                                                               
-------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------                    
NLS_LANGUAGE                                       SIMPLIFIED CHINESE                                                                                                                                  
NLS_TERRITORY                                      CHINA                                                                                                                                               
NLS_CURRENCY                                       ¥                                                                                                                                                  
NLS_ISO_CURRENCY                                   CHINA                                                                                                                                               
NLS_NUMERIC_CHARACTERS                             .,                                                                                                                                                  
NLS_CALENDAR                                       GREGORIAN                                                                                                                                           
NLS_DATE_FORMAT                                    DD-MON-RR                                                                                                                                           
NLS_DATE_LANGUAGE                                  SIMPLIFIED CHINESE                                                                                                                                  
NLS_CHARACTERSET                                   AL32UTF8                                                                                                                                            
NLS_SORT                                           BINARY                                                                                                                                              
NLS_TIME_FORMAT                                    HH.MI.SSXFF AM

PARAMETER                                          VALUE                                                                                                                                               
-------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------                    
NLS_TIMESTAMP_FORMAT                               DD-MON-RR HH.MI.SSXFF AM                                                                                                                            
NLS_TIME_TZ_FORMAT                                 HH.MI.SSXFF AM TZR                                                                                                                                  
NLS_TIMESTAMP_TZ_FORMAT                            DD-MON-RR HH.MI.SSXFF AM TZR                                                                                                                        
NLS_DUAL_CURRENCY                                  ¥                                                                                                                                                  
NLS_NCHAR_CHARACTERSET                             AL16UTF16                                                                                                                                           
NLS_COMP                                           BINARY                                                                                                                                              
NLS_LENGTH_SEMANTICS                               BYTE                                                                                                                                                
NLS_NCHAR_CONV_EXCP                                FALSE

已选择19行。

SQL> alter session set NLS_DATE_FORMAT = ‘yyyy-mm-dd‘;

会话已更改。

SQL> select *enaee
  2  from emp
  3  where hiredate=‘1981-11-17‘;

EMPNO ENAME                JOB                       MGR HIREDATE          SAL       COMM     DEPTNO                                                                                              
---------- -------------------- ------------------ ---------- ---------- ---------- ---------- ----------                                                                                              
      7839 KING                 PRESIDENT                     1981-11-17       5000                    10

SQL> select *
  2  from emp
  3  where hiredate=‘17-11月-81‘;
where hiredate=‘17-11月-81‘
               *
第 3 行出现错误:
ORA-01861: 文字与格式字符串不匹配

SQL> select * from v$nls_parameters;

PARAMETER                                          VALUE                                                                                                                                               
-------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------                    
NLS_LANGUAGE                                       SIMPLIFIED CHINESE                                                                                                                                  
NLS_TERRITORY                                      CHINA                                                                                                                                               
NLS_CURRENCY                                       ¥                                                                                                                                                  
NLS_ISO_CURRENCY                                   CHINA                                                                                                                                               
NLS_NUMERIC_CHARACTERS                             .,                                                                                                                                                  
NLS_CALENDAR                                       GREGORIAN                                                                                                                                           
NLS_DATE_FORMAT                                    yyyy-mm-dd                                                                                                                                          
NLS_DATE_LANGUAGE                                  SIMPLIFIED CHINESE                                                                                                                                  
NLS_CHARACTERSET                                   AL32UTF8                                                                                                                                            
NLS_SORT                                           BINARY                                                                                                                                              
NLS_TIME_FORMAT                                    HH.MI.SSXFF AM

PARAMETER                                          VALUE                                                                                                                                               
-------------------------------------------------- --------------------------------------------------------------------------------------------------------------------------------                    
NLS_TIMESTAMP_FORMAT                               DD-MON-RR HH.MI.SSXFF AM                                                                                                                            
NLS_TIME_TZ_FORMAT                                 HH.MI.SSXFF AM TZR                                                                                                                                  
NLS_TIMESTAMP_TZ_FORMAT                            DD-MON-RR HH.MI.SSXFF AM TZR                                                                                                                        
NLS_DUAL_CURRENCY                                  ¥                                                                                                                                                  
NLS_NCHAR_CHARACTERSET                             AL16UTF16                                                                                                                                           
NLS_COMP                                           BINARY                                                                                                                                              
NLS_LENGTH_SEMANTICS                               BYTE                                                                                                                                                
NLS_NCHAR_CONV_EXCP                                FALSE

已选择19行。

SQL> select *
  2  from emp
  3  where ename=‘KING‘ and job=‘PRESIDENT‘;

EMPNO ENAME                JOB                       MGR HIREDATE          SAL       COMM     DEPTNO                                                                                              
---------- -------------------- ------------------ ---------- ---------- ---------- ---------- ----------                                                                                              
      7839 KING                 PRESIDENT                     1981-11-17       5000                    10

SQL> --查询工资在2000-5000之间的所有员工
SQL> select *
  2  from emp
  3  where sal>2000 and sal < 5000;

EMPNO ENAME                JOB                       MGR HIREDATE          SAL       COMM     DEPTNO                                                                                              
---------- -------------------- ------------------ ---------- ---------- ---------- ---------- ----------                                                                                              
      7566 JONES                MANAGER                  7839 1981-04-02       2975                    20                                                                                              
      7698 BLAKE                MANAGER                  7839 1981-05-01       2850                    30                                                                                              
      7782 CLARK                MANAGER                  7839 1981-06-09       2450                    10                                                                                              
      7788 SCOTT                ANALYST                  7566 1987-04-19       3000                    20                                                                                              
      7902 FORD                 ANALYST                  7566 1981-12-03       3000                    20

SQL> select *
  2  from emp
  3  where sal between 2000 and 5000;

EMPNO ENAME                JOB                       MGR HIREDATE          SAL       COMM     DEPTNO                                                                                              
---------- -------------------- ------------------ ---------- ---------- ---------- ---------- ----------                                                                                              
      7566 JONES                MANAGER                  7839 1981-04-02       2975                    20                                                                                              
      7698 BLAKE                MANAGER                  7839 1981-05-01       2850                    30                                                                                              
      7782 CLARK                MANAGER                  7839 1981-06-09       2450                    10                                                                                              
      7788 SCOTT                ANALYST                  7566 1987-04-19       3000                    20                                                                                              
      7839 KING                 PRESIDENT                     1981-11-17       5000                    10                                                                                              
      7902 FORD                 ANALYST                  7566 1981-12-03       3000                    20

已选择6行。

SQL> select *
  2  from emp
  3  where sal between 5000 and 2000;

未选定行

SQL> --between ...and 只能将小的写在前面大的写在后面
SQL> -- in/not in
SQL> --查询20?30号部门的所有员工
SQL> select *
  2  from emp
  3  where deptno = 20 or deptno = 30;

EMPNO ENAME                JOB                       MGR HIREDATE          SAL       COMM     DEPTNO                                                                                              
---------- -------------------- ------------------ ---------- ---------- ---------- ---------- ----------                                                                                              
      7369 SMITH                CLERK                    7902 1980-12-17        800                    20                                                                                              
      7499 ALLEN                SALESMAN                 7698 1981-02-20       1600        300         30                                                                                              
      7521 WARD                 SALESMAN                 7698 1981-02-22       1250        500         30                                                                                              
      7566 JONES                MANAGER                  7839 1981-04-02       2975                    20                                                                                              
      7654 MARTIN               SALESMAN                 7698 1981-09-28       1250       1400         30                                                                                              
      7698 BLAKE                MANAGER                  7839 1981-05-01       2850                    30                                                                                              
      7788 SCOTT                ANALYST                  7566 1987-04-19       3000                    20                                                                                              
      7844 TURNER               SALESMAN                 7698 1981-09-08       1500          0         30                                                                                              
      7876 ADAMS                CLERK                    7788 1987-05-23       1100                    20                                                                                              
      7900 JAMES                CLERK                    7698 1981-12-03        950                    30                                                                                              
      7902 FORD                 ANALYST                  7566 1981-12-03       3000                    20

已选择11行。

SQL> select *
  2  from emp
  3  where deptno in(20,30);

EMPNO ENAME                JOB                       MGR HIREDATE          SAL       COMM     DEPTNO                                                                                              
---------- -------------------- ------------------ ---------- ---------- ---------- ---------- ----------                                                                                              
      7369 SMITH                CLERK                    7902 1980-12-17        800                    20                                                                                              
      7499 ALLEN                SALESMAN                 7698 1981-02-20       1600        300         30                                                                                              
      7521 WARD                 SALESMAN                 7698 1981-02-22       1250        500         30                                                                                              
      7566 JONES                MANAGER                  7839 1981-04-02       2975                    20                                                                                              
      7654 MARTIN               SALESMAN                 7698 1981-09-28       1250       1400         30                                                                                              
      7698 BLAKE                MANAGER                  7839 1981-05-01       2850                    30                                                                                              
      7788 SCOTT                ANALYST                  7566 1987-04-19       3000                    20                                                                                              
      7844 TURNER               SALESMAN                 7698 1981-09-08       1500          0         30                                                                                              
      7876 ADAMS                CLERK                    7788 1987-05-23       1100                    20                                                                                              
      7900 JAMES                CLERK                    7698 1981-12-03        950                    30                                                                                              
      7902 FORD                 ANALYST                  7566 1981-12-03       3000                    20

已选择11行。

SQL> -- 查询不在20和30号部门里面的所有员工
SQL> select *
  2  from emp
  3  where deptno != 20 and deptno != 30;

EMPNO ENAME                JOB                       MGR HIREDATE          SAL       COMM     DEPTNO                                                                                              
---------- -------------------- ------------------ ---------- ---------- ---------- ---------- ----------                                                                                              
      7782 CLARK                MANAGER                  7839 1981-06-09       2450                    10                                                                                              
      7839 KING                 PRESIDENT                     1981-11-17       5000                    10                                                                                              
      7934 MILLER               CLERK                    7782 1982-01-23       1300                    10

SQL> select *
  2  from emp
  3  where deptno not in(20,30);

EMPNO ENAME                JOB                       MGR HIREDATE          SAL       COMM     DEPTNO                                                                                              
---------- -------------------- ------------------ ---------- ---------- ---------- ---------- ----------                                                                                              
      7782 CLARK                MANAGER                  7839 1981-06-09       2450                    10                                                                                              
      7839 KING                 PRESIDENT                     1981-11-17       5000                    10                                                                                              
      7934 MILLER               CLERK                    7782 1982-01-23       1300                    10

SQL> -- 查询奖金为300和为空的所有员工信息
SQL> select *
  2  from emp
  3  where comm in(300,null
     EMPNO ENAME                JOB                       MGR HIREDATE          SAL       COMM     DEPTNO                                                                                              
---------- -------------------- ------------------ ---------- ---------- ---------- ---------- ----------                                                                                              
      7499 ALLEN                SALESMAN                 7698 1981-02-20       1600        300         30

SQL> select *
  2  from emp
  3  where comm not in (300,null);

未选定行

SQL> -- in里面可以跟null,而not in 里面不能跟null
SQL> -- 查询comm为空的所有员工信息
SQL> select *
  2  from emp
  3  where comm is null;

EMPNO ENAME                JOB                       MGR HIREDATE          SAL       COMM     DEPTNO                                                                                              
---------- -------------------- ------------------ ---------- ---------- ---------- ---------- ----------                                                                                              
      7369 SMITH                CLERK                    7902 1980-12-17        800                    20                                                                                              
      7566 JONES                MANAGER                  7839 1981-04-02       2975                    20                                                                                              
      7698 BLAKE                MANAGER                  7839 1981-05-01       2850                    30                                                                                              
      7782 CLARK                MANAGER                  7839 1981-06-09       2450                    10                                                                                              
      7788 SCOTT                ANALYST                  7566 1987-04-19       3000                    20                                                                                              
      7839 KING                 PRESIDENT                     1981-11-17       5000                    10                                                                                              
      7876 ADAMS                CLERK                    7788 1987-05-23       1100                    20                                                                                              
      7900 JAMES                CLERK                    7698 1981-12-03        950                    30                                                                                              
      7902 FORD                 ANALYST                  7566 1981-12-03       3000                    20                                                                                              
      7934 MILLER               CLERK                    7782 1982-01-23       1300                    10

已选择10行。

SQL> -- 模糊查询
SQL> -- 查询员工名字里面包含了O的所有员工信息
SQL> select *
  2  from emp
  3  where ename like ‘%O%‘;

EMPNO ENAME                JOB                       MGR HIREDATE          SAL       COMM     DEPTNO                                                                                              
---------- -------------------- ------------------ ---------- ---------- ---------- ---------- ----------                                                                                              
      7566 JONES                MANAGER                  7839 1981-04-02       2975                    20                                                                                              
      7788 SCOTT                ANALYST                  7566 1987-04-19       3000                    20                                                                                              
      7902 FORD                 ANALYST                  7566 1981-12-03       3000                    20

SQL> -- like 是一个关键字 表示模糊查询,其中的% 代表通配
SQL> -- 查询员工名字里面以K打头的员工信息
SQL> select *
  2  from emp
  3  where ename like ‘K%‘;

EMPNO ENAME                JOB                       MGR HIREDATE          SAL       COMM     DEPTNO                                                                                              
---------- -------------------- ------------------ ---------- ---------- ---------- ---------- ----------                                                                                              
      7839 KING                 PRESIDENT                     1981-11-17       5000                    10

SQL> -- 查询ename的长度为4的所有员工信息
SQL> select *
  2  from emp
  3  where ename like ‘____‘;

EMPNO ENAME                JOB                       MGR HIREDATE          SAL       COMM     DEPTNO                                                                                              
---------- -------------------- ------------------ ---------- ---------- ---------- ---------- ----------                                                                                              
      7521 WARD                 SALESMAN                 7698 1981-02-22       1250        500         30                                                                                              
      7839 KING                 PRESIDENT                     1981-11-17       5000                    10                                                                                              
      7902 FORD                 ANALYST                  7566 1981-12-03       3000                    20

SQL> -- 在oracle中_ 代表一个字符
SQL> insert into emp(empno,ename,sal,deptno) values(1001,‘TOM_ab‘,50000,20);

已创建 1 行。

SQL> select * from emp;

EMPNO ENAME                JOB                       MGR HIREDATE          SAL       COMM     DEPTNO                                                                                              
---------- -------------------- ------------------ ---------- ---------- ---------- ---------- ----------                                                                                              
      7369 SMITH                CLERK                    7902 1980-12-17        800                    20                                                                                              
      7499 ALLEN                SALESMAN                 7698 1981-02-20       1600        300         30                                                                                              
      7521 WARD                 SALESMAN                 7698 1981-02-22       1250        500         30                                                                                              
      7566 JONES                MANAGER                  7839 1981-04-02       2975                    20                                                                                              
      7654 MARTIN               SALESMAN                 7698 1981-09-28       1250       1400         30                                                                                              
      7698 BLAKE                MANAGER                  7839 1981-05-01       2850                    30                                                                                              
      7782 CLARK                MANAGER                  7839 1981-06-09       2450                    10                                                                                              
      7788 SCOTT                ANALYST                  7566 1987-04-19       3000                    20                                                                                              
      7839 KING                 PRESIDENT                     1981-11-17       5000                    10                                                                                              
      7844 TURNER               SALESMAN                 7698 1981-09-08       1500          0         30                                                                                              
      7876 ADAMS                CLERK                    7788 1987-05-23       1100                    20

EMPNO ENAME                JOB                       MGR HIREDATE          SAL       COMM     DEPTNO                                                                                              
---------- -------------------- ------------------ ---------- ---------- ---------- ---------- ----------                                                                                              
      7900 JAMES                CLERK                    7698 1981-12-03        950                    30                                                                                              
      7902 FORD                 ANALYST                  7566 1981-12-03       3000                    20                                                                                              
      7934 MILLER               CLERK                    7782 1982-01-23       1300                    10                                                                                              
      1001 TOM_ab                                                             50000                    20

已选择15行。

SQL> -- 查询ename字段里面包含了_的员工信息
SQL> select *
  2  from emp
  3  where ename like ‘%_%‘;

EMPNO ENAME                JOB                       MGR HIREDATE          SAL       COMM     DEPTNO                                                                                              
---------- -------------------- ------------------ ---------- ---------- ---------- ---------- ----------                                                                                              
      7369 SMITH                CLERK                    7902 1980-12-17        800                    20                                                                                              
      7499 ALLEN                SALESMAN                 7698 1981-02-20       1600        300         30                                                                                              
      7521 WARD                 SALESMAN                 7698 1981-02-22       1250        500         30                                                                                              
      7566 JONES                MANAGER                  7839 1981-04-02       2975                    20                                                                                              
      7654 MARTIN               SALESMAN                 7698 1981-09-28       1250       1400         30                                                                                              
      7698 BLAKE                MANAGER                  7839 1981-05-01       2850                    30                                                                                              
      7782 CLARK                MANAGER                  7839 1981-06-09       2450                    10                                                                                              
      7788 SCOTT                ANALYST                  7566 1987-04-19       3000                    20                                                                                              
      7839 KING                 PRESIDENT                     1981-11-17       5000                    10                                                                                              
      7844 TURNER               SALESMAN                 7698 1981-09-08       1500          0         30                                                                                              
      7876 ADAMS                CLERK                    7788 1987-05-23       1100                    20

EMPNO ENAME                JOB                       MGR HIREDATE          SAL       COMM     DEPTNO                                                                                              
---------- -------------------- ------------------ ---------- ---------- ---------- ---------- ----------                                                                                              
      7900 JAMES                CLERK                    7698 1981-12-03        950                    30                                                                                              
      7902 FORD                 ANALYST                  7566 1981-12-03       3000                    20                                                                                              
      7934 MILLER               CLERK                    7782 1982-01-23       1300                    10                                                                                              
      1001 TOM_ab                                                             50000                    20

已选择15行。

SQL> -- oracle中的转义
SQL> select *
  2  from emp
  3  where ename like ‘%\_%‘ escape ‘\‘;

EMPNO ENAME                JOB                       MGR HIREDATE          SAL       COMM     DEPTNO                                                                                              
---------- -------------------- ------------------ ---------- ---------- ---------- ---------- ----------                                                                                              
      1001 TOM_ab                                                             50000                    20

SQL> select * from emp;

EMPNO ENAME                JOB                       MGR HIREDATE          SAL       COMM     DEPTNO                                                                                              
---------- -------------------- ------------------ ---------- ---------- ---------- ---------- ----------                                                                                              
      7369 SMITH                CLERK                    7902 1980-12-17        800                    20                                                                                              
      7499 ALLEN                SALESMAN                 7698 1981-02-20       1600        300         30                                                                                              
      7521 WARD                 SALESMAN                 7698 1981-02-22       1250        500         30                                                                                              
      7566 JONES                MANAGER                  7839 1981-04-02       2975                    20                                                                                              
      7654 MARTIN               SALESMAN                 7698 1981-09-28       1250       1400         30                                                                                              
      7698 BLAKE                MANAGER                  7839 1981-05-01       2850                    30                                                                                              
      7782 CLARK                MANAGER                  7839 1981-06-09       2450                    10                                                                                              
      7788 SCOTT                ANALYST                  7566 1987-04-19       3000                    20                                                                                              
      7839 KING                 PRESIDENT                     1981-11-17       5000                    10                                                                                              
      7844 TURNER               SALESMAN                 7698 1981-09-08       1500          0         30                                                                                              
      7876 ADAMS                CLERK                    7788 1987-05-23       1100                    20

EMPNO ENAME                JOB                       MGR HIREDATE          SAL       COMM     DEPTNO                                                                                              
---------- -------------------- ------------------ ---------- ---------- ---------- ---------- ----------                                                                                              
      7900 JAMES                CLERK                    7698 1981-12-03        950                    30                                                                                              
      7902 FORD                 ANALYST                  7566 1981-12-03       3000                    20                                                                                              
      7934 MILLER               CLERK                    7782 1982-01-23       1300                    10                                                                                              
      1001 TOM_ab                                                             50000                    20

已选择15行。

SQL> rollback;

回退已完成。

SQL> /

回退已完成。

SQL> select * from emp;

EMPNO ENAME                JOB                       MGR HIREDATE          SAL       COMM     DEPTNO                                                                                              
---------- -------------------- ------------------ ---------- ---------- ---------- ---------- ----------                                                                                              
      7369 SMITH                CLERK                    7902 1980-12-17        800                    20                                                                                              
      7499 ALLEN                SALESMAN                 7698 1981-02-20       1600        300         30                                                                                              
      7521 WARD                 SALESMAN                 7698 1981-02-22       1250        500         30                                                                                              
      7566 JONES                MANAGER                  7839 1981-04-02       2975                    20                                                                                              
      7654 MARTIN               SALESMAN                 7698 1981-09-28       1250       1400         30                                                                                              
      7698 BLAKE                MANAGER                  7839 1981-05-01       2850                    30                                                                                              
      7782 CLARK                MANAGER                  7839 1981-06-09       2450                    10                                                                                              
      7788 SCOTT                ANALYST                  7566 1987-04-19       3000                    20                                                                                              
      7839 KING                 PRESIDENT                     1981-11-17       5000                    10                                                                                              
      7844 TURNER               SALESMAN                 7698 1981-09-08       1500          0         30                                                                                              
      7876 ADAMS                CLERK                    7788 1987-05-23       1100                    20

EMPNO ENAME                JOB                       MGR HIREDATE          SAL       COMM     DEPTNO                                                                                              
---------- -------------------- ------------------ ---------- ---------- ---------- ---------- ----------                                                                                              
      7900 JAMES                CLERK                    7698 1981-12-03        950                    30                                                                                              
      7902 FORD                 ANALYST                  7566 1981-12-03       3000                    20                                                                                              
      7934 MILLER               CLERK                    7782 1982-01-23       1300                    10

已选择14行。

SQL> spool off;

时间: 2024-10-26 22:28:43

过滤和排序·上的相关文章

Oracle学习(2):过滤和排序

Oracle的过滤与排序 where过滤语法 SQL> --查询10号部门的员工 SQL> select * 2  from emp 3  where deptno=10; EMPNO ENAME    JOB              MGR HIREDATE         SAL       COMM     DEPTNO ---------- -------- --------- ---------- -------------- ----- ---------- ----------

在ASP.NET MVC5中实现具有服务器端过滤、排序和分页的GridView

背景 在前一篇文章<[初学者指南]在ASP.NET MVC 5中创建GridView>中,我们学习了如何在 ASP.NET MVC 中实现 GridView,类似于 ASP.NET web 表单的功能.通过前文,我们已经了解到使用 jQuery 插件的数据表可以很容易地实现具有搜索.排序和分页等重要功能的表格. 前文中需要注意的是,所有通过插件实现的特性都是客户端的,这意味着所有的数据都首先在页面载入,然后由插件来处理客户端搜索.分页和排序的数据.如果数据表不是特别大,这么做是可以的:但是,如

基于AngularJS的过滤与排序

前面了解了AngularJS的使用方法,这里就简单的写个小程序,实现查询过滤以及排序的功能. 本程序中可以了解到: 1 angularjs的过滤器 2 ng-repeat的使用方法 3 控制器的使用 4 数据的绑定 程序设计分析 首先,如果要是先查询过滤,就要使用到AngularJS中的 过滤器filter 了. 直接在表达式的后面使用管道命令符 | ,按照下面的写法就可以达到一个过滤的效果: {{ persons | filter:query }} 通过使用filter实现过滤操作,query

AngularJS 过滤与排序详解及实例代码

这篇文章主要介绍了AngularJS 过滤与排序,实现查询过滤以及排序的功能. 通过这篇文章可以了解到 1. angularjs的过滤器 2. ng-repeat的使用方法 3. 控制器的使用 4. 数据的绑定 首先,如果要是先查询过滤,就要使用到AngularJS中的 过滤器filter 了. 直接在表达式的后面使用管道命令符 | ,按照下面的写法就可以达到一个过滤的效果: {{ persons | filter:query }} 通过使用filter实现过滤操作,query是查询过滤时输入的

《Entity Framework 6 Recipes》中文翻译系列 (27) ------ 第五章 加载实体和导航属性之关联实体过滤、排序、执行聚合操作

翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 5-9  关联实体过滤和排序 问题 你有一实体的实例,你想加载应用了过滤和排序的相关实体. 解决方案 假设你有如图5-24所示的概念模型 图5-24 一个酒店预定系统的模型 假设我们有一个酒店(Hotel)实体,使用代码清单5-22,获取酒店的商务套房(executive suite),查看是否被预定,并按房价排序. 代码清单5-22.通过方法Entry()和Query()显式加载实体集合,

Oracle数据库--过滤和排序

过滤和排序 1. 在查询中过滤行 过滤:使用WHERE子句将不满足条件的行过滤掉 where子句紧跟From子句 1)查询10号部门的员工 SQL> select * 2 from emp 3 where deptno=10; 2)字符串大小写敏感      查询名叫KING的员工 SQL> select * 2 from emp 3* where ename='KING' SQL> / 3)日期格式敏感     查询入职日期是17-11月-81的员工 SQL> select *

〈三〉ElasticSearch的认识:搜索、过滤、排序

目录 上节回顾 本节前言 文档的搜索 URL参数条件搜索 请求体条件搜索 语法与示例: 补充: 小节总结: 文档的过滤filter 语法与举例: filter与bool constant_score cache 小节总结: 文档的聚合分析 准备数据 语法与举例: 其他语法: 补充: 小节总结: 文档的分页.排序 分页 排序 deep paging 补充: 小节总结: 发表日期:2019年9月20日 上节回顾 1.讲了如何对索引CRUD 2.重新解释了type,只是元数据的效果 3.讲了如何对文档

drf_jwt手动签发与校验-drf小组件:过滤-筛选-排序-分页

签发token 源码的入口:完成token签发的view类里面封装的方法. 源码中在请求token的时候只有post请求方法,主要分析一下源码中的post方法的实现. settings源码: 总结: 源码的入口 # 前提:给一个局部禁用了所有 认证与权限 的视图类发送用户信息得到token,其实就是登录接口 # 1)rest_framework_jwt.views.ObtainJSONWebToken 的 父类 JSONWebTokenAPIView 的 post 方法 # 接受有usernam

下载Lucene4.X实战类baidu搜索的大型文档海量搜索系统(分词、过滤、排序、索引)

Lucene是一个高性能.可伸缩的信息搜索(IR)库.目前最新版本是4.3.1. 它可以为你的应用程序添加索引和搜索能力.Lucene是用java实现的.成熟的开源项目,是著名的Apache Jakarta大家庭的一员,并且基于Apache软件许可 [ASF, License].同样,Lucene是当前非常流行的.免费的Java信息搜索(IR)库. Lucene4.X实战类baidu搜索的大型文档海量搜索系统(分词.过滤.排序.索引),刚刚入手,转一注册文件,视频的确不错,可以先下载看看:htt