问题描述
我在Oracle过程中有一个带整数数据类型的参数,它会将参数中提到的行数生成到表中。
I have a parameter with integer data type in a Oracle procedure which produces number of rows mentioned in the parameter into a table.
我想用其数据类型验证参数。这意味着,如果参数值为5.0,则它会创建5行,如果值为5.2,则会产生错误。如何创建此逻辑?
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?
推荐答案
奇怪的是,PL / SQL不强制执行 INTEGER
参数。如果将5.2传递给 INTEGER
参数,我希望Oracle隐式转换数据或抛出错误。看起来您需要添加自己的验证:
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;
/
这篇关于如何在oracle过程中验证整数数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!