Oracle截取字符串和查找字符串
<div class="postText">
<div id="cnblogs_post_body"><p align="left"><span style="font-size: 15px;">oracle 截取字符(substr),检索字符位置(instr) case when then else end语句使用 收藏 </span><br><span style="font-size: 15px;">常用函数:substr和instr</span><br><span style="font-size: 15px;">1.SUBSTR(string,start_position,[length]) 求子字符串,返回字符串</span><br><span style="font-size: 15px;">解释:string 元字符串</span><br><span style="font-size: 15px;"> start_position 开始位置(从0开始)</span><br><span style="font-size: 15px;"> length 可选项,子字符串的个数</span><br><span style="font-size: 15px;">For example:</span><br><span style="font-size: 15px;">substr("ABCDEFG", 0); //返回:ABCDEFG,截取所有字符 </span><br><span style="font-size: 15px;">substr("ABCDEFG", 2); //返回:CDEFG,截取从C开始之后所有字符 </span><br><span style="font-size: 15px;">substr("ABCDEFG", 0, 3); //返回:ABC,截取从A开始3个字符 </span><br><span style="font-size: 15px;">substr("ABCDEFG", 0, 100); //返回:ABCDEFG,100虽然超出预处理的字符串最长度,但不会影响返回结果,系统按预处理字符串最大数量返回。 </span><br><span style="font-size: 15px;">substr("ABCDEFG", -3); //返回:EFG,注意参数-3,为负值时表示从尾部开始算起,字符串排列位置不变。</span></p>
2.INSTR(string,subString,position,ocurrence)查找字符串位置
解释:string:源字符串
subString:要查找的子字符串
position:查找的开始位置
ocurrence:源字符串中第几次出现的子字符串
For example:
INSTR('CORPORATE FLOOR','OR', 3, 2)中,源字符串为'CORPORATE FLOOR', 目标字符串为'OR',起始位置为3,取第2个匹配项的位置;返回结果为 14 '
</div>
<div class="postfoot">
posted on <span id="post-date">2011-06-14 14:00</span> <a href="http://www.cnblogs.com/gsk99/">gskcc</a> 阅读(<span id="post_view_count">142159</span>) 评论(<span id="post_comment_count">4</span>) <a href="https://i.cnblogs.com/EditPosts.aspx?postid=2080573" rel="nofollow">编辑</a> <a href="#" onclick="AddToWz(2080573);return false;">收藏</a>
</div>
<div class="post">
<div class="postTitle">
<a href="#2682129" class="layer">#3楼</a><a name="2682129" id="comment_anchor_2682129"></a>
<span>
<span class="comment_date">2013-05-16 12:34</span>
</span>
<a id="a_comment_author_2682129" href="http://www.cnblogs.com/crazyjava/" target="_blank">Chunwai Yeung</a> <a href="http://msg.cnblogs.com/send/Chunwai%20Yeung" title="发送站内短消息" class="sendMsg2This"> </a>
</div>
<div class="postText">
<div id="comment_body_2682129" class="blog_comment_body"><a href="#2681224" title="查看所回复的评论" onclick="commentManager.renderComments(0,50,2681224);">@</a>
gskcc
substr('ABCDEFG',-3)
用sqldevelop运行 select substr('ABCDEFG',-3) from dual;
<div class="post">
<div class="postTitle">
<a href="#2682132" class="layer">#4楼</a><a name="2682132" id="comment_anchor_2682132"></a>[<span class="louzhu">楼主</span>]<span id="comment-maxId" style="display:none;">2682132</span><span id="comment-maxDate" style="display:none;">2013/5/16 12:40:29</span>
<span>
<span class="comment_date">2013-05-16 12:40</span>
</span>
<a id="a_comment_author_2682132" href="http://www.cnblogs.com/gsk99/" target="_blank">gskcc</a> <a href="http://msg.cnblogs.com/send/gskcc" title="发送站内短消息" class="sendMsg2This"> </a>
</div>
<div class="postText">
<div id="comment_body_2682132" class="blog_comment_body"><a href="#2682129" title="查看所回复的评论" onclick="commentManager.renderComments(0,50,2682129);">@</a>
仗剑行江湖
多谢指教
评论
仗剑行江湖
谢谢指点,应该是这样吗?
substr("ABCDEFG", -3);