Oracle 中的 sql语句

1、

select rowId,vin_S, assemblycode_s, assemblydes_s, case iskeeponpbs_s when '1' then '是' else '否' end, specialdes_s from uda_order where stage_s < '4800'  and (isKeepOnPBS_s =0 or isKeepOnPBS_s is null) and OBJECT_KEY in (select order_key from work_order where creation_time > to_date('2014-10-10 15:30:29','yyyy-mm-dd hh24:mi:ss')  and   creation_time < to_date('2014-10-18 15:30:29','yyyy-mm-dd hh24:mi:ss')  )

case iskeeponpbs_s when '1' then '是' else '否' end

and (isKeepOnPBS_s =0 or isKeepOnPBS_s is null)

上面的语句不能使用 

isKeepOnPBS_s !=1

来查找(当数据库中isKeepOnPBS存在1,0,null三种情况时),否则null值的查不出来,<>和!=都是不等于,都可以使用

2、

 with temp as(select vin_s from (select vin_s from at_mes_interface_car_move where 1=1  and station_name_s = 'AB_ON'  order by entry_time_t desc) where rownum = 1) select temp.vin_s, ua.csn_s, case ua.areanum_s when 'WE' then ua.vtypecode_s  when '2P' then ua.pbtypecode_s when '2A' then ua.assemblycode_s end  CARTYPE, ua.plannum_s,ua.SENDERPCSN_I from temp left join uda_order ua on temp.vin_s = ua.vin_s

3、

select rownum,id,name from student where rownum=1;
select rownum,id,name from student where rownum<3;

4、查询当天的记录

select *
from tabname
where trunc(dtcol) = trunc(sysdate)

5、sql查询当前时间

select to_char(sysdate,'yyyy-MM-dd HH24:mi:ss') from dual

6、查询今日零时到现在的记录

select count(1) from table_name where entry_time_t>= trunc(SYSDATE)  and  entry_time_t<=sysdate

7、查询一个月内的记录,并且去重复

select station_name_s,stage_s from at_mes_interface_car_move where creation_time>trunc(add_months(sysdate,-1)) group by station_name_s,stage_s  order by stage_s

8、日期加

select PLAN_CNT from SCHEDULED_PRODUCTION where plan_start_time <=to_char(trunc(sysdate)+6/24,'yyyy-mm-dd hh24:mi:ss')

字符串形式存储的时间也可以进行大小的比较

9、指定日期时分秒

update uda_order set entry_station_time_t=to_date('2014-12-19 14:54:31','yyyy-mm-dd hh24:mi:ss') where vin_s = 'LS5A33BE8EB340351'

10、字符串截取和包含

   select vin_s,pvi_s from AT_MES_Interface_Car_Move where instr(csn_s,(select substr(csn_s,4,9)+1 
   from AT_MES_Interface_Car_Move where vin_s='LS5A33FE5EB346411' and station_name_s='AB_ON' and rownum=1))>0 and station_name_s='AB_ON'

11、字符串截取和与数字加

  select vin_s,pvi_s,csn_s,station_name_s from AT_MES_Interface_Car_Move where  (substr(csn_s,4,9)+0=(select substr(csn_s,4,9)+1 
   from AT_MES_Interface_Car_Move where vin_s='LS5A23LE1EB091795' and station_name_s='AB_ON' and rownum=1)) and station_name_s='AB_ON'

12、查询数据库编码

   select userenv('language') from dual;

如果显示SIMPLIFIED CHINESE_CHINA.ZHS16GBK,一个汉字占用两个字节;

如果显示SIMPLIFIED CHINESE_CHINA.AL32UTF8,一个汉字占用三个字节.

如果显示SIMPLIFIED CHINESE_CHINA.UTF8,一个汉字占用三个字节.

查看一个汉字占用几个字节

select lengthb('你') from dual;//返回2,表示2个字节

13、查看当前用户有多少张表

select count(*) from user_tables;


你可能感兴趣的:(Oracle 中的 sql语句)