(8.0.29)
drop procedure proc1;
delimiter //
create procedure proc1(
in param1 numeric
,inout param2 numeric
,out param3 numeric
)
begin
set param2 = param2 * param2;
set param3 = param1 * 100;
end
//
delimiter ;
set @i = 10;
set @j = 20;
call proc1(@i,@j,@k);
select @i,@j,@k;
(19c)
create or replace procedure proc1(
param1 in number
,param2 in out number
,param3 out number
)
as
begin
param2 := param2 * param2;
param3 := param1 * 100;
end;
/
show error;
set serveroutput on
declare
i number;
j number;
k number;
begin
i := 10;
j := 20;
proc1(i,j,k);
dbms_output.put_line('i: ' || i);
dbms_output.put_line('j: ' || j);
dbms_output.put_line('k: ' || k);
end;
/
(14)
create or replace procedure proc1(
param1 in numeric
,param2 inout numeric
,param3 out numeric
)
language plpgsql
as $$
declare
begin
param2 := param2 * param2;
param3 := param1 * 100;
end;
$$;
do $$
declare
i numeric;
j numeric;
k numeric;
begin
i := 10;
j := 20;
call proc1(i,j,k);
raise info 'i: %', i;
raise info 'j: %', j;
raise info 'k: %', k;
end;
$$;
(2019)
IN OUTパラメータはない模様のため、2つの変数で代用
OUTPUT 変数は、プロシージャの作成時と変数の使用時に定義する必要があります。
create or alter procedure proc1(
@param1 numeric
,@param21 numeric
,@param22 numeric out
,@param3 numeric out
)
as
begin
set @param22 = @param21 * @param21;
set @param3 = @param1 * 100;
end
go
declare @i numeric;
declare @j1 numeric;
declare @j2 numeric;
declare @k numeric;
set @i = 10;
set @j1 = 20;
begin
exec proc1 @i, @j1, @j2 out, @k out
print '@i: ' + cast(@i as varchar)
print '@j1: ' + cast(@j1 as varchar)
print '@j2: ' + cast(@j2 as varchar)
print '@k: ' + cast(@k as varchar)
end
go