Subject Re: Functions in PL/SQL
Author maximshiryaev
Hi.

You can use a UDF from inside a store procedure. And the stored
procedure can be used in a view.

Real example:

I had a stored proc that checks whether two values are similar:

CREATE PROCEDURE IS_DISTINCT_INT (
a integer,
b integer)
returns (
res integer)
as
begin
if (a = b or (a is null and b is null) ) then begin
res = 0;
end else begin
res = 1;
end

suspend;
end

I can use it in a view:

CREATE VIEW V_TEST(
ID,
SOMETHING)
AS
select
id,
(select res from is_distinct_int(1, 2))
from sometable
;

Now if I have a UDF, somethig like

DECLARE EXTERNAL FUNCTION EQINT
INTEGER,
INTEGER
RETURNS INTEGER BY VALUE
ENTRY_POINT 'EQINT' MODULE_NAME 'somelib'

the only thing I should change is a declaration of IS_DISTINCT_INT
to use this UDF instead of SPL code:

ALTER PROCEDURE IS_DISTINCT_INT (
a integer,
b integer)
returns (
res integer)
as
begin
res = EQINT(a, b);
end

Maxim.