Oracle基本查询

SQL> --清屏命令
SQL> host cls

SQL> --当前用户下的表
SQL> select * from tab;

TNAME                          TABTYPE  CLUSTERID                              

------------------------------ ------- ----------                              
DEPT                           TABLE                                           
EMP                            TABLE                                           
BONUS                          TABLE                                           
SALGRADE                       TABLE                                           

SQL> --tab:oracle提供的一个数据字典,包含了当前用户下的表和视图
SQL> --查询所有员工信息
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                                                                     
                                                                               

     EMPNO ENAME      JOB              MGR HIREDATE              SAL       COMM

---------- ---------- --------- ---------- -------------- ---------- ----------
    DEPTNO                                                                     
----------                                                                     
      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                                                                     
                                                                               

     EMPNO ENAME      JOB              MGR HIREDATE              SAL       COMM

---------- ---------- --------- ---------- -------------- ---------- ----------
    DEPTNO                                                                     
----------                                                                     
      7782 CLARK      MANAGER         7839 09-6月 -81           2450           
        10                                                                     
                                                                               
      7788 SCOTT      ANALYST         7566 13-7月 -87           3000           
        20                                                                     
                                                                               
      7839 KING       PRESIDENT            17-11月-81           5000           
        10                                                                     
                                                                               

     EMPNO ENAME      JOB              MGR HIREDATE              SAL       COMM

---------- ---------- --------- ---------- -------------- ---------- ----------
    DEPTNO                                                                     
----------                                                                     
      7844 TURNER     SALESMAN        7698 08-9月 -81           1500          0
        30                                                                     
                                                                               
      7876 ADAMS      CLERK           7788 13-7月 -87           1100           
        20                                                                     
                                                                               
      7900 JAMES      CLERK           7698 03-12月-81            950           
        30                                                                     
                                                                               

     EMPNO ENAME      JOB              MGR HIREDATE              SAL       COMM

---------- ---------- --------- ---------- -------------- ---------- ----------
    DEPTNO                                                                     
----------                                                                     
      7902 FORD       ANALYST         7566 03-12月-81           3000           
        20                                                                     
                                                                               
      7934 MILLER     CLERK           7782 23-1月 -82           1300           
        10                                                                     
                                                                               

已选择14行。

SQL> --设置行宽
SQL> set linesize 120
SQL> --设置列显示宽度,设置sal
SQL> col sal for 9999
SQL> col ename for a15
SQL> /

     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 13-7月 -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 13-7月 -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> /*
SQL> 9999:设置数字
SQL> aa15:表示设置字符串宽带15位
SQL> */
SQL> set pagesize 60
SQL> /

     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 13-7月 -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 13-7月 -87      1100                    20                             

      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> --设置feedback
SQL> set feedback off
SQL> /

     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 13-7月 -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 13-7月 -87      1100                    20                             

      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                             

SQL> set feedback on
SQL> /

     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 13-7月 -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 13-7月 -87      1100                    20                             

      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 empno,ename,job,mgr,hirdate,sal,comm,deptno from emp;
select empno,ename,job,mgr,hirdate,sal,comm,deptno from emp
                           *
第 1 行出现错误:
ORA-00904: "HIRDATE": 标识符无效

SQL> --修改命令:c
SQL> c /hirdate/hiredate
  1* select empno,ename,job,mgr,hiredate,sal,comm,deptno from emp
SQL> /

     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 13-7月 -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 13-7月 -87      1100                    20                             

      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命令
SQL> select empno,ename,job,mgr,hirdate,sal,comm,deptno from emp;
select empno,ename,job,mgr,hirdate,sal,comm,deptno from emp
                           *
第 1 行出现错误:
ORA-00904: "HIRDATE": 标识符无效

SQL> ed
已写入 file afiedt.buf

  1* select empno,ename,job,mgr,hiredate,sal,comm,deptno from emp
SQL> /

     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 13-7月 -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 13-7月 -87      1100                    20                             

      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> /*
SQL> select *
SQL> select 列名1,....
SQL> 这两种哪个性能好?第二个好
SQL> 在oracle9i后,可以认为一样
SQL> */
SQL> --查询指定列: 名字,工资,奖金
SQL> select ename,sal,comm from emp;

ENAME             SAL       COMM                                                                                       

--------------- ----- ----------                                                                                       

SMITH             800                                                                                                  

ALLEN            1600        300                                                                                       

WARD             1250        500                                                                                       

JONES            2975                                                                                                  

MARTIN           1250       1400                                                                                       

BLAKE            2850                                                                                                  

CLARK            2450                                                                                                  

SCOTT            3000                                                                                                  

KING             5000                                                                                                  

TURNER           1500          0                                                                                       

