SashaBuilder3
Programmer
Hi everybody,
My cursor takes data from a many-column table and I need to process the fields in similar ways.
Say, I have a table t1 with fields f0,f1,f2,f3,f4. Values of fields f1 and f3 are set, of fields f2,f4 are not. Field f0 is the primary key.
Here is a snippet from the simplified procedure which sets values in even fields (f2 and f4) depending on corresponding values in odd columns.
PROCEDURE My_proc AS
CURSOR crs_t1 IS
SELECT * from t1;
row_t1 crs_t1%ROWTYPE;
some_value NUMBER;
BEGIN
...
FETCH crs_t1 into row_t1;
some_value=some_function(row_t1.f1);
UPDATE t1 set f2=some_value
WHERE f0=row_t1.f0;
some_value=some_function(row_t1.f3);
UPDATE t1 set f4=some_value
WHERE f0=row_t1.f0;
...
END;
As you see I repeated the UPDATE block twice. It's OK in this example but my real table has about a hundred columns and I am wondering whether it's possible to place the block in a loop. So my question is if it's possible somehow to refer to the fields by an index, something like: row_t1.(1) - and not by explicit names. I know that there is such a thing in MS-Access when working with recordsets, but what about Oracle?
Can anyone share an idea how to solve this?
Thanks,
Alexandre
My cursor takes data from a many-column table and I need to process the fields in similar ways.
Say, I have a table t1 with fields f0,f1,f2,f3,f4. Values of fields f1 and f3 are set, of fields f2,f4 are not. Field f0 is the primary key.
Here is a snippet from the simplified procedure which sets values in even fields (f2 and f4) depending on corresponding values in odd columns.
PROCEDURE My_proc AS
CURSOR crs_t1 IS
SELECT * from t1;
row_t1 crs_t1%ROWTYPE;
some_value NUMBER;
BEGIN
...
FETCH crs_t1 into row_t1;
some_value=some_function(row_t1.f1);
UPDATE t1 set f2=some_value
WHERE f0=row_t1.f0;
some_value=some_function(row_t1.f3);
UPDATE t1 set f4=some_value
WHERE f0=row_t1.f0;
...
END;
As you see I repeated the UPDATE block twice. It's OK in this example but my real table has about a hundred columns and I am wondering whether it's possible to place the block in a loop. So my question is if it's possible somehow to refer to the fields by an index, something like: row_t1.(1) - and not by explicit names. I know that there is such a thing in MS-Access when working with recordsets, but what about Oracle?
Can anyone share an idea how to solve this?
Thanks,
Alexandre