Re: [PL/pgSQL] How should I use FOUND special variable.

From: Matthias(dot)Pitzl(at)izb(dot)de
To: jmiedzinski(at)gmail(dot)com, pgsql-general(at)postgresql(dot)org
Subject: Re: [PL/pgSQL] How should I use FOUND special variable.
Date: 2006-11-09 12:35:21
Message-ID: 11EC9A592C31034C88965C87AF18C2A70CFCD9@m0000s61
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi!

Just use this:

FETCH crs_cnt into row_cnt;
EXIT WHEN NOT FOUND;

Greetings,
Matthias

-----Original Message-----
From: pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Jeremiasz
Miedzinski
Sent: Thursday, November 09, 2006 1:15 PM
To: pgsql-general(at)postgresql(dot)org
Subject: [GENERAL] [PL/pgSQL] How should I use FOUND special variable.
Documentation is little unclear for me

Hello.

I'm porting some procedures from PL/SQL and I encountered following
problem:
In PL/SQL I'm using this statement related to cursor:

OPEN crs_cnt(start_millis, end_millis);
LOOP
FETCH crs_cnt into row_cnt;
EXIT WHEN crs_cnt%NOTFOUND;
insert into spm_audit_stats values(SEQ_SPM_ID_AUTO_INC.nextval,
start_millis, base_stat_period, row_cnt.adt_count, row_cnt.adt_avg,
row_cnt.adt_max, row_cnt.adt_min, row_cnt.adt_stdev,
row_cnt.adt_service_name, row_cnt.adt_root_user);
global_counter := global_counter + 1;
END LOOP;
CLOSE crs_cnt;

Now, I need to do the same action in PL/pgSQL. It's rather simple, but I
don't know how to use FOUND variable described in documentation:

FETCH retrieves the next row from the cursor into a target, which may be a
row variable, a record variable, or a comma-separated list of simple
variables, just like SELECT INTO. As with SELECT INTO, the special variable
FOUND may be checked to see whether a row was obtained or not.

When I'm trying to use it in Oracle way, my DB reports error. Also I tried
to use it like that:

IF NOT crs_cnt%FOUND THEN ...

But it also doesn't worked for me.

Thanks for any help.

Kind Regards.

--
-- audi vide sile --

Browse pgsql-general by date

  From Date Subject
Next Message Matthias.Pitzl 2006-11-09 12:38:55 Re: autovacuum blues
Previous Message Harco de Hilster 2006-11-09 12:31:08 Re: converting Informix outer to Postgres