ADAMS            1100                                                                                                  

JAMES             950                                                                                                  

FORD             3000                                                                                                  

MILLER           1300                                                                                                  

已选择14行。

SQL> -- 查询员工的年薪=月薪*12
SQL> select ename,sal,sal*12 年薪,comm from emp;

ENAME             SAL       年薪       COMM                                                                            

--------------- ----- ---------- ----------                                                                            

SMITH             800       9600                                                                                       

ALLEN            1600      19200        300                                                                            

WARD             1250      15000        500                                                                            

JONES            2975      35700                                                                                       

MARTIN           1250      15000       1400                                                                            

BLAKE            2850      34200                                                                                       

CLARK            2450      29400                                                                                       

SCOTT            3000      36000                                                                                       

KING             5000      60000                                                                                       

TURNER           1500      18000          0                                                                            

ADAMS            1100      13200                                                                                       

JAMES             950      11400                                                                                       

FORD             3000      36000                                                                                       

MILLER           1300      15600                                                                                       

已选择14行。

SQL> -- 查询员工的年收入=年薪+奖金
SQL> select ename 姓名,sal 月薪,sal*12 年薪, comm 奖金,sal*12+comm 年收入 from emp;

姓名             月薪       年薪       奖金     年收入                                                                 

---------- ---------- ---------- ---------- ----------                                                                 

SMITH             800       9600                                                                                       

ALLEN            1600      19200        300      19500                                                                 

WARD             1250      15000        500      15500                                                                 

JONES            2975      35700                                                                                       

MARTIN           1250      15000       1400      16400                                                                 

BLAKE            2850      34200                                                                                       

CLARK            2450      29400                                                                                       

SCOTT            3000      36000                                                                                       

KING             5000      60000                                                                                       

TURNER           1500      18000          0      18000                                                                 

ADAMS            1100      13200                                                                                       

JAMES             950      11400                                                                                       

FORD             3000      36000                                                                                       

MILLER           1300      15600                                                                                       

已选择14行。

SQL> --关于null值的使用:
SQL> --1. 如果一个表达式中含义null, 会导致整个表达式为null
SQL> --2. 在sql中, null!=null
SQL> --对于第一种情况,使用滤空函数
SQL> select ename 姓名,sal 月薪,sal*12 年薪, comm 奖金,sal*12+ nvl(comm,0) 年收入 from emp;

姓名             月薪       年薪       奖金     年收入                                                                 

---------- ---------- ---------- ---------- ----------                                                                 

SMITH             800       9600                  9600                                                                 

ALLEN            1600      19200        300      19500                                                                 

WARD             1250      15000        500      15500                                                                 

JONES            2975      35700                 35700                                                                 

MARTIN           1250      15000       1400      16400                                                                 

BLAKE            2850      34200                 34200                                                                 

CLARK            2450      29400                 29400                                                                 

SCOTT            3000      36000                 36000                                                                 

KING             5000      60000                 60000                                                                 

TURNER           1500      18000          0      18000                                                                 

ADAMS            1100      13200                 13200                                                                 

JAMES             950      11400                 11400                                                                 

FORD             3000      36000                 36000                                                                 

MILLER           1300      15600                 15600                                                                 

已选择14行。

SQL> --查询奖金为空的员工
SQL> select * from emp
  2  where comm = null;

未选定行

SQL> ed
已写入 file afiedt.buf

  1  select * from emp
  2* where comm is null
SQL> /

     EMPNO ENAME           JOB              MGR HIREDATE         SAL       COMM     DEPTNO                             

---------- --------------- --------- ---------- -------------- ----- ---------- ----------                             

      7369 SMITH           CLERK           7902 17-12月-80       800                    20                             

      7566 JONES           MANAGER         7839 02-4月 -81      2975                    20                             

      7698 BLAKE           MANAGER         7839 01-5月 -81      2850                    30                             

      7782 CLARK           MANAGER         7839 09-6月 -81      2450                    10                             

      7788 SCOTT           ANALYST         7566 13-7月 -87      3000                    20                             

      7839 KING            PRESIDENT            17-11月-81      5000                    10                             

      7876 ADAMS           CLERK           7788 13-7月 -87      1100                    20                             

      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                             

已选择10行。

SQL> select *
  2  frm emp
  3  where comm is null;
frm emp
*
第 2 行出现错误:
ORA-00923: 未找到要求的 FROM 关键字

SQL> ed
已写入 file afiedt.buf

  1  select *
  2  frm emp
  3* where comm is null
SQL> 2
  2* frm emp
SQL> c /frm/from
  2* from emp
SQL> /

     EMPNO ENAME           JOB              MGR HIREDATE         SAL       COMM     DEPTNO                             

