日期:2014-05-17  浏览次数:20923 次

SQL(ORACLE)中的条件和is not null问题
IF( '111 '   IS   NOT NULL){
IF(strV = 「1」 )
{    
strV  LIKE     SUBSTR(   strV ,1,1) +’%’  

ELSE IF(strV = 「1」 )

strV  LIKE     SUBSTR(strV ,1,1) +’%’  



以上这段逻辑,写在sql的where部分,怎么写,我试着写了一下,碰到两个问题:

第一、case   '111 '   when   is   not   null....或者case   '111 '   when   not   null都会说is   not   null语法不对。

第二、SUBSTR( '111 ',1,1) +’%’   这样他不认识百分号,应该怎么写

哪位高手帮我完整的翻译一下,谢谢

------解决方案--------------------
楼主oracle的版本是9i以上的吗??
8i不支持case when。
------解决方案--------------------
如果楼主写的是WHERE子句的过滤条件,那么用函数decode()应该能解决楼主的问题,希望楼主用自然语言表达一下自己的想法,你写的东西 ,看不明白,呵呵
------解决方案--------------------
1、如果不支持CASE ... WHEN ... 用DECODE()

2、SUBSTR( '111 ',1,1) || '% '
------解决方案--------------------
strV like DECODE( '111 ',NULL,strV,DECODE(strV,1,SUBSTR(strV,1,1)|| '% ',NULL))
------解决方案--------------------
在where子句里用or
比如select 1 from dual where ( '123 ' is null and 1=1) or ( '123 ' is not null and 1 <> 1)
------解决方案--------------------
1.case when '111 ' is not null then '0 ' end
2.SUBSTR( '111 ',1,1) || '% '
------解决方案--------------------
没有看懂楼主想做啥
-_-