当前位置:Gxlcms > 数据库问题 > 【Oracle】【19】instr()和substr()函数

【Oracle】【19】instr()和substr()函数

时间:2021-07-01 10:21:17 帮助过:8人阅读

instr():判断字符串是否包含某指定字符

substr():截取字符串

正文:

1,instr()

语法:instr(sourceString,destString,start,appearPosition) → instr(‘源字符串‘ , ‘目标字符串‘ ,‘开始位置‘,‘第几次出现‘);start,appearPosition默认为1

返回值:查找到的字符串的位置

注:位置从1开始计算;返回值为指定字符的第一个字符位置,如果start大于第一个字符位置,取第二个字符位置,以此类推

  1. <span style="color: #0000ff;">select</span> instr(<span style="color: #ff0000;">‘</span><span style="color: #ff0000;">yuechaotianyuechao</span><span style="color: #ff0000;">‘</span>,<span style="color: #ff0000;">‘</span><span style="color: #ff0000;">ao</span><span style="color: #ff0000;">‘</span>) position <span style="color: #0000ff;">from</span><span style="color: #000000;"> dual;
  2. </span><span style="color: #008080;">--</span><span style="color: #008080;"> 得到6</span>

2,substr()

语法:substr( string, start_position, [ length ] ) → substr(‘目标字符串‘,开始位置,长度)

注:位置从1开始计算;length不填默认为到末尾;start_position为负数代表从右往左

  1. substr(<span style="color: #ff0000;">‘</span><span style="color: #ff0000;">This is a test</span><span style="color: #ff0000;">‘</span>, <span style="color: #800000; font-weight: bold;">6</span>, <span style="color: #800000; font-weight: bold;">2</span><span style="color: #000000;">)
  2. </span><span style="color: #008080;">--</span><span style="color: #008080;"> 得到 is</span>

参考博客:

oracle截取字段中的部分字符串 - Agoly - 博客园
https://www.cnblogs.com/qmfsun/p/4493918.html

【Oracle】【19】instr()和substr()函数

标签:appear   第一个字符   返回值   any   www   字段   get   star   包含   

人气教程排行