想问一下,下面那样的IF语句应该怎么写,能让里面的第二个IF语句能生效呢?,仅限于筛选B表的SQL语句,求大佬帮解决
SELECT *
FROM DUAL A
WHERE 1 = 1
${IF(LEN(AA)= 0 ,
"AND ROWNUM = (SELECT ROWNUM
FROM DUAL B
AND ROWID = '"+AA+"'
IF(LEN(BB)=0,"AND ROWNUM = 1","AND ROWNUM = '"+BB+"'" )
")}
,'')
帆软里的动态语句,函数是不能被""双引号包起来的,所以你第二段的AA+"'这里要用双引号回收,变成AA+"'",然后用+连接if语句,if写完之后后面没有sql语句了,所以最后那个双引号要删掉
${IF(LEN(AA)= 0
,"SELECT SYSDATE
FROM DUAL"
,"SELECT *
FROM DUAL
AND ROWNUM = '"+AA+"'"+
IF(LEN(BB)=0,"AND ROWNUM = 1","AND ROWNUM = '"+BB+"'")
)}
修改后新语句:
SELECT * FROM DUAL A
${IF(LEN(AA)= 0 ,'',
"AND ROWNUM = (SELECT ROWNUM FROM DUAL B
AND ROWID = '"+AA+"'"+
IF(LEN(BB)=0,"AND ROWNUM = 1)","AND ROWNUM = '"+BB+"')"))}
${IF(LEN(AA)=0,"SELECT SYSDATE
FROM DUAL", IF(LEN(BB)=0,"
WHERE
ROWNUM = 1","
ROWNUM = 2"))}