473,326 Members | 2,255 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

fetching more than once in a loop

4
I am trying to find top n salaries from given table . My code returns top n salaries but if there are same value of salaries for more than 1 emp than program just picks one of them, I want to list all of them who has max salaries
How can I fetch twice inside a loop with the same cursor .
I am trying to fetch a cursor who finds max sal emp names , then I need to fetch it again to find all other emps who has same max sal .
thanks
cursor selects name ,sal from table who ahs max sal (passed param)

select max(sal) into v_sal from emp ;
for i in 1..N Loop
open emp_cur(v_sal) ;
Fetch emp_cur into v_name ,v_sal ;
select name , sal into v_name,v_sal from emp where sal = v_sal and rownum = 1 ;
DBMS_OUTPUT.PUT_LINE(v_name || ' ' || v_sal);
close emp_cur ;
select max(sal) into v_sal from emp where sal < v_sal ;
end loop ;
Jul 8 '07 #1
1 1351
r035198x
13,262 8TB
I am trying to find top n salaries from given table . My code returns top n salaries but if there are same value of salaries for more than 1 emp than program just picks one of them, I want to list all of them who has max salaries
How can I fetch twice inside a loop with the same cursor .
I am trying to fetch a cursor who finds max sal emp names , then I need to fetch it again to find all other emps who has same max sal .
thanks
cursor selects name ,sal from table who ahs max sal (passed param)

select max(sal) into v_sal from emp ;
for i in 1..N Loop
open emp_cur(v_sal) ;
Fetch emp_cur into v_name ,v_sal ;
select name , sal into v_name,v_sal from emp where sal = v_sal and rownum = 1 ;
DBMS_OUTPUT.PUT_LINE(v_name || ' ' || v_sal);
close emp_cur ;
select max(sal) into v_sal from emp where sal < v_sal ;
end loop ;
Is this MySQL or PL/SQL ?
Jul 10 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Arsen V. | last post by:
Hello, Does anyone know if an object or how to create one, that will allow me to fetch up to 10 URLs (containing XML-feed data) in an extremelly fast server side fashion? If the request is...
1
by: deepdata | last post by:
Hi, I am trying to fetch data from db2 (express version) database by calling stored procedure. I have tried to use both cursor and for loop but still i am getting error. --======Start...
7
by: multicherry | last post by:
Hi, Having searched for a way to fetch a window object by name, all I came across were answers along the line of... "All you have to do is say windowObj = window.open("blah", "name");" which...
1
by: MD | last post by:
When displaying the metadata for our system, takes about 5 seconds to display 10 results to the browser. The whole process works like this. 1. Call the servlet from the javascript with Dom var...
22
by: Sandman | last post by:
So, I have this content management system I've developed myself. The system has a solid community part where members can register and then participate in forums, write weblogs and a ton of other...
0
by: Day | last post by:
Hi! I'm writing in C# under .NET 2.0, WINXP SP 2 My application runs under a different set of permissions than the ones I logged in with (once I log in I use Process.Start and provide the...
5
by: Bhavesh | last post by:
Hello genious people, I m trying to insert a LARGE text from Multiline Textbox into my table of sqlserver2000. I m using vs-2005. Please note that I dont want to store blob data From FILE...
1
by: Bhavesh | last post by:
Hi Bruce, Thanks For Reply. U were right, Needed to pass string , but also need to pass size of Data( instead of 16, passed actual length of data). So that worked for me & didn't get any...
0
debasisdas
by: debasisdas | last post by:
We can fetch from a cursor into one or more collections: DECLARE TYPE NameList IS TABLE OF employees.last_name%TYPE; TYPE SalList IS TABLE OF employees.salary%TYPE; CURSOR c1 IS SELECT...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.