dbTalk Databases Forums  

Q: Using of variables in PL/SQL in a LOOP??

comp.databases.oracle.server comp.databases.oracle.server


Discuss Q: Using of variables in PL/SQL in a LOOP?? in the comp.databases.oracle.server forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Ralf Bender
 
Posts: n/a

Default Q: Using of variables in PL/SQL in a LOOP?? - 09-12-2006 , 06:13 AM






Hello togehter!

Call me blind, but why is this not working. Is it not possible to use
sFlag(i) or sVNr(i) in a LOOP? :

CREATE OR REPLACE TRIGGER trig_ai2_ABTEST
AFTER INSERT ON ABTEST
FOR EACH ROW
DECLARE
sFlag1 BOOLEAN;
sVNr1 CHAR(5);
sFlag2 BOOLEAN;
sVNr2 CHAR(5);

stemp CHAR(1);
sSQLStatement VARCHAR(250);
BEGIN
IF INSERTING THEN
IF :NEW.V_NUMMER1 IS NOT NULL AND :NEW.SEITE = '001' THEN
sVNr1 := :NEW.V_NUMMER1;
sFlag1 := TRUE;
dbms_output.put_line(SYSDATE ||'Flag1:');
END IF;
IF :NEW.V_NUMMER2 IS NOT NULL AND :NEW.SEITE = '001' THEN
sVNr2 := :NEW.V_NUMMER2;
sFlag2 := TRUE;
dbms_output.put_line(SYSDATE || 'Flag2:');
END IF;

FOR i IN 1 .. 4 LOOP
IF sFlag(i) = TRUE THEN
dbms_output.put_line(SYSDATE || 'Flag(I):'||sVNr(i));
END IF;
END LOOP;
END IF;
END;

/

Reply With Quote
  #2  
Old   
sybrandb
 
Posts: n/a

Default Re: Q: Using of variables in PL/SQL in a LOOP?? - 09-12-2006 , 06:23 AM







Ralf Bender wrote:
Quote:
Hello togehter!

Call me blind, but why is this not working. Is it not possible to use
sFlag(i) or sVNr(i) in a LOOP? :

CREATE OR REPLACE TRIGGER trig_ai2_ABTEST
AFTER INSERT ON ABTEST
FOR EACH ROW
DECLARE
sFlag1 BOOLEAN;
sVNr1 CHAR(5);
sFlag2 BOOLEAN;
sVNr2 CHAR(5);

stemp CHAR(1);
sSQLStatement VARCHAR(250);
BEGIN
IF INSERTING THEN
IF :NEW.V_NUMMER1 IS NOT NULL AND :NEW.SEITE = '001' THEN
sVNr1 := :NEW.V_NUMMER1;
sFlag1 := TRUE;
dbms_output.put_line(SYSDATE ||'Flag1:');
END IF;
IF :NEW.V_NUMMER2 IS NOT NULL AND :NEW.SEITE = '001' THEN
sVNr2 := :NEW.V_NUMMER2;
sFlag2 := TRUE;
dbms_output.put_line(SYSDATE || 'Flag2:');
END IF;

FOR i IN 1 .. 4 LOOP
IF sFlag(i) = TRUE THEN
dbms_output.put_line(SYSDATE || 'Flag(I):'||sVNr(i));
END IF;
END LOOP;
END IF;
END;

/

Sflag is not a collection. sVNR is also not a collection, but a string.
The (<subscript>) syntax applies to collections only.
So yes, you need more coffee.

--
Sybrand Bakker
Senior Oracle DBA



Reply With Quote
  #3  
Old   
Ralf Bender
 
Posts: n/a

Default Re: Q: Using of variables in PL/SQL in a LOOP?? - 09-12-2006 , 09:43 AM



sybrandb said the following on 12.09.2006 12:23:
Quote:
Ralf Bender wrote:
Hello togehter!

Call me blind, but why is this not working. Is it not possible to use
sFlag(i) or sVNr(i) in a LOOP? :

CREATE OR REPLACE TRIGGER trig_ai2_ABTEST
AFTER INSERT ON ABTEST
FOR EACH ROW
DECLARE
sFlag1 BOOLEAN;
sVNr1 CHAR(5);
sFlag2 BOOLEAN;
sVNr2 CHAR(5);

stemp CHAR(1);
sSQLStatement VARCHAR(250);
BEGIN
IF INSERTING THEN
IF :NEW.V_NUMMER1 IS NOT NULL AND :NEW.SEITE = '001' THEN
sVNr1 := :NEW.V_NUMMER1;
sFlag1 := TRUE;
dbms_output.put_line(SYSDATE ||'Flag1:');
END IF;
IF :NEW.V_NUMMER2 IS NOT NULL AND :NEW.SEITE = '001' THEN
sVNr2 := :NEW.V_NUMMER2;
sFlag2 := TRUE;
dbms_output.put_line(SYSDATE || 'Flag2:');
END IF;

FOR i IN 1 .. 4 LOOP
IF sFlag(i) = TRUE THEN
dbms_output.put_line(SYSDATE || 'Flag(I):'||sVNr(i));
END IF;
END LOOP;
END IF;
END;

/


Sflag is not a collection. sVNR is also not a collection, but a string.
The (<subscript>) syntax applies to collections only.
So yes, you need more coffee.

You are right :-)
After a few cups it works .... The question was 10 level under novice...



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.