Oracle 中的 sql语句

一、正则表达式

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)

上面的语句不能使用 sql

isKeepOnPBS_s !=1

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

二、函数

 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

三、编码

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

四、查询当天的记录code

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

五、sql查询当前时间regexp

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

六、查询今日零时到如今的记录ci

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

七、查询一个月内的记录,而且去重复字符串

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

八、日期加it

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

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

九、指定日期时分秒

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'

十、字符串截取和包含

   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'

   select substr( assemblycode_s,0,INSTR( assemblycode_s, '-',-1,1)-1),assemblycode_s  from uda_order where vin_s = 'LS5A23LE1EB091795'

十一、字符串截取和与数字加

  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'

十二、查询数据库编码

   select userenv('language') from dual;

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

若是显示SIMPLIFIED CHINESE_CHINA.AL32UTF8,一个汉字占用三个字节.

若是显示SIMPLIFIED CHINESE_CHINA.UTF8,一个汉字占用三个字节.

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

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

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

select count(*) from user_tables;

1四、使用nvl函数

select nvl(certificatevtype_s, nvl(ppomodule_s, assemblycode_s)) assemblycode_s, certificatcolor_s, enginecode_s from uda_order  where vin_s = 'xxxxxxxxxxxxxxxxx'

1五、使用正则表达式

select atr_key,type_S,regexp_replace(torque_left_front_min_S/10, '^\\D', '0.') from AT_MES_QM_MainArbor_Manage
相关文章
相关标签/搜索