Как вернуть несколько ссылок курсора из PostgreSQL? - PullRequest
0 голосов
/ 28 сентября 2018

Я успешно создал функцию.Я хочу вернуть несколько курсоров ссылок, как показано ниже.Когда я выполняю функцию, я получаю ответ, как на картинке ниже.Как я могу решить эту проблему?

CREATE OR REPLACE FUNCTION public.get_dashboard_graph(
    p_fromdate character varying,
    p_todate character varying)
    RETURNS SETOF refcursor 
    LANGUAGE 'plpgsql'
    COST 100.0
    VOLATILE 
    ROWS 1000.0
AS $function$

DECLARE
      process_wise_positrol refcursor;           
      process_wise_micro_audit refcursor;
      process_wise_positrol_line_stop refcursor;          
      process_wise_micro_audit_line_stop refcursor;
BEGIN

-- process wise positrol completed
OPEN process_wise_positrol FOR
    select count(*), d.dd_value from audit_transaction t, audit_master m, dd_type_details d 
    where t.audit_id = m.audit_id and m.activity_id = 9 and t.iscompleted = 'completed' and d.dd_id = m.process 
    and audit_start_time BETWEEN p_fromdate::timestamp AND p_todate::timestamp group by d.dd_value;
RETURN NEXT process_wise_positrol;

-- process wise Micro audit completed
OPEN process_wise_micro_audit FOR
    select count(*), d.dd_value from audit_transaction t, audit_master m, dd_type_details d 
    where t.audit_id = m.audit_id and m.activity_id = 8 and t.iscompleted = 'completed' 
    and d.dd_id = m.process 
    and audit_start_time BETWEEN p_fromdate::timestamp AND p_todate::timestamp group by d.dd_value;
RETURN NEXT process_wise_micro_audit;

-- process wise positrol line stop
OPEN process_wise_positrol_line_stop FOR
    select count(*), d.dd_value from audit_transaction t
    left join audit_master m on m.audit_id= t.audit_id
    left join dd_type_details d on d.dd_id= m.process
    left join audit_ques_link al on al.audit_trans_id= t.audit_trans_id
    where t.audit_id = m.audit_id and m.activity_id = 9 and al.line_stop = 0
    and t.iscompleted = 'completed' and d.dd_id = m.process 
    and audit_start_time BETWEEN p_fromdate::timestamp AND p_todate::timestamp 
    group by d.dd_value;
RETURN NEXT process_wise_positrol_line_stop;

-- process wise Micro audit line  stop
OPEN process_wise_micro_audit_line_stop FOR
    select count(*), d.dd_value from audit_transaction t
    left join audit_master m on m.audit_id= t.audit_id
    left join dd_type_details d on d.dd_id= m.process
    left join audit_ques_link al on al.audit_trans_id= t.audit_trans_id
    where t.audit_id = m.audit_id and m.activity_id = 8 and al.line_stop = 0
    and t.iscompleted = 'completed' and d.dd_id = m.process 
    and audit_start_time BETWEEN p_fromdate::timestamp AND p_todate::timestamp 
    group by d.dd_value;
RETURN NEXT process_wise_micro_audit_line_stop;

END;

$function$;

ALTER FUNCTION public.get_dashboard_graph(character varying, character varying)
    OWNER TO postgres;

Когда я выполняю вышеуказанную функцию, она возвращает вывод, как показано ниже.

select * from get_Dashboard_Graph('09/01/2018','09/28/2018');

enter image description here

1 Ответ

0 голосов
/ 28 сентября 2018

Вы получили именно то, что хотели - четыре курсора.

После того, как cou вызвал функцию, вы можете выполнить оператор SQL

FETCH NEXT FROM "<unnamed portal 26>";

Если вам не нравится имякурсор, назначьте другой внутри тела функции:

process_wise_micro_audit := 'auditcursor';

Затем вы можете вызвать FETCH, как это после завершения функции:

FETCH NEXT FROM auditcursor;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...