How to pass params in function at for in select loop end loop

53 Views Asked by At

enter image description hereI have a function with 2 char params. I tried pass it by order $1 $2, by name with and without a colon and via alias. it doesn't work - I get an empty result. When passing values instead of parameters, everything is ok. Also try to change types of params varchar -> character varying and still get an empty result.

CREATE OR REPLACE FUNCTION archive_kasudr__dds.f_get_soap1(p_sel_id varchar, p_sel_dt varchar)
    RETURNS text
    LANGUAGE plpgsql
    VOLATILE
AS $$
    
declare 
p_sel_id_a ALIAS FOR p_sel_id;
p_sel_dt_a ALIAS FOR p_sel_dt;

rez text:='';
temprow RECORD;
var_result  text;

begin

FOR temprow IN SELECT
                    attr_id,
                    low_val, 
                    high_val 
                FROM 
                    archive_kasudr__dds.tunes 
                WHERE 
                    sel_id = 'A5' and --:p_sel_id  $1 p_sel_id_a
                    sel_dt = 'TD' and --:p_sel_dt  $2 p_sel_dt_a
                    clause = 'W'    and 
                    dim_id = 'SOAP'
                ORDER BY 
                    sel_num
    LOOP 
        rez = rez || temprow.low_val;
        
        IF temprow.attr_id = 'VAR' then 
            EXECUTE temprow.high_val into var_result;
            rez = rez || var_result;
        END IF;
    END LOOP;
    
                
RETURN rez;

END;

$$
EXECUTE ON ANY;

select archive_kasudr__dds.f_get_soap1('A5', 'DT');

How to pass params correctly?

1

There are 1 best solutions below

0
Babo On

Excuse me, guys.I got the letters mixed up in places. TD - DT Everything is worked.