网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > 数据库 > Oracle教程
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
数据库:数据库教程,数据库技巧,Oracle教程,MySQL教程,Sybase教程,Access教程,DB2教程,数据库安全,数据库文摘
本月文章推荐
.使用Instr()与decode()进行多条件.
.9I新特性之细粒度访问原则.
.ORALCE的执行计划稳定性.
.PL/SQL中的多进程通信技术简介.
.在Java中使用Oracle blob.
.日期运用union的一种奇怪现象及解.
.邮件管理篇 VmailMgr.
.oracle数据库性能监控的SQL的几种.
.Oracle中Trigger例子2.
.[Oracle] 书写历史的甲骨文――O.
.MYSQL到ORACLE程序迁移的注意事项.
.Oracle 10g 可传输表空间现在可以.
.在UNIX环境下创建第二个数据库实.
.ORA-03113错误分析与解决.
.DISKGEN V2.0 (DISKMAN)运用一例.
.优化Oracle停机时间及数据库恢复.
.Linux Shadow-Password-HOWTO.
.Oracle数据库较好的重新启动步骤.
.如何杀死oracle死锁进程.
.ORACLE在HP-UX下的系列问题处理(.

使用Instr()与decode()进行多条件组合查询

发表日期:2008-2-9


    系统中碰到了要处理多条件组合查询的情况,好比说有4个独立的条件,那么组合出的查询条件便有24种,不可能写24条Sql语句再分别指定给24种组合情况吧,条件数再多点呢,人都会搞疯的。。。。于是我求助于高手,获得了使用instr()和decode()函数的实现方法。     下面先说明一下instr()的功能和语法:(函数的语法是从http://www.techonthenet.com/Oracle/functions/index.htm处得到的,相当清楚明了:)
In Oracle/PLSQL, the instr function returns the location of a substring in a string. The syntax for the instr function is: instr (string1, string2, [start_position], [nth_appearance]) string1 is the string to search. string2 is the substring to search for in string1. start_position is the position in string1 where the search will start.  This argument is optional.  If omitted, it defaults to 1.  The first position in the string is 1.  If the start_position is negative, the function counts back start_position number of characters from the end of string1 and then searches towards the beginning of string1. nth_appearance is the nth appearance of string2.  This is optional.  If omiited, it defaults to 1.
再说明一下decode()的功能和语法: In Oracle/PLSQL, the decode function has the functionality of an IF-THEN-ELSE statement. The syntax for the decode function is: decode ( eXPression , search , result [, search , result]... [, default] ) expression is the value to compare. search is the value that is compared against expression. result is the value returned, if expression is equal to search. default is optional.  If no matches are found, the decode will return default.  If default is omitted, then the decode statement will return null (if no matches are found). 综合使用得到的SQL语句如下: select e.到达日期,
       e.角色名,
       d.单据标题,
       d.单据编号,
       e.节点编号,
       e.处理动作,
       e.处理日期,
       b.流程实例编号   from gzl_流程类型     a,
       gzl_流程实例     b,
       gzl_流程定义     c,
       dj_单据          d,
       gzl_流程流转状态 e
 where a.流程类型编号 = c.流程类型编号 and e.处理标记 = '是'
       and   e.用户id = 'tetdmis' and b.流程定义编号 = c.流程定义编号    
       and b.活动编号 = d.单据编号 and c.流程定义编号 = b.流程定义编号
       and  e.流程实例编号 = b.流程实例编号
    
  and instr(decode(:流程类型条件, '-1', a.流程类型编号, :流程类型条件), a.流程类型编号) > 0
      and (to_char(e.处理日期, 'yyyy-mm-dd') between :开始日期 and :结束日期)      
       and instr(decode(:节点名称条件, '-1', e.处理动作, :节点名称条件),
                 e.处理动作) > 0
上一篇:Oracle XML学习笔记-存储XML数据 人气:827
下一篇:系统对象IDL_UB1$表的含义及作用 人气:678
浏览全部Oracle教程的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