我正在尝试使用条件elsif
,其中需要使用类似解码的内容,以便条件为真并进行插入。我在一个程序和条件就是这样做
elsif ((v_DIVIDEND/Divisor)-1 < ABS(0.2)) then
insert into table(Divisor,b,c) values(Dividend,y,z);
当除数不为零时它工作正常但是当除数为零时它失败。我想在elsif
或类似解码之类的情况下使用另一个嵌套if条件来排除除数中的零。我尝试了另一个if
,但语法似乎错了。使用Decode
表示它只能在SQL语句中使用。有任何建议,请...
答案 0 :(得分:0)
好吧,根据你想要得到的结果,当divisor = 0时(即大或某些小),你可以使用这样的东西:< / p>
对于小结果(除以1E99):
case when divisor = 0 then 1E99 else divisor end
对于大的结果(除以1E-99)
case when divisor = 0 then 1E-99 else divisor end
由于您无法使用DECODE:这是正确的,它只能在SELECT语句中使用。这意味着您应该重写代码并将所有内容放入SELECT(这可能是一个坏主意)。所以 - 试试CASE。
答案 1 :(得分:0)
也许您可以添加这样的条件来检查org.ow2.authzforce.core.pdp.api.IndeterminateEvaluationException: Function urn:oasis:names:tc:xacml:1.0:function:integer-equal: indeterminate arg
at org.ow2.authzforce.core.pdp.api.func.BaseFirstOrderFunctionCall$EagerSinglePrimitiveTypeEval.evaluate(BaseFirstOrderFunctionCall.java:662)
at org.ow2.authzforce.core.pdp.api.func.BaseFirstOrderFunctionCall.evaluate(BaseFirstOrderFunctionCall.java:359)
at org.ow2.authzforce.core.pdp.impl.expression.ApplyExpressions$VariableApplyExpression.evaluate(ApplyExpressions.java:87)
at org.ow2.authzforce.core.pdp.impl.rule.ConditionEvaluators$BooleanExpressionEvaluator.evaluate(ConditionEvaluators.java:94)
at org.ow2.authzforce.core.pdp.impl.rule.RuleEvaluator.evaluate(RuleEvaluator.java:535)
at org.ow2.authzforce.core.pdp.impl.combining.CombiningAlgEvaluators$RulesWithSameEffectEvaluator.evaluate(CombiningAlgEvaluators.java:134)
at org.ow2.authzforce.core.pdp.impl.policy.PolicyEvaluators$BaseTopLevelPolicyElementEvaluator.evaluate(PolicyEvaluators.java:764)
at org.ow2.authzforce.core.pdp.impl.policy.PolicyEvaluators$BaseTopLevelPolicyElementEvaluator.evaluate(PolicyEvaluators.java:881)
at org.ow2.authzforce.core.pdp.impl.policy.RootPolicyEvaluators$StaticView.findAndEvaluate(RootPolicyEvaluators.java:190)
at org.ow2.authzforce.core.pdp.impl.BasePdpEngine$IndividualDecisionRequestEvaluator.evaluateInNewContext(BasePdpEngine.java:685)
at org.ow2.authzforce.core.pdp.impl.BasePdpEngine$NonCachingIndividualDecisionRequestEvaluator.evaluate(BasePdpEngine.java:730)
at org.ow2.authzforce.core.pdp.impl.BasePdpEngine.evaluate(BasePdpEngine.java:984)
at org.ow2.authzforce.core.pdp.api.io.BasePdpEngineAdapter.evaluate(BasePdpEngineAdapter.java:128)
at org.ow2.authzforce.core.pdp.api.io.BasePdpEngineAdapter.evaluate(BasePdpEngineAdapter.java:149)
at XACMLTester.main(XACMLTester.java:29)
Caused by: org.ow2.authzforce.core.pdp.api.IndeterminateEvaluationException: Indeterminate arg #0
at org.ow2.authzforce.core.pdp.api.func.BaseFirstOrderFunctionCall.evalPrimitiveArgs(BaseFirstOrderFunctionCall.java:94)
at org.ow2.authzforce.core.pdp.api.func.BaseFirstOrderFunctionCall.access$200(BaseFirstOrderFunctionCall.java:53)
at org.ow2.authzforce.core.pdp.api.func.BaseFirstOrderFunctionCall$EagerSinglePrimitiveTypeEval.evaluate(BaseFirstOrderFunctionCall.java:658)
... 14 more
Caused by: org.ow2.authzforce.core.pdp.api.IndeterminateEvaluationException: Function urn:oasis:names:tc:xacml:1.0:function:integer-one-and-only: Invalid arg #0: empty bag or bag size > 1. Required: one and only one value in bag.
at org.ow2.authzforce.core.pdp.api.func.FirstOrderBagFunctions$SingletonBagToPrimitive.<init>(FirstOrderBagFunctions.java:82)
at org.ow2.authzforce.core.pdp.api.func.FirstOrderBagFunctions.getFunctions(FirstOrderBagFunctions.java:554)
at org.ow2.authzforce.core.pdp.impl.func.StandardFunction.getRegistry(StandardFunction.java:901)
at org.ow2.authzforce.core.pdp.impl.PdpEngineConfiguration.<init>(PdpEngineConfiguration.java:286)
at org.ow2.authzforce.core.pdp.impl.PdpEngineConfiguration.getInstance(PdpEngineConfiguration.java:479)
at org.ow2.authzforce.core.pdp.impl.PdpEngineConfiguration.getInstance(PdpEngineConfiguration.java:519)
at org.ow2.authzforce.core.pdp.impl.PdpEngineConfiguration.getInstance(PdpEngineConfiguration.java:551)
at org.ow2.authzforce.core.pdp.impl.PdpEngineConfiguration.getInstance(PdpEngineConfiguration.java:687)
at org.ow2.authzforce.core.pdp.impl.PdpEngineConfiguration.getInstance(PdpEngineConfiguration.java:704)
at XACMLTester.main(XACMLTester.java:23)
是否为零。
Divisor
答案 2 :(得分:0)
您可以尝试nullif
:
declare
divisor constant integer := 0;
result number;
begin
result := 100 / nullif(divisor,0);
end;
如果divisor
的值为0
,则result
替换为null,将<Directory>
设为空。
答案 3 :(得分:0)
你也可以处理“divisor equal to zero”异常并在发生错误时进行插入,参见处理“divisor equal to zero”异常的示例代码,
示例1:此示例定义了divisor_equal_to_zero异常
DECLARE
divisor_equal_to_zero EXCEPTION;
PRAGMA EXCEPTION_INIT(divisor_equal_to_zero, -1476);
v_divisor NUMBER := 0;
v_quotient NUMBER;
BEGIN
v_quotient := 1/v_divisor;
DBMS_OUTPUT.PUT_LINE('Print A: '||v_quotient);
EXCEPTION
WHEN divisor_equal_to_zero THEN
v_divisor := 1;
v_quotient := 1/v_divisor;
DBMS_OUTPUT.PUT_LINE('Print B: '||v_quotient);
--you can put the insert statement here
END;
/
示例2:此示例使用预定义的ZERO_DIVIDE异常
DECLARE
v_divisor NUMBER := 0;
v_quotient NUMBER;
BEGIN
v_quotient := 1/v_divisor;
DBMS_OUTPUT.PUT_LINE('Print A: '||v_quotient);
EXCEPTION
WHEN ZERO_DIVIDE THEN
v_divisor := 1;
v_quotient := 1/v_divisor;
DBMS_OUTPUT.PUT_LINE('Print B: '||v_quotient);
--you can put the insert statement here
END;
/