1 instr函数的概念
在Oracle中可以使用instr函数对某个字符串进行判断,判断其是否含有指定的字符。在一个字符串中查找指定的字符,返回被查找到的指定
的字符的位置。
2 语法
instr(sourceString,destString,start,appearPosition)
instr(‘源字符串’,‘⽬标字符串’,‘开始位置’,‘第几次出现’)
- 其中sourceString代表源字符串;
- destString代表要从源字符串中查找的子串;
- start代表查找的开始位置,这个参数可选的,默认为1;
- appearPosition代表想从源字符中查找出第几次出现的destString,这个参数也是可选的, 默认为1
- 如果start的值为负数,则代表从右往左进行查找,但是位置数据仍然从左向右计算。
- 返回值为:查找到的字符串的位置。如果没有查找到,返回0。
3 示例
select * from ( select t.id,
t.market_contract_no,
t.purchase_code,
t.purchase_name,
t.purchase_name as purchase_name1,
t.subsidiary_code,
t.subsidiary_name,
t.subsidiary_name as subsidiary_name2,
case when instr( '吉林通钢国际贸易有限公司,吉林通钢国际贸易有限公司长春分公司,
吉林通钢国际贸易有限公司哈尔滨分公司,吉林通钢国际贸易有限公司宁波分公司,吉林通钢国际贸易有限公司大连分公司,吉林通钢国际贸易有限公司无锡分公司
,吉林通钢国际贸易有限公司沈阳分公司, 吉林通钢国际贸易有限公司现货市场',t.subsidiary_name)> 0 then '通化钢铁股份有限公司' else '' end as subsidiary_name1, t.dept_code,
t.dept_name,
t.warehouse_code,
warehouse_td.dict_name as warehouse_name,
t.product_category,
t.delivery_type,
delivery_type_td.dict_name as delivery_type_name,
t.price_file,
t.resource_file,
t.notes_gm,
to_char(t.order_goods_date, 'yyyy-MM-dd') as order_goods_date,
to_char(t.delivery_date, 'yyyy-MM-dd') as delivery_date,
t.market_contract_status,
t.update_user_cd,
t.update_user_name,
t.update_date,
t.create_user_cd,
t.create_user_name,
t.create_user_name || to_char(t.create_date, 'yyyy-mm-dd hh24:mi:ss') as create_user_date,
t.create_date
, to_char(t.create_date, 'yyyy-mm-dd') as create_date_new
, t.item_code,
td.dict_name as market_contract_status_name,
nvl(market.total_weight, 0) as total_weight,
nvl(out.executed_weight, 0) as executed_weight,
nvl((market.total_weight - nvl(out.executed_weight, 0)), 0) as unexecuted_weight
from t_market_contract t
left join ( select a.market_contract_no, sum(a.actual_weight) as executed_weight from t_out_market_contract_detail a left join t_out_market_contract b on a.out_contract_no = b.out_contract_no where b.out_contract_status != '6' group by a.market_contract_no ) out on out.market_contract_no = t.market_contract_no
left join( select market_contract_no, sum(total_weight) as total_weight from t_market_contract_detail group by market_contract_no ) market on market.market_contract_no = t.market_contract_no
left join t_dict td on td.dict_code = t.market_contract_status and td.dict_type = 'market_contract_status'
left join t_dict delivery_type_td on delivery_type_td.dict_code = t.delivery_type and delivery_type_td.dict_type = 'delivery_type'
left join t_dict warehouse_td on warehouse_td.dict_code = warehouse_code and warehouse_td.dict_type='warehouse'
) a where 1=1 and a.unexecuted_weight>0.5 order by a.create_date desc
4 也可以用在where条件中,同理like