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])&nbsp;&nbsp;&nbsp; 求子字符串,返回字符串</span><br><span style="font-size: 15px;">解释:string 元字符串</span><br><span style="font-size: 15px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; start_position&nbsp;&nbsp; 开始位置(从0开始)</span><br><span style="font-size: 15px;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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 '

 

 

 

3
0
« 上一篇:oracle时间转换:12小时24小时制
» 下一篇:.net创建Windows应用程序基本文件介绍
</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="#2681162" class="layer">#1楼</a><a name="2681162" id="comment_anchor_2681162"></a>
				<span>
					 <span class="comment_date">2013-05-15 15:33</span>
				</span>
			<a id="a_comment_author_2681162" href="http://www.cnblogs.com/crazyjava/" target="_blank">Chunwai Yeung</a> <a href="http://msg.cnblogs.com/send/Chunwai%20Yeung" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="postText">
			<div id="comment_body_2681162" class="blog_comment_body">substr("ABCDEFG", 0, -3); //返回:EFG,注意参数-3,为负值时表示从尾部开始算起,字符串排列位置不变。<br><br>这个应该去掉0,否则,取到的值为null</div><div class="comment_vote"><a href="javascript:void(0);" class="comment_digg" onclick="return voteComment(2681162,'Digg',this)">支持(0)</a><a href="javascript:void(0);" class="comment_bury" onclick="return voteComment(2681162,'Bury',this)">反对(0)</a></div>
		</div>
        <div class="commentOpt">
		&nbsp;&nbsp;<span class="comment_actions"><a href="javascript:void(0);" onclick="return ReplyComment(2681162,'yx4O7QX5osd/Fbkkcgq8eZ4rAO+tpOJ5Nlty7lhEn8cv8hXf/59MdQ==')">回复</a><a href="javascript:void(0);" onclick="return QuoteComment(2681162,'yx4O7QX5osd/Fbkkcgq8eZ4rAO+tpOJ5Nlty7lhEn8cv8hXf/59MdQ==')">引用</a></span>
        </div>
	</div>
	<br>

	<div class="post">			
		<div class="postTitle">
			<a href="#2681224" class="layer">#2楼</a><a name="2681224" id="comment_anchor_2681224"></a>[<span class="louzhu">楼主</span>]
				<span>
					 <span class="comment_date">2013-05-15 16:14</span>
				</span>
			<a id="a_comment_author_2681224" href="http://www.cnblogs.com/gsk99/" target="_blank">gskcc</a> <a href="http://msg.cnblogs.com/send/gskcc" title="发送站内短消息" class="sendMsg2This">&nbsp;</a>
		</div>
		<div class="postText">
			<div id="comment_body_2681224" class="blog_comment_body"><a href="#2681162" title="查看所回复的评论" onclick="commentManager.renderComments(0,50,2681162);">@</a>

仗剑行江湖
谢谢指点,应该是这样吗?
substr("ABCDEFG", -3);






	<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">&nbsp;</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">&nbsp;</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>

仗剑行江湖
多谢指教






posted @ 2017-03-15 15:03  jobs-lgy  阅读(295)  评论(0编辑  收藏  举报