一、正則表達式
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