Insert语句无法识别变量值

问题描述 投票:-2回答:1

包装上的代码工作正常。从oracle表单中,我试图在表中插入新条目。

错误信息

ORA-01400:无法插入NULL(“BUS”。“BP_AUTH_CODE”。“CODE”)

Declare
    v_bn varchar2(9);
    v_bn_exists number;
    v_has_auth_code number;
    v_auth_code varchar2(9);
Begin
    v_bn := :TAC.bn;

    v_bn_exists := CG$BP_AUTH_CODE.bn_exists(v_bn);

    if v_bn_exists = 1 then
        .....

        if v_has_auth_code = 1 then
            ...
        else
            v_auth_code := CG$BP_AUTH_CODE.make_auth_code;
            --Error happening over here
            insert into bp_auth_code (bn, code) values(v_bn, v_auth_code);
            commit;
            message(v_auth_code); -- I can see the value
        end if; 

    else
        ....
    end if;

End;
oracle oracle10g oracleforms
1个回答
0
投票

我怕你错了:

v_auth_code := CG$BP_AUTH_CODE.make_auth_code;
--Error happening over here
insert into bp_auth_code (bn, code) values(v_bn, v_auth_code);
commit;
message(v_auth_code); -- I can see the value

说“你可以看到价值” - 不,你不能。

如果INSERT失败,Oracle会引发ORA-01400错误,因此执行停止。 INSERT背后没有任何内容被执行,其中包括MESSAGE调用。你不可能知道这个价值,但是 - 如果我是你,我会相信甲骨文。如果它说CODE为null,那么它就是。

根据您使用的Forms版本,您可以(始终)重写代码(用于调试目的)

v_auth_code := CG$BP_AUTH_CODE.make_auth_code;
message(v_auth_code);             -- now you'll see the V_AUTH_CODE value
insert into bp_auth_code (bn, code) values(v_bn, v_auth_code);
commit;

或者以调试模式运行表单(不要忘记设置断点!)并跟踪其执行情况。

© www.soinside.com 2019 - 2024. All rights reserved.