Home » SQL & PL/SQL » SQL & PL/SQL » Problem with pl/sql for loop (oracle 10g)
Problem with pl/sql for loop [message #353286] Mon, 13 October 2008 04:43 Go to next message
citella
Messages: 3
Registered: October 2008
Junior Member
I have this data:

RESTO1=9 RESTO2=9 REST03=9 X=3 Z=10



I want to write this C code in pl/sql:

FOR (i=0;i=x;i++) {
y=resto(i)+resto(i+1);

if (y>z) { Q(i+1)=(z-resto(i));resto(i+1)=resto(i+1)-q(i+1);}

else Q(i+1)=resto(i); resto(i+1)=0;

}



I know very well pl/sql for loop structure, but
how i can do whit pl/sql to use progressive variable name made by a varchar+ for index, like: resto(i),resto(i+1),q(i),q(i+1) etc etc...???

Thanks.
Re: Problem with pl/sql for loop [message #353294 is a reply to message #353286] Mon, 13 October 2008 04:54 Go to previous messageGo to next message
Michel Cadot
Messages: 64151
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Use array as in your C code or dynamic SQL.
Anyway it is not a useful exercise, he should never happen in real life.

Also please read OraFAQ Forum Guide, especially "How to format your post?" section.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code (See SQL Formatter) and align the columns in result.
Use the "Preview Message" button to verify.

Post a test case: create table and insert statements along with the result you want with these data.
And always post what you tried.

Regards
Michel

[Updated on: Mon, 13 October 2008 04:54]

Report message to a moderator

Re: Problem with pl/sql for loop [message #353334 is a reply to message #353286] Mon, 13 October 2008 06:04 Go to previous messageGo to next message
tanmoy1048
Messages: 133
Registered: June 2007
Senior Member
DECLARE
    TYPE v_arr IS VARRAY(25) of NUMBER(3);
    v1 v_arr;
    a number;
    BEGIN
        v1(1):=9;
        v1(2):=11;
        v1(3):=10;
        v1(4) := 3;
for x in 1..3 loop
a:=v1(x)+v1(x+1);
..................
............................
end loop;
    END;


Does it work for u?

[Updated on: Mon, 13 October 2008 06:04]

Report message to a moderator

Re: Problem with pl/sql for loop [message #353361 is a reply to message #353334] Mon, 13 October 2008 09:46 Go to previous message
citella
Messages: 3
Registered: October 2008
Junior Member
Thanks to all.
I resolve it with array like you say.
Thanks. Laughing
Previous Topic: Oracle Query_Trigger
Next Topic: New in PL/SQL Triggers
Goto Forum:
  


Current Time: Fri Dec 09 13:42:09 CST 2016

Total time taken to generate the page: 0.05399 seconds