我想做个类似if(1==1){
where a=a
}else{
where b=b
}
用oracle能实现吗?
比如:select * from aa表 where if(1==1){a=1条件一}else{b=2条件二}
where a=a
}else{
where b=b
}
用oracle能实现吗?
比如:select * from aa表 where if(1==1){a=1条件一}else{b=2条件二}
counted int := 0;
strSql varchar2(1000) := '';
begin
strSql := 'select count(1) from hi_indicators';
execute immediate strSql into counted;
if (counted = 0) then
dbms_output.put_line('the table is empty.');
else
dbms_output.put_line('the table has ' || to_char(counted) || ' records');
end if;
end;--结果
the table has 46 records
可以使用union
请参考:SELECT * FROM 表名
WHERE 列名1 = 特定值 AND 列名2 = 某个值
UNION
SELECT * FROM 表名
WHERE 列名1 != 特定值 AND 列名2 = 另外某个值;
select * from aa表
where 1==1 and a=条件一
union all
select * from aa表
where 1<>1 and b=条件二
WHERE (FIELD1 = 'A' AND FIELD2 = 'B')
OR (FIELD1 <> 'A' AND FIELD3 = 'C')
表名.id=263547
}
这个意思。因为某些原因我不能写存储过程,不能在后台进行sql拼接。只能用SQL语句弄出来。
FIELD1 = 'A' 和 FIELD1 <> 'A' 这2个条件只有1个成立
所以(FIELD1 = 'A' AND FIELD2 = 'B') 等价于 IF(TRUE){...}
(FIELD1 <> 'A' AND FIELD3 = 'C') 等价于 ELSE{...}
...;
elsif 1=2 then
..;
else
..;
end if;
WHEN COL > 1 THEN
'1'
ELSE
'4'
END
FROM TABLE应该可以实现,或者可以用存储过程