开发者

Suppress ORA-01403: no data found excpetion

I have the following code

SELECT SUM(nvl(book_value,
                   0))
    INTO v_balance
    FROM account_details
    WHERE currency = 'UGX';

--Write the balance away

SELECT SUM(nvl(book_value,
                   0))
    INTO v_balance
    FROM account_details
    WHERE currency = 'USD';

--Write the balance away

Now the problem is, there might not be data in the table for that specific currency, but there might be data for the 'USD' currency. So basically I want to select the sum into my variable and if there is no data I want my stored proc to continue and not throw the 01403 exception.

I don't want to put every select into statement in a BEGIN EXCEPTION END block either, 开发者_开发知识库so is there some way I can suppress the exception and just leave the v_balance variable in an undefined (NULL) state without the need for exception blocks?


select nvl(balance,0) 
into v_balance
from 
(
    select sum(nvl(book_value,0)) as balance
    from account_details
    where currency = 'UGX'
);


SELECT L1.PKCODE L1CD,  L1.NAME L1N, L1.LVL L1LVL,
          L2.PKCODE L2CD, L2.NAME L2N,  L2.LVL L2LVL,
          L5.PKCODE L5CD, L5.NAME L5N,

INFOTBLM.OPBAL (  L5.PKCODE, :PSTDT, :PSTUC, :PENUC, :PSTVT, :PENVT ) OPBAL,
INFOTBLM.DEBIT    ( L5.PKCODE, :PSTDT,:PENDT, :PSTUC, :PENUC, :PSTVT, :PENVT ) AMNTDR,
INFOTBLM.CREDIT ( L5.PKCODE, :PSTDT,:PENDT, :PSTUC, :PENUC, :PSTVT, :PENVT ) AMNTCR

FROM   FSLVL  L1, FSLVL L2,  FSMAST L5

WHERE  L2.FKCODE  =  L1.PKCODE
AND        L5.FKCODE  =  L2.PKCODE

AND        L5.PKCODE Between :PSTCD AND NVL(:PENCD,:PSTCD)

GROUP BY  L1.PKCODE ,  L1.NAME , L1.LVL ,
                 L2.PKCODE , L2.NAME ,  L2.LVL ,
                 L5.PKCODE , L5.NAME 

ORDER BY L1.PKCODE, L2.PKCODE,  L5.PKCODE
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