PL SQL - 类似于 (!a?0:a) 功能
我在游标中有一个简单的查询
Cursor some_cursor IS
select
sum(some_field)
from some_table table_1
where
table_1.TYPE =1
AND TO_CHAR(table_1.date,'YYYYMMDD') = '20090905'
AND table_1.f2 = 962
AND table_1.f3 = 41813;
然后我做
fetch some_cursor into some_var;--some_var is of type Number, cursor is open
当我运行此查询时, some_var 有可能为 NULL。在这种情况下,id喜欢取0值;
类似
--C like pseudocode of what I want
(some_cursor!=Null?(fetch some_cursor into some_var):(some_var:=0))
有没有办法做到这一点?我正在考虑将上面的查询重写为
Cursor some_cursor IS
select
sum(some_field),count(*)
from some_table table_1
where
table_1.TYPE =1
AND TO_CHAR(table_1.date,'YYYYMMDD') = '20090905'
AND table_1.f2 = 962
AND table_1.f3 = 41813;
然后写入,
fetch some_cursor into some_var,some_counter;
if (some_counter = 0) then
begin
some_var :=0;
end
但这意味着重写 10 个游标(是的,不是那么多)。也许 plsql 有更干净的方法。
提前致谢
I have a simple query in a cursor
Cursor some_cursor IS
select
sum(some_field)
from some_table table_1
where
table_1.TYPE =1
AND TO_CHAR(table_1.date,'YYYYMMDD') = '20090905'
AND table_1.f2 = 962
AND table_1.f3 = 41813;
Then i do
fetch some_cursor into some_var;--some_var is of type Number, cursor is open
When I run this query, there's the chance that some_var will be NULL. In that case, id like it to take the 0 value;
Something like
--C like pseudocode of what I want
(some_cursor!=Null?(fetch some_cursor into some_var):(some_var:=0))
Is there a way to do this? I was thinking of rewriting the above query to
Cursor some_cursor IS
select
sum(some_field),count(*)
from some_table table_1
where
table_1.TYPE =1
AND TO_CHAR(table_1.date,'YYYYMMDD') = '20090905'
AND table_1.f2 = 962
AND table_1.f3 = 41813;
and then writing
fetch some_cursor into some_var,some_counter;
if (some_counter = 0) then
begin
some_var :=0;
end
but this implies rewriting 10 cursors (yes, not so many). Maybe plsql has a cleaner way.
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试:
Try:
您可能会在那里更正其他几个问题:
因此:
You might correct a couple of other issues while you're there:
thus: