X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 361AB9DC84D for ; Wed, 14 Dec 2005 04:21:34 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 95219-09 for ; Wed, 14 Dec 2005 04:21:34 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web52809.mail.yahoo.com (web52809.mail.yahoo.com [206.190.48.252]) by postgresql.org (Postfix) with SMTP id A1BDC9DC810 for ; Wed, 14 Dec 2005 04:21:31 -0400 (AST) Received: (qmail 36639 invoked by uid 60001); 14 Dec 2005 08:21:30 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Subject:To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=lhATKpeWSrMNruL2hQ0BUQ2VgocCWMamcBJaOLCWpuMvCawZ1JjQhK2iNFhjl3geF+1VyRbXahRRJKff+lGZHXFC2UsN7g6jzOkjLANpExBuhXssrLkqk0ZMl1n0ktqPsACmauKk6lB49crqOabzIPVYHVOcdvIvzDn2oUQjKAU= ; Message-ID: <20051214082130.36637.qmail@web52809.mail.yahoo.com> Received: from [86.34.7.25] by web52809.mail.yahoo.com via HTTP; Wed, 14 Dec 2005 00:21:30 PST Date: Wed, 14 Dec 2005 00:21:30 -0800 (PST) From: Calin Meze Subject: Help me do a LOOP To: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="0-1225382331-1134548490=:28077" Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.48 required=5 tests=[DNS_FROM_RFC_ABUSE=0.479, HTML_MESSAGE=0.001] X-Spam-Score: 0.48 X-Spam-Level: X-Archive-Number: 200512/185 X-Sequence-Number: 23727 --0-1225382331-1134548490=:28077 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit I need to test each record of a cursor for some requirements, something like this DECLARE xpvnr varchar(50); xdata date; xcod int; xagentd varchar(3); xid bigint; xserie varchar(4); xnr varchar(7); xsocasig varchar(3); DECLARE myCursor CURSOR FOR select cod,pvnr,data,agentd,id,serie,nr,socasig from pvmst, pvdtl where pvmst.cod=pvdtl.cod order by data; BEGIN delete from stoccalc_temp; OPEN myCursor; FETCH NEXT FROM myCursor INTO xcod,xpvnr,xdata,xagentd,xid,xserie,xnr, xsocasig; WHILE (still in the cursor) BEGIN DECLARE xxcod varchar(21); xxcod2 varchar(21); xxagent varchar(3); xxid bigint; DECLARE my2cursor CURSOR FOR select cod,agent,id from stoccalc_temp where nr=xnr and serie=xserie and socasig=xsocasig; OPEN my2cursor; FETCH NEXT FROM my2cursor INTO xxcod,xxagent,xxid; xxcod2:=TRIM('2005'+TRIM(xsocasig)+TRIM(xxagent)+TRIM(xserie)+TRIM(xnr)); IF xxcod <> '' THEN -- inseamna ca este in stoccalc_temp polita update stoccalc set cod=xxcod2, agent=xxagent, stare='0' where id=xid; END IF; CLOSE my2cursor; FETCH NEXT FROM myCursor INTO xcod,xpvnr,xdata,xagentd,xid,xserie,xnr,xsocasig; END; CLOSE myCursor; END; -- the problem is that I do not know how to make the while loop execute until the last record "WHILE (still in the cursor)"... So I need something like for i:=1 to lastrecord_of_cursor do begin ... end; Can anyone help me with this? It really seems silly... but I cannot get to solve this, I do not know where to look for syntax like this or tutorials like this. Help --------------------------------- Yahoo! Shopping Find Great Deals on Holiday Gifts at Yahoo! Shopping --0-1225382331-1134548490=:28077 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: 8bit
 I need to test each record of a cursor for some requirements, something like this

DECLARE xpvnr varchar(50);
     xdata date;
     xcod int;
     xagentd varchar(3);
     xid bigint;
     xserie varchar(4);
     xnr varchar(7);
     xsocasig varchar(3);
DECLARE myCursor CURSOR FOR
     select cod,pvnr,data,agentd,id,serie,nr,socasig
     from pvmst, pvdtl
     where pvmst.cod=pvdtl.cod
     order by data;
BEGIN
delete from stoccalc_temp;
OPEN myCursor;
FETCH NEXT FROM myCursor INTO xcod,xpvnr,xdata,xagentd,xid,xserie,xnr,
xsocasig;  
WH ILE (still in the cursor)
     BEGIN
     DECLARE
          xxcod varchar(21);
          xxcod2 varchar(21);
          xxagent varchar(3);
          xxid bigint;
     DECLARE my2cursor CURSOR FOR
          select cod,agent,id from stoccalc_temp
          where nr=xnr and serie=xserie and socasig=xsocasig;
          OPEN my2cursor;
          FETCH NEXT FROM my2cursor INTO xxcod,xxagent,xxid;
          xxcod2:=TRIM('2005'+TRIM(xsocasig)+TRIM(xxagent)+TRIM(xserie)+TRIM(xnr));
          IF xxcod <> '' THEN -- inseamna ca este in stoccalc_temp polita
          update stoccalc set cod=xxcod2, agent=xxagent, stare='0' where id=xid;
          END IF;
          CLOSE my2cursor;
     FETCH NEXT FROM myCursor INTO xcod,xpvnr,xdata,xagentd,xid,xserie,xnr,xsocasig;
     END;
CLOSE myCursor;
END;

-- the problem is that I do not know how to make the while loop execute until the last record "WHILE (still in the cursor)"... So I need something like

for i:=1 to lastrecord_of_cursor do
begin
...
end;

Can anyone help me with this? It really seems silly... but I cannot get to solve this, I do not know where to look for syntax like this or tutorials  like this.
Help


Yahoo! Shopping
Find Great Deals on Holiday Gifts at Yahoo! Shopping --0-1225382331-1134548490=:28077--