其實這個比較簡單,用oracle自帶截取函數便可,oracle
select e.*, trim(f.f_id), f.leader, trim(f.leader_tele), trim(leader_handset), f.firm_type from ENTERPRISEINFO e left join JC_FIRM f on trim(f.f_id) = substr(e.id, 1, instr(e.id, '-') - 1) where 1 = 1 and (e.enterprise_name like '%番禺%' or e.code like '%番禺%' or e.contactor like '%番禺%') order by id asc
當時沒注意到F_ID字段值有空格!!!,一直查不出數據,加個trim()去掉空格就行了!函數
而後 left join後面多個條件時,用where.... and....拼接查詢條件,(以前直接在on後面 用 and 了,細節問題要注意)code
截取「-」後的子串: substr(
e.id
,instr(e.id
,
'-'
)+1,length(e.id
)-instr(e.id
,
'-'
))
blog