Problem In Accessing The value of Outer Cursor in inner Cursor ? [message #602703] |
Sat, 07 December 2013 06:03 |
|
jalal-rasooly
Messages: 11 Registered: November 2013
|
Junior Member |
|
|
i have a procedure that have tow cursor and they are nested.the outer cursor move on a relation_table and the inner cursor move on a pk_table ((this table have all the pk)).in this procedure the first cursor check every rows of relation_table and get the value of a specific field ((this value is one of the pk_table column)).the second cursor for every rows of first cursor loop on a pk_table. in the second cursor i want to get a field from a column that that its name is in the first cursor, some thing like this :inner_cursor.outer_cursor.field which the return a column name that is i want to use in the inner cursor.well i cant do this even in this shape: inner_cursor.(outer_cursor.field); . does any body know how to handle this?
my tables:
CREATE TABLE BIG_TABLE
(
ID VARCHAR2(50),
Pk_A VARCHAR2(50),
PK_B VARCHAR2(50),
PK_C VARCHAR2(50),
PK_D VARCHAR2(50)
);
this table column is the pk of my tables(A,B,C,D)
CREATE TABLE RELATION_TABLE
(
ID VARCHAR2(50),
SOURCE_TABLE VARCHAR2(50),
SOURCE_PK VARCHAR2(50),
SOURCE_FK VARCHAR2(50),
DESTINATION_TABLE VARCHAR2(50),
DESTINATION_PK VARCHAR2(50)
);
this table store the relations between tables.
and my procedure (ofcource this is part of my procedure):
CREATE OR REPLACE PROCEDURE TEST1
AS
CURSOR loop_relation IS
SELECT * FROM RELATION_table;
relation_rec loop_relation%rowtype;
CURSOR loop_pk_TABLE IS
SELECT * FROM pk_TABLE;
pk_TABLE_rec loop_pk_TABLE%rowtype;
BEGIN
FOR RELATION_REC IN LOOP_RELATION
LOOP
FOR pk_TABLE_rec in loop_pk_TABLE
LOOP
IF (pk_TABLE_REC.RELATION_REC.DESTINATION_PK IS NULL) THEN --MY PROBLEM,I CANT USE THREE DOTS
UPDATE PK_TABLE
SET PK_TABLE.RELATION_REC.DESTINATION_PK = 'NOT IMPORTANT' --OOPS, ANOTHER THREE DOTS
WHERE PK_TABLE_REC.ID = PK_TABLE.ID;
END IF;
END LOOP;
END LOOP;
END TEST1;
/
|
|
|
|
|
Re: Problem In Accessing The value of Outer Cursor in inner Cursor ? [message #602710 is a reply to message #602703] |
Sat, 07 December 2013 09:08 |
martijn
Messages: 286 Registered: December 2006 Location: Netherlands
|
Senior Member |
|
|
I have the feeling that you are from the java world (JPA or so). Maybe I'm completely mistaken so don't be offended.
If that's the case, you should forget all OO stuff, and think relational, you're in the database world.
Can you give a small example of the input and the desired output?
I believe that the words of pablolee hold true, this probably can be done with one or two sql-statements.
|
|
|
|
Re: Problem In Accessing The value of Outer Cursor in inner Cursor ? [message #602712 is a reply to message #602705] |
Sat, 07 December 2013 09:54 |
Solomon Yakobson
Messages: 3273 Registered: January 2010 Location: Connecticut, USA
|
Senior Member |
|
|
And what inner_cursor.outer_cursor.field is supposed to mean? There is no correlation between two cursors. Your inner loop simply fetches same data from pk_TABLE over and over. And what is that pk_TABLE? There is only BIG_TABLE & RELATION_table in your post. You need to describe logic you need to implement in words.
SY.
P.S. FOR CURSOR loop variable scope is local to loop, therefore variable pk_TABLE_rec declared as pk_TABLE_rec loop_pk_TABLE%rowtype; and variable pk_TABLE_rec declared by FOR pk_TABLE_rec in loop_pk_TABLE are two different variables.
SY.
|
|
|
|
|
Re: Problem In Accessing The value of Outer Cursor in inner Cursor ? [message #602727 is a reply to message #602714] |
Sun, 08 December 2013 00:44 |
|
jalal-rasooly
Messages: 11 Registered: November 2013
|
Junior Member |
|
|
it will be like this:
in relation table:(id, source_table, source_pk, source_fk, destination_table, destination_pk) = (id, EMP, EMPNO, DEPTNO, SCOTT.DEPT, DEPTNO)
in pk_table we have 'EMPNO' and 'DEPTNO' as column. if we have a row in 'SCOTT.DEPT' which iT'S PK 'DEPTNO' is '9', and we have a row in 'EMP' which it's pk is '50' and it's fk is '9', so we have a row in pk_table that EMPNO value is '50' and DEPTNO value is '9'.
i think it's not important to understand the system. what i want to know is how to use tow dots(.). like (cursor1.cursor2.cursor2_field1;), and (cursor2_field1) will return a field of cursor1. i don't know how to explain this to stupid oracle!!
|
|
|
Re: Problem In Accessing The value of Outer Cursor in inner Cursor ? [message #602745 is a reply to message #602727] |
Sun, 08 December 2013 06:00 |
pablolee
Messages: 2882 Registered: May 2007 Location: Scotland
|
Senior Member |
|
|
You're right, oracle is stupid, it will only do exactly as it is told. If it's not doing what you want it to do, than that is your fault, not Oracle's. Based on your descriptions so far (which have been poorly structured and very difficult to understand), you are going about things the wrong way. Once again, it looks very much like you should be using pure sql and not pl/sql. You will find that on these forums, few people will help you implement bad design, which means that we have to be convinced that what you're doing is NOT bad design. You have failed to do this so far.
|
|
|
|
Re: Problem In Accessing The value of Outer Cursor in inner Cursor ? [message #602753 is a reply to message #602727] |
Sun, 08 December 2013 08:00 |
Its_me_ved
Messages: 979 Registered: October 2009 Location: India
|
Senior Member |
|
|
Quote:
it will be like this:
in relation table:(id, source_table, source_pk, source_fk, destination_table, destination_pk) = (id, EMP, EMPNO, DEPTNO, SCOTT.DEPT, DEPTNO)
in pk_table we have 'EMPNO' and 'DEPTNO' as column. if we have a row in 'SCOTT.DEPT' which iT'S PK 'DEPTNO' is '9', and we have a row in 'EMP' which it's pk is '50' and it's fk is '9', so we have a row in pk_table that EMPNO value is '50' and DEPTNO value is '9'.
i think it's not important to understand the system
Before jumping into a problem, we should always try to understand/analyze the problem well.
For me, you have not understand your requirement well.
Or, if you have understand the requirement well, i should ask you what your objective is.The whole approach appears to be flawed to me.
Regards
Ved
|
|
|
|
|
|
|
Re: Problem In Accessing The value of Outer Cursor in inner Cursor ? [message #602891 is a reply to message #602873] |
Tue, 10 December 2013 02:45 |
pablolee
Messages: 2882 Registered: May 2007 Location: Scotland
|
Senior Member |
|
|
jalal-rasooly wrote on Tue, 10 December 2013 07:15i think you didn't get my problem correctly on that we agree.
Quote:(actually my fault,can't express my problem explicit,probably because i'm novice) yes it is your fault, not because you are a novice, but because you have failed to provide a valid test case and explanation of what you're trying to do.
Quote:i actually explained my problem to some experienced oracle man in person and they confirmed my problem. Based on what you've posted here, I'm going to disagree with your 'experienced oracle man'
Quote:i really cant do it with pure sql, i really tried after your advise but it's impossible Bull. If you tried, then post your attempts. You haven't bothered to try to explain the actual problem properly, you have fixed a 'solution' in your head and decided that that is the way that you need to go and anyone who disagrees is wrong.
Quote:please do not continue this topic, That is your choice to continue or not.
Quote:i have no more time to think for alternative solution,i decided to continue on my solution
anyway, thank you for your help
That is your choice, it's crappy choices like that that keep people like me in contracts.
|
|
|
|
Re: Problem In Accessing The value of Outer Cursor in inner Cursor ? [message #602922 is a reply to message #602904] |
Tue, 10 December 2013 06:52 |
pablolee
Messages: 2882 Registered: May 2007 Location: Scotland
|
Senior Member |
|
|
jalal-rasooly wrote on Tue, 10 December 2013 11:22i don't understand why are you angry((maybe because i found a solution and you didn't))!! we have no enmity I'm not angry, I simply don't care enough to be angry. However, since enmity is simply a state of active opposition, yes, there is enmity between us.
Quote:By The Way,base on a time you spend on this forum to insult to others, I have not insulted you, I have pointed out that crappy decisions keep me busy, Quote:i think i have more contracts than you I can guarantee that this is not the case.
|
|
|
|
|
|
Re: Problem In Accessing The value of Outer Cursor in inner Cursor ? [message #603183 is a reply to message #603157] |
Thu, 12 December 2013 01:54 |
|
jalal-rasooly
Messages: 11 Registered: November 2013
|
Junior Member |
|
|
actually this procedure will not run consecutively. it will make the PK_TABLE once and after that for every change in tables it will update the PK_TABLE.
so pure performance does not make the big problem.
THE MOST IMPORTANT REASON i choosed this way is because honestly it's the only way i found AND also i have close deadline.
i will consider an optimized solution for later changes.
thank you
|
|
|