how to validate integer datatype in oracle procedure

╄→尐↘猪︶ㄣ 提交于 2019-12-23 04:18:28

问题


I have a parameter with integer data type in a Oracle procedure which produces number of rows mentioned in the parameter into a table.

I want to validate the parameter with its data type. that means, if the parameter value is 5.0 then it creates 5 rows and if the value is 5.2 then it produces error. How do I create this logic?


回答1:


Oddly, PL/SQL does not enforce INTEGER parameters. I would expect Oracle to either implicitly convert the data or throw an error if 5.2 was passed to an INTEGER parameter. Looks like you'll need to add your own validation:

create or replace procedure test_procedure(a integer) is
begin
    if a is not null and a <> trunc(a) then
        raise_application_error(-20000, 'Parameter must be an integer');
    end if;
end;
/

--Works
begin
    test_procedure(5.0);
end;
/

--Fails with "ORA-20000: Parameter must be an integer".
begin
    test_procedure(5.2);
end;
/


来源:https://stackoverflow.com/questions/28775820/how-to-validate-integer-datatype-in-oracle-procedure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!