单表查询

–conn scott/tiger
select * from emp;
select * from emp where (1=1);
select * from ( select empno,sal 工资 from emp) where 工资<1000;–列别名在select以后才有效;
select * from emp where comm is null;
–coalesce(a,b,c,d,e,f);unllif(‘a’,‘a’)返回null,unllif(‘a’,‘b’)返回a;
SQL> select nvl(4,‘abc’) from dual;
ORA-01722: 无效数字
SQL> select nvl(to_char(4),‘abc’) from dual; --nvl的二个参数数据类型要一致。
select nvl(comm,0) from emp;
select nvl2(comm,comm,9999) from emp;
select decode(comm,null,9999,comm) from emp;
select replace(‘abc’,‘a’,null) from dual;
select ‘insert into t318(dates) values (’||hiredate||’)’ from emp;
select 档次,count() as 人数 from (select (case when sal<=1000 then ‘0000-1000’
when sal<=2000 then ‘1000-2000’
when sal<=3000 then ‘2000-3000’
when sal<=4000 then ‘3000-4000’
else ‘high’ end) as 档次 from emp) group by 档次 order by 1;
select rownum,emp.
from emp where rownum<5;
--case floor((to_char(stat_date, ‘mi’)) / 15) when 0 then to_char(stat_date, ‘yyyy.mm.dd hh24’) || ‘:00:00’
 --                  when 1 then to_char(stat_date, ‘yyyy.mm.dd hh24’) || ‘:15:00’

你可能感兴趣的:(oracle,sql)