PostgreSQL过程多个选择语句结果作为输出

时间:2018-11-22 06:54:50

标签: postgresql procedure

我们如何从Postgresql过程中获得多个结果集。以下是我创建的不起作用的过程。我知道这不是它在Postgresql中的工作方式,但是无法在任何地方找到所需的答案。之后,我需要在Java JDBC中获得这些多个结果集。

CREATE OR REPLACE PROCEDURE public.validate_user_login(
a_username character varying,
a_password character varying,
a_ip character varying,
a_uuid character varying,
a_appid integer,
a_osname character varying,
a_osversion character varying,
a_devicemake character varying,
a_devicemodel character varying,
a_devicelat numeric,
a_devicelong numeric
)
LANGUAGE 'plpgsql'

AS $BODY$

DECLARE
v_tenant_id INTEGER;
v_user_id INTEGER;
v_tenant_device_id INTEGER;
statuscode INTEGER;

BEGIN

select user_id  , tenant_id into v_tenant_id  , v_user_id
from public.users 
where username = a_username
and password = a_password;

if v_tenant_id > 0 AND v_user_id > 0 
then 
    statuscode := 1;

    select tenant_device_id into v_tenant_device_id from tenant_devices
    where tenant_id = v_tenant_id
    and uuid = a_uuid;

    insert into login_history (user_id , app_id , geo_lat , geo_long                 ,ip_address , tenant_device_id)
    VALUES (v_user_id, a_appid,a_devicelat ,a_devicelong , a_ip, v_tenant_device_id );
else
    statuscode := -1;
end if;


select user_id , username , email , phone_no, alt_phone_no
from public.users 
where username = a_username
and password = a_password 
limit 1;

select role_id from
public.user_roles
where user_id = v_user_id;

select statuscode;
END

$BODY$;

0 个答案:

没有答案