oracle的基本查询~下

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了oracle的基本查询~下相关的知识,希望对你有一定的参考价值。

SQL> --别名
SQL> select ename 姓名, job as "工作" ,sal "薪水" from emp;

姓名                 工作                     薪水                                                                     
-------------------- ------------------ ----------                                                                     
SMITH                CLERK                     800                                                                     
ALLEN                SALESMAN                 1600                                                                     
WARD                 SALESMAN                 1250                                                                     
JONES                MANAGER                  2975                                                                     
MARTIN               SALESMAN                 1250                                                                     
BLAKE                MANAGER                  2850                                                                     
CLARK                MANAGER                  2450                                                                     
SCOTT                ANALYST                  3000                                                                     
KING                 PRESIDENT                5000                                                                     
TURNER               SALESMAN                 1500                                                                     
ADAMS                CLERK                    1100                                                                     

姓名                 工作                     薪水                                                                     
-------------------- ------------------ ----------                                                                     
JAMES                CLERK                     950                                                                     
FORD                 ANALYST                  3000                                                                     
MILLER               CLERK                    1300                                                                     

已选择14行。

SQL> --这三种别名有什么不同呢?
SQL> ed
SP2-0110: 无法创建保存文件 "afiedt.buf"
SQL> select ename 姓名, ename "姓名" from dual;
select ename 姓名, ename "姓名" from dual
                     *
第 1 行出现错误:
ORA-00904: "ENAME": 标识符无效


SQL> ed
SP2-0110: 无法创建保存文件 "afiedt.buf"
SQL> ed
SP2-0110: 无法创建保存文件 "afiedt.buf"
SQL> select * from emp;

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

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

已选择14行。

SQL> ed
SP2-0110: 无法创建保存文件 "afiedt.buf"
SQL> select ename 姓名, ename "姓名" from emp;

姓名                 姓名                                                                                              
-------------------- --------------------                                                                              
SMITH                SMITH                                                                                             
ALLEN                ALLEN                                                                                             
WARD                 WARD                                                                                              
JONES                JONES                                                                                             
MARTIN               MARTIN                                                                                            
BLAKE                BLAKE                                                                                             
CLARK                CLARK                                                                                             
SCOTT                SCOTT                                                                                             
KING                 KING                                                                                              
TURNER               TURNER                                                                                            
ADAMS                ADAMS                                                                                             

姓名                 姓名                                                                                              
-------------------- --------------------                                                                              
JAMES                JAMES                                                                                             
FORD                 FORD                                                                                              
MILLER               MILLER                                                                                            

已选择14行。

SQL> select ename 姓select/名, ename "姓名" from emp;
select ename 姓select/名, ename "姓名" from emp
                      *
第 1 行出现错误:
ORA-00923: 未找到要求的 FROM 关键字


SQL> select ename 姓名, ename "姓select/名" from emp;

姓名                 姓select/名                                                                                       
-------------------- --------------------                                                                              
SMITH                SMITH                                                                                             
ALLEN                ALLEN                                                                                             
WARD                 WARD                                                                                              
JONES                JONES                                                                                             
MARTIN               MARTIN                                                                                            
BLAKE                BLAKE                                                                                             
CLARK                CLARK                                                                                             
SCOTT                SCOTT                                                                                             
KING                 KING                                                                                              
TURNER               TURNER                                                                                            
ADAMS                ADAMS                                                                                             

姓名                 姓select/名                                                                                       
-------------------- --------------------                                                                              
JAMES                JAMES                                                                                             
FORD                 FORD                                                                                              
MILLER               MILLER                                                                                            

已选择14行。

SQL> select * from emp;

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

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

已选择14行。

SQL> select job from emp;

JOB                                                                                                                    
------------------                                                                                                     
CLERK                                                                                                                  
SALESMAN                                                                                                               
SALESMAN                                                                                                               
MANAGER                                                                                                                
SALESMAN                                                                                                               
MANAGER                                                                                                                
MANAGER                                                                                                                
ANALYST                                                                                                                
PRESIDENT                                                                                                              
SALESMAN                                                                                                               
CLERK                                                                                                                  

JOB                                                                                                                    
------------------                                                                                                     
CLERK                                                                                                                  
ANALYST                                                                                                                
CLERK                                                                                                                  

已选择14行。

SQL> select distinct job from emp;

JOB                        

以上是关于oracle的基本查询~下的主要内容,如果未能解决你的问题,请参考以下文章

oracle基本查询内容整理

oracle——单表查询

oracle的基本查询

oracle笔记1:-安装-体系结构-基本查询

oracle分组查询

oracle分组查询