INSTR函数浅析

2024-08-30 22:18
文章标签 函数 浅析 instr

本文主要是介绍INSTR函数浅析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

--INSTR函数


{ INSTR| INSTRB| INSTRC| INSTR2| INSTR4}(string , substring [, position [, occurrence ] ])


The INSTR functions search string for substring. The search operation is defined as comparing the substring argument with substrings of string of the same length for equality until a match is found or there are no more substrings left. Each consecutive compared substring of string begins one character to the right (for forward searches) or one character to the left (for backward searches) from the first character of the previous compared substring. If a substring that is equal to substring is found, then the function returns an integer indicating the position of the first character of this substring. If no such substring is found, then the function returns zero.

返回找到的子串的位置。


position is an nonzero integer indicating the character of string where Oracle Database begins the search—that is, the position of the first character of the first substring to compare with substring. If position is negative, then Oracle counts backward from the end of string and then searches backward from the resulting position.

如果position值为负,则从右往左开始搜寻。


occurrence is an integer indicating which occurrence of substring in string Oracle should search for. The value of occurrence must be positive. If occurrence is greater than 1, then the database does not return on the first match but continues comparing consecutive substrings of string, as described above, until match number occurrence has been found.


Examples

The following example searches the string CORPORATE FLOOR, beginning with the third character, for the string "OR". It returns the position in CORPORATE FLOOR at which the second occurrence of "OR" begins:

SELECT INSTR('CORPORATE FLOOR','OR', 3, 2) "Instring"FROM DUAL;Instring
----------14
--寻找CORPORATE FLOOR中从第三个字符开始第二次出现的'OR‘位置。


题目练习


http://www.itpub.net/thread-2072122-1-1.html


哪些选项实现了一个名为plch_between_2_4的函数,使得下列代码块执行之后会显示 "enXFeue" ?


BEGINsys.DBMS_OUTPUT.put_line (plch_between_2_4 ('StevenXFeuerstein', 'e'));
END;
/(A) 
CREATE OR REPLACE FUNCTION plch_between_2_4 (string_in   IN VARCHAR2, letter_in   IN VARCHAR2)RETURN VARCHAR2
IS
BEGINRETURN SUBSTR (string_in, INSTR (string_in, letter_in, 1, 2),   INSTR (string_in, letter_in, 1, 4)- INSTR (string_in, letter_in, 1, 2)+ 1);
END;
/(B) 
CREATE OR REPLACE FUNCTION plch_between_2_4 (string_in   IN VARCHAR2, letter_in   IN VARCHAR2)RETURN VARCHAR2
ISc_2nd   CONSTANT PLS_INTEGER:= INSTR (string_in, letter_in, 1, 2) ;c_4th   CONSTANT PLS_INTEGER:= INSTR (string_in, letter_in, 1, 4) ;
BEGINRETURN SUBSTR (string_in, c_2nd, c_4th - c_2nd + 1);
END;
/(C) 
CREATE OR REPLACE FUNCTION plch_between_2_4 (string_in   IN VARCHAR2, letter_in   IN VARCHAR2)RETURN VARCHAR2
ISl_2nd   PLS_INTEGER:= INSTR (string_in, letter_in, 1, 2);l_4th   PLS_INTEGER:= INSTR (string_in, letter_in, l_2nd + 1, 2);
BEGINRETURN SUBSTR (string_in, l_2nd, l_4th - l_2nd + 1);
END;
/(D) 
CREATE OR REPLACE FUNCTION plch_between_2_4 (string_in   IN VARCHAR2, letter_in   IN VARCHAR2)RETURN VARCHAR2
IS
BEGINRETURN SUBSTR (string_in, letter_in, 2, 4);
END;
/

A选项中相当于SUBSTR('StevenXFeuerstein', 5 , 11-5+1) 结果是enXFeue,BC选项其实和A选择表达的意思相同,D选项substr( string, start_position, [ length ] )参数超过了要求的所以报错,答案应该是ABC