---------- --------------- --------- ---------- -------------- ----- ---------- ----------                             

      7369 SMITH           CLERK           7902 17-12月-80       800                    20                             

      7566 JONES           MANAGER         7839 02-4月 -81      2975                    20                             

      7698 BLAKE           MANAGER         7839 01-5月 -81      2850                    30                             

      7782 CLARK           MANAGER         7839 09-6月 -81      2450                    10                             

      7788 SCOTT           ANALYST         7566 13-7月 -87      3000                    20                             

      7839 KING            PRESIDENT            17-11月-81      5000                    10                             

      7876 ADAMS           CLERK           7788 13-7月 -87      1100                    20                             

      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                             

已选择10行。

SQL> --连接符:||
SQL> --查询员工的工资,要求显示的格式: Tom的工资是1000
SQL> select ename||'的工资是'||sal
  2  from emp;

ENAME||'的工资是'||SAL                                                                                                 

----------------------------------------------------------                                                             

SMITH的工资是800                                                                                                       

ALLEN的工资是1600                                                                                                      

WARD的工资是1250                                                                                                       

JONES的工资是2975                                                                                                      

MARTIN的工资是1250                                                                                                     

BLAKE的工资是2850                                                                                                      

CLARK的工资是2450                                                                                                      

SCOTT的工资是3000                                                                                                      

KING的工资是5000                                                                                                       

TURNER的工资是1500                                                                                                     

ADAMS的工资是1100                                                                                                      

JAMES的工资是950                                                                                                       

FORD的工资是3000                                                                                                       

MILLER的工资是1300                                                                                                     

已选择14行。

SQL> select 'Hello World'
  2  from dual;

'HELLOWORLD                                                                                                            

-----------                                                                                                            

Hello World                                                                                                            

已选择 1 行。

SQL> --dual表: Oracle提供的一个伪表
SQL> select 1+2 from dual;

       1+2                                                                                                             

----------                                                                                                             

         3                                                                                                             

已选择 1 行。

SQL> --distinct的使用
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 13-7月 -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 13-7月 -87      1100                    20                             

      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 distinct job from emp;

JOB                                                                                                                    

---------                                                                                                              

CLERK                                                                                                                  

SALESMAN                                                                                                               

PRESIDENT                                                                                                              

MANAGER                                                                                                                

ANALYST                                                                                                                

已选择5行。

SQL> -- distinct作用于多列:当作用列全部相同时,才认为是重复记录
SQL> select distinct job,deptno from emp;

JOB           DEPTNO                                                                                                   

--------- ----------                                                                                                   

MANAGER           20                                                                                                   

PRESIDENT         10                                                                                                   

CLERK             10                                                                                                   

SALESMAN          30                                                                                                   

ANALYST           20                                                                                                   

MANAGER           30                                                                                                   

MANAGER           10                                                                                                   

CLERK             30                                                                                                   

CLERK             20                                                                                                   

已选择9行。

SQL> --追加命令: a(append)
SQL> a order by deptno
  1* select distinct job,deptno from emporder by deptno
SQL> ed
已写入 file afiedt.buf

  1* select distinct job,deptno from emp order by deptno
SQL> /

JOB           DEPTNO                                                                                                   

--------- ----------                                                                                                   

CLERK             10                                                                                                   

MANAGER           10                                                                                                   

PRESIDENT         10                                                                                                   

ANALYST           20                                                                                                   

CLERK             20                                                                                                   

MANAGER           20                                                                                                   

CLERK             30                                                                                                   

MANAGER           30                                                                                                   

SALESMAN          30                                                                                                   

已选择9行。

SQL> --a命令:两个空格
SQL> desc emp
 名称                                                              是否为空? 类型
 ----------------------------------------------------------------- -------- --------------------------------------------
 EMPNO                                                             NOT NULL NUMBER(4)
 ENAME                                                                      VARCHAR2(10)
 JOB                                                                        VARCHAR2(9)
 MGR                                                                        NUMBER(4)
 HIREDATE                                                                   DATE
 SAL                                                                        NUMBER(7,2)
 COMM                                                                       NUMBER(7,2)
 DEPTNO                                                                     NUMBER(2)

SQL> spool off

 

时间: 2025-01-31 06:06:51

Oracle基本查询的相关文章

Oracle数据库查询响应时间的计算公式问题

问题描述 Oracle数据库查询响应时间的计算公式问题 前提条件 1.一个上亿级的数据表(t1),有字段客户memberid,产品productid. 2.查询语句select memberid,productid from t1 where memberid='' and productid='' 问题 1.没有建index,查询返回结果集时间S,记录条数N的计算公式? 2.建立索引(memberid,productid),那么查询返回结果集时间S,记录条数N的计算公式?

