错误:查询在使用游标时没有结果数据的目的地 [英] Error: query has no destination for result data while using a cursor

查看:190
本文介绍了错误:查询在使用游标时没有结果数据的目的地的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数,我写了自动执行一组功能为我的项目。我采取一个refcursor,我存储我需要的数据,我将作为参数传递给我的每个函数被调用,并基于参数将被执行。我在这里给我的代码:

I have a function which I have written to automate the execution of a group of functions for my project. I am taking a refcursor where I am storing my required data which I will be passing as an argument to each of my functions being called and based on the argument will get executed. I am giving my code here:

CREATE OR REPLACE FUNCTION ccdb.fn_automation()
RETURNS void AS
$BODY$

DECLARE 
sec_col refcursor;
cnt integer;
sec_code ccdb.update_qtable%ROWTYPE;
new_cnt numeric;

BEGIN

SELECT COUNT(*) INTO cnt FROM ccdb.update_qtable WHERE status_flag IN (-1,1);

OPEN sec_col FOR SELECT DISTINCT section_code FROM ccdb.update_qtable WHERE status_flag IN (-1,1);

FOR i IN 1..cnt
LOOP

        FETCH sec_col INTO sec_code;
        SELECT ccdb.o_dtr_update(sec_code.section_code);
        SELECT ccdb.o_consumer_update_for_update(sec_code.section_code);
        SELECT ccdb.o_bills_update_for_update(sec_code.section_code);
        SELECT ccdb.o_payments_update_for_update_new(sec_code.section_code);
        SELECT ccdb.o_payments_map_update_for_update(sec_code.section_code);

        SELECT COUNT(*) INTO new_cnt FROM ccdb.update_qtable WHERE status_flag IN (-1,1);

        IF new_cnt > cnt 
        THEN 
            CLOSE sec_col;

            OPEN sec_col FOR SELECT DISTINCT section_code FROM ccdb.update_qtable WHERE status_flag IN (-1,1);

            cnt := new_cnt;
        END IF;

END LOOP;

CLOSE sec_col;

END;

$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;

现在这里面临的问题是,每当我尝试执行这个函数,错误说:

Now here the problem that I am facing is, whenever I try to execute this function, i get an error saying,

ERROR:  query has no destination for result data
HINT:  If you want to discard the results of a SELECT, use PERFORM instead.
CONTEXT:  PL/pgSQL function ccdb.fn_automation() line 20 at SQL statement

I不知道我应该在这个函数中使用PERFORM的位置。上下文说错误在行20,即我打开我的游标时使用的SELECT语句。所以我不能如何解决这个问题。

I don't know where am I supposed to use PERFORM in this function. The the context says the error is in line 20, i.e., the SELECT statement which I am using while opening my cursor. So I don't how can I resolve this issue.

推荐答案

根据手册中的说明


有时评估表达式或 SELECT 查询很有用,但
舍弃结果,例如当调用具有
副作用但没有有用结果值的函数时。要在PL / pgSQL中执行此操作,请使用
PERFORM 语句:

Sometimes it is useful to evaluate an expression or SELECT query but discard the result, for example when calling a function that has side-effects but no useful result value. To do this in PL/pgSQL, use the PERFORM statement:

PERFORM query;


这篇关于错误:查询在使用游标时没有结果数据的目的地的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