这篇关于INSTR函数浅析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1122086

相关文章

Python itertools中accumulate函数用法及使用运用详细讲解

《Pythonitertools中accumulate函数用法及使用运用详细讲解》:本文主要介绍Python的itertools库中的accumulate函数,该函数可以计算累积和或通过指定函数... 目录1.1前言:1.2定义:1.3衍生用法:1.3Leetcode的实际运用:总结 1.1前言:本文将详

浅析如何使用Swagger生成带权限控制的API文档

《浅析如何使用Swagger生成带权限控制的API文档》当涉及到权限控制时,如何生成既安全又详细的API文档就成了一个关键问题,所以这篇文章小编就来和大家好好聊聊如何用Swagger来生成带有... 目录准备工作配置 Swagger权限控制给 API 加上权限注解查看文档注意事项在咱们的开发工作里,API

轻松上手MYSQL之JSON函数实现高效数据查询与操作

《轻松上手MYSQL之JSON函数实现高效数据查询与操作》:本文主要介绍轻松上手MYSQL之JSON函数实现高效数据查询与操作的相关资料,MySQL提供了多个JSON函数,用于处理和查询JSON数... 目录一、jsON_EXTRACT 提取指定数据二、JSON_UNQUOTE 取消双引号三、JSON_KE

MySQL数据库函数之JSON_EXTRACT示例代码

《MySQL数据库函数之JSON_EXTRACT示例代码》:本文主要介绍MySQL数据库函数之JSON_EXTRACT的相关资料,JSON_EXTRACT()函数用于从JSON文档中提取值,支持对... 目录前言基本语法路径表达式示例示例 1: 提取简单值示例 2: 提取嵌套值示例 3: 提取数组中的值注意

Java function函数式接口的使用方法与实例

《Javafunction函数式接口的使用方法与实例》:本文主要介绍Javafunction函数式接口的使用方法与实例,函数式接口如一支未完成的诗篇,用Lambda表达式作韵脚,将代码的机械美感... 目录引言-当代码遇见诗性一、函数式接口的生物学解构1.1 函数式接口的基因密码1.2 六大核心接口的形态学

浅析Rust多线程中如何安全的使用变量

《浅析Rust多线程中如何安全的使用变量》这篇文章主要为大家详细介绍了Rust如何在线程的闭包中安全的使用变量,包括共享变量和修改变量,文中的示例代码讲解详细,有需要的小伙伴可以参考下... 目录1. 向线程传递变量2. 多线程共享变量引用3. 多线程中修改变量4. 总结在Rust语言中,一个既引人入胜又可

Oracle的to_date()函数详解

《Oracle的to_date()函数详解》Oracle的to_date()函数用于日期格式转换,需要注意Oracle中不区分大小写的MM和mm格式代码,应使用mi代替分钟,此外,Oracle还支持毫... 目录oracle的to_date()函数一.在使用Oracle的to_date函数来做日期转换二.日

C++11的函数包装器std::function使用示例

《C++11的函数包装器std::function使用示例》C++11引入的std::function是最常用的函数包装器,它可以存储任何可调用对象并提供统一的调用接口,以下是关于函数包装器的详细讲解... 目录一、std::function 的基本用法1. 基本语法二、如何使用 std::function

浅析Spring Security认证过程

类图 为了方便理解Spring Security认证流程,特意画了如下的类图,包含相关的核心认证类 概述 核心验证器 AuthenticationManager 该对象提供了认证方法的入口,接收一个Authentiaton对象作为参数; public interface AuthenticationManager {Authentication authenticate(Authenti

hdu1171(母函数或多重背包)

题意:把物品分成两份,使得价值最接近 可以用背包,或者是母函数来解,母函数(1 + x^v+x^2v+.....+x^num*v)(1 + x^v+x^2v+.....+x^num*v)(1 + x^v+x^2v+.....+x^num*v) 其中指数为价值,每一项的数目为(该物品数+1)个 代码如下: #include<iostream>#include<algorithm>