问题
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