惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Help Net Security
博客园 - Franky
GbyAI
GbyAI
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
爱范儿
爱范儿
IT之家
IT之家
酷 壳 – CoolShell
酷 壳 – CoolShell
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
Scott Helme
Scott Helme
有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
C
CERT Recently Published Vulnerability Notes
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Jina AI
Jina AI
F
Fortinet All Blogs
N
Netflix TechBlog - Medium
L
LangChain Blog
L
LINUX DO - 最新话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
H
Hacker News: Front Page
MyScale Blog
MyScale Blog
P
Palo Alto Networks Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
AI
AI
T
Troy Hunt's Blog
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
S
Secure Thoughts
大猫的无限游戏
大猫的无限游戏
博客园 - 叶小钗
人人都是产品经理
人人都是产品经理
Blog — PlanetScale
Blog — PlanetScale
博客园 - 司徒正美
Apple Machine Learning Research
Apple Machine Learning Research
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 三生石上(FineUI控件)
S
Security @ Cisco Blogs
Cloudbric
Cloudbric
E
Exploit-DB.com RSS Feed
Attack and Defense Labs
Attack and Defense Labs

博客园 - 阿泰

水晶报表问题交流与答疑帖-2011/07-08-09 水晶报表问题交流与答疑帖-2011/04-05-06 水晶报表问题交流与答疑帖-2010/07-08-09【关闭】 【公告】如果发现博客中图片或文件丢失,请在本贴中回复中贴上URL [转]2010年Gartner企业绩效管理四分区 重要通知:为了能提升答疑质量,本博客的答疑转移到CSDN论坛 2009年11月答疑贴 VS2010beta2中RDLC与水晶报表之简单评测 【水晶报表内功心法】--信手拈来,掌控对象 之 多值参数传入 - 阿泰 2009年10月份答疑贴 Oracle 00600 错误解决方法 2009年9月份答疑帖 2009年8月份答疑贴 【水晶报表内功心法】--完美Excel(下) 【水晶报表内功心法】--完美Excel(上) 【水晶报表内功心法】--公式、函数与运行时总计 【水晶报表内功心法】--第一阶段小结 【水晶报表内功心法】--数据过滤 【水晶报表内功心法】--信手拈来,掌控对象
Oracle中可选参数的处理
阿泰 · 2011-03-28 · via 博客园 - 阿泰

今天遇到这么个小问题,说来也常见。就记录一下。

查询 一个输入范围 内的 数据: Select * from table1 Where fld1>=A and fld<=B

其中A,B均为可选输入项目,有如下几种组合:

1:A有值,B无值,即 Select * from table1 Where fld1>=A

2:A有值,B有值,即 Select * from table1 Where fld1>=A and fld<=B

3:A无值,B无值,即 Select * from table1 

4:A无值,B有值,即 Select * from table1 Where  fld<=B

基本语法如下(Oracle),其中fld1字段为数值型函数

Select * from table1

Where 

decode('&1','',1,fld1)>=to_number(decode('&1','',1,'&1'))

and

decode('&2','',1,fld1)<=to_number(decode('&2','',1,'&2'))

基本思路是:

如果输入的值为空,则主动给一个1,将比对字段也设为1。
这样当值为空时,这个条件转化为1>=1,恒定为true,从而使该条件失效(说有效也可以)。

同理,如果只是对于一个可选参数,就是

Select * from table1

Where 

decode('&1','',1,fld1)>=to_number(decode('&1','',1,'&1'))