Home » SQL & PL/SQL » SQL & PL/SQL » comparision
comparision [message #190369] Wed, 30 August 2006 06:56 Go to next message
nshanmuga
Messages: 1
Registered: August 2006
Junior Member
Hi,
I am New to this forum. I have a problem.

Cursor1 cursor2

--------- -------

1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10


I want to loop through first cursor and second cursor and compare the values.

cursor1 first record should loop though 2....10 in cursor2
cursor1 second record should loop though 3....10 in cursor2
cursor1 third record should loop though 4....10 in cursor2 and so on.

I have showed only the primary column in cursors but i have more columns which will be compared inside the loop.. Is there any better to achieve this.

right now what I am doing is before opening the second cursor for each record in first cursor I used a where to make sure the cursor2 value is greater than the cursor1 passed value.

thanks for all your help and effort.


Re: comparision [message #190388 is a reply to message #190369] Wed, 30 August 2006 07:57 Go to previous message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
Here's a single query that'll get you the data you describe.

create table tab_cursor_1 (col_1  number, col_2  varchar2(30));

create table tab_cursor_2 (col_1  number, col_2  varchar2(30));

insert into tab_cursor_1 (select lvl, 'Tab 1 Row '||lvl from (select level lvl from dual connect by level <= 10));

insert into tab_cursor_2 (select lvl, 'Tab 2 Row '||lvl from (select level lvl from dual connect by level <= 10));

commit;

select t1.col_1,t1.col_2,t2.col_1,t2.col_2
from   tab_cursor_1 t1, tab_cursor_2 t2
where  t2.col_1 >= t1.col_1
order by t1.col_1,t2.col_1;
Previous Topic: Cannot connect SYS thru SQL*PLUS only
Next Topic: table function in anather function
Goto Forum:
  


Current Time: Sat Dec 03 16:24:56 CST 2016

Total time taken to generate the page: 0.08212 seconds