用Oracle并行查询发挥多CPU的威力

在一个单独的服务器中安装更多的CPU成为目前的一个趋势.使用对称多处理服务器(SMP)的情况下,一个Oracle服务器拥有8个.16个或32个CPU以及几吉比特RAM的SGA都不足为奇.     Oracle跟上了硬件发展的步伐,提供了很多面向多CPU的功能.从Oracle8i开始,Oracle在每个数据库函数中都实现了并行性,包括SQL访问(全表检索).并行数据操作和并行恢复.对于Oracle专业版的挑战是为用户的数据库配置尽可能多的CPU.     在Oracle环境中实现并行性最好的方法之

如何解决Oracle分页查询中排序与效率问题

本文将结合作者近日工作中,在ORACLE数据库分页查询时,遇到一个小问题,为大家讲解如何解决Oracle分页查询中排序与效率问题. 原始未分页查询Sql代码如下: select ROWNUM rn, t.id ID, o.name YYB,u.name XM, t.MC from tZDYSX t,tuser u,lborganization o where t.cjr=u.id and u.orgid=o.orgcode and t.gx = 1 order by ID 结果如下: RN  I

关联-关于oracle中查询sql的优化

问题描述 关于oracle中查询sql的优化 在数据库中的某个表中有几百万条数据,现在要用这张表关联别的表去查询,查询速度很慢,如何优化才能使查询速度快一些. 解决方案 先优化SQL,然后再优化业务逻辑.最后优化数据库数据存储.起码得把SQL贴出来看看吧,几百万的数据不算多呀. 解决方案二: oracle的权值查询 解决方案三: 用一个相关联的ID,直接查那个表,这样就简单了!

oracle分组查询中 查出的值为空的,用nvl()函数,把为空的填为0 为什么不起作用??

问题描述 oracle分组查询中 查出的值为空的,用nvl()函数,把为空的填为0 为什么不起作用?? 解决方案 不知道具体的情况 不过count(0) 不是null 如果没有值默认也是0 如例 select count(0) from dual where 1=2

脚本-oracle条件查询,才能查询时不区分大小写

问题描述 oracle条件查询,才能查询时不区分大小写 Oracle 默认是区分大小写.如果不要区分,就要额外的设置. 下面就是不区分的脚本设置: ALTER SESSION SET NLS_COMP=ANSI; ALTER SESSION SET NLS_SORT=binary_ci;不过这个是在当前会话上,也就是说在每次发起查询的时候都需要执行这个才能起作用的.那么在java中该怎么设置才能得到所需的结果 解决方案 oracle查询区分大小写查询区分大小写查询区分大小写 解决方案二: sql

c# 从oracle中查询数据,设置时间参数问题,在线等

问题描述 c# 从oracle中查询数据,设置时间参数问题,在线等 各位大神,小弟刚接触c#时间不长,写了个程序,从界面上datatimepicker中取出时间,然后在c#代码的sql语句中设置时间参数,无论怎么设置要不就查不到数据,要不就是时间格式设置的不对,下面是代码 public DataTable QueryUsedMaterial(string classgroup, string beginTime, string endTime) { string sql_QueryMateria

oracle的查询语句问题

问题描述 oracle的查询语句问题 现在有三张表,分别是用户的点餐表,缴费表,价格表,如何通过这三张表来更新余额表 解决方案 create table 表A( id int, username varchar(20), payamount int ); create table 表B( id int, username varchar(20), dishname varchar(100), amount int ); create table 表C( id int, dishname varc

Oracle 数据库查询最近添加的50条数据

问题描述 Oracle数据库查询最近添加的50条数据 解决方案 解决方案二:要有一个可判断顺序的字段,比如递增字段,或者日期,你orderbydesc然后取前50就行解决方案三:selecttop50*fromAorderbyAtimedesc解决方案四:Oracle没有top,但是有rowsnumber解决方案五:oracle的rownumhttp://www.cnblogs.com/zjrstar/archive/2006/08/31/491090.html解决方案六:引用1楼bdmh的回复

过滤两个字段-关于oracle sql查询同一个表,根据不同字段过滤去重的问题

问题描述 关于oracle sql查询同一个表,根据不同字段过滤去重的问题 select j.xmbhid,j.xmmc,j.scjd,j.xmzt from jhxx_new j where j.xxdm='4111010001' and j.lrjh in (209,210,244) order by xmbhid,scjd,xmzt 重复记录中所处阶段三个状态(0,2,3),项目状态(xmzt)两个状态(0,1) 先要查看所处阶段最大值,并且项目状态是1,即第二个图片的显示效果,求大神们帮