oracle 自定义比较函数
1>自定义比较函数,targetVal的值为字符串,例如:“>=90”,"2~8"等范围格式,dataVal值为字符串。
create or replace function compare1(targetVal in varchar2,
dataVal in varchar2) return integer is
v_Result integer;
dataVal_int number;
targetVal_int number;
v_targetVal varchar2(200);
v_dataVal varchar2(200);
v_flag boolean;
v_index integer;
begin
v_flag := true;
v_targetVal := replace(targetVal, ' ');
v_dataVal := replace(dataVal, ' ');
dataVal_int := to_number(v_dataVal);
if instr(v_targetVal, '>=') > 0 then
v_targetVal := replace(v_targetVal, '>=');
targetVal_int := to_number(v_targetVal);
v_flag := dataVal_int >= targetVal_int;
elsif instr(v_targetVal, '>') > 0 then
v_targetVal := replace(v_targetVal, '>');
targetVal_int := to_number(v_targetVal);
v_flag := dataVal_int > targetVal_int;
elsif instr(v_targetVal, '<=') > 0 then
v_targetVal := replace(v_targetVal, '<=');
targetVal_int := to_number(v_targetVal);
v_flag := dataVal_int <= targetVal_int;
elsif instr(v_targetVal, '<') > 0 then
v_targetVal := replace(v_targetVal, '<');
targetVal_int := to_number(v_targetVal);
v_flag := dataVal_int < targetVal_int;
elsif instr(v_targetVal, '~') > 0 then
v_index := instr(v_targetVal, '~');
v_flag := dataVal_int <= to_number(substr(v_targetVal, v_index + 1)) and
dataVal_int >=
to_number(substr(v_targetVal, 1, v_index - 1));
elsif instr(v_targetVal, '=') > 0 then
v_targetVal := replace(v_targetVal, '=');
targetVal_int := to_number(v_targetVal);
v_flag := dataVal_int = targetVal_int;
elsif instr(v_targetVal, '=') = 0 then
targetVal_int := to_number(v_targetVal);
v_flag := dataVal_int = targetVal_int;
end if;
if v_flag then
v_Result := 1;
else
v_Result := 0;
end if;
return(v_Result);
exception
when others then
return 1;
end compare1;
程序员的基础教程:菜鸟程序员
oracle 自定义比较函数的更多相关文章
- oracle 自定义 聚合函数
Oracle自定义聚合函数实现字符串连接的聚合 create or replace type string_sum_obj as object ( --聚合函数的实质就是一个对象 sum ...
- Oracle自定义数据类型 1
原文 oracle 自定义类型 type / create type 一 Oracle中的类型 类型有很多种,主要可以分为以下几类: 1.字符串类型.如:char.nchar.varchar2.nva ...
- Mybatis下配置调用Oracle自定义函数返回的游标结果集
在ibatis和Mybatis对存储过程和函数函数的调用的配置Xml是不一样的,以下是针对Mybatis 3.2的环境进行操作的. 第一步配置Mapper的xml内容 <mapper names ...
- 【C++】自定义比较函数小结
1.使用结构体grid作为map的key struct grid { int x; int y; }; (1)需要自定义比较函数operator<,不然会报错: error C2784: “bo ...
- 【转】Oracle 自定义函数语法与实例
原文地址:https://blog.csdn.net/libertine1993/article/details/47264211 Oracle自定义函数的语法如下: create or replac ...
- Oracle自定义函数和存储过程示例,自定义函数与存储过程区别
参考资料:http://www.newbooks.com.cn/info/60861.html oracle自定义函数学习和连接运算符(||) 贴一段中文文档示例,应该就可以开始工作了: --过程(P ...
- 对于一些stl自定义比较函数
1.unorderd_map自定义键 自定义类型 struct my_key { int num; string name; }; 1.由于unordered_map是采用哈希实现的,对于系统的类型i ...
- ORACLE 自定义聚合函数
用户可以自定义聚合函数 ODCIAggregate,定义了四个聚集函数:初始化.迭代.合并和终止. Initialization is accomplished by the ODCIAggrega ...
- ORACLE自定义顺序排序-转
ORACLE可以借助DECODE函数,自定义顺序排序: select * from ( select 'Nick' as item from dual union all select 'Viki' ...
随机推荐
- 利用Vmware 创建Linux虚拟机的方法
https://blog.csdn.net/qq_34929457/article/details/52663265 使用VMware新建一个Linux系统虚拟机 原创 2016年09月25日 17: ...
- 【nginx&php】后台权限认证方式
一.最常用的方法(代码中限制) 1.如何限制IP function get_new_ip(){ if(getenv('HTTP_CLIENT_IP')) { $onlineip = getenv('H ...
- Linux 互斥锁
互斥的概念 在多线程编程中,引入了对象互斥锁的概念,来保证共享数据操作的完整性. 每个对象都对应于一个可称为" 互斥锁" 的标记,这个标记用来保证在任一时刻, 只能有一个线程访问该 ...
- Mac下的Chrome或Safari访问跨域设置,MBP上使用模拟器Simulator.app或iphone+Safari调试网页
Mac下的Chrome或Safari访问跨域设置: mac下终端启动Chrome $ open -a Google\ Chrome --args --disable-web-security 或 /A ...
- 单片机成长之路(avr基础篇)- 001 ISP与IAP的区别
ISP(In-System Programming)在系统可编程,指电路板上的空白器件可以编程写入最终用户代码, 而不需要从电路板上取下器件,已经编程的器件也可以用ISP方式擦除或再编程.IAP(In ...
- Nginx 学习专栏
Nginx 入门学习教程 译:Centos7 编译安装Nginx 教程
- Sublime Text3 运行 PHP 文件
在 Zend Studio(12.5)下可以通过 Run(Ctrl + F11)把 PHP 程序的执行结果通过 Debug Output 显示在 IDE 中,这样比开启 Server,再打开浏览器执行 ...
- Java8新特性interface中的static方法和default方法
static方法 java8中为接口新增了一项功能:定义一个或者更多个静态方法.用法和普通的static方法一样. 代码示例 public interface InterfaceA { /** * 静 ...
- 【Zookeeper】连接ZooKeeper的方式
使用客户端命令连接Zookeeper 连接Server 使用命令./zkCli.sh -server 127.0.0.1:2181 使用JAVA连接使用ZK POM添加引用 <dependenc ...
- Java编程的逻辑 (88) - 正则表达式 (上)
本系列文章经补充和完善,已修订整理成书<Java编程的逻辑>,由机械工业出版社华章分社出版,于2018年1月上市热销,读者好评如潮!各大网店和书店有售,欢迎购买,京东自营链接:http:/ ...