Hi,
In PL/SQL (Oracle 9i) I need to iterate over a discontinuous range of patient-ID's (numbers).
I need something like
WHILE variable IN (SELECT DISTINCT ....)
LOOP...
However Oracle does not allow using a subquery in this way.
I know in version 11 there is the CONTINUE construct but we do not run 11...
Does anyone have suggestions on how to do this in an other way?
thanks,
Willem
7 2193
Do you mean patient_id can be 1,3,5,7,8,10,11 and so on and not continuous??
Do you mean patient_id can be 1,3,5,7,8,10,11 and so on and not continuous??
Yes, indeed, that's it.
Willem
Yes, indeed, that's it.
Willem
Try this: -
-
SQL> SET SEVRVEROUTPUT ON
-
-
SQL>declare
-
cursor C1 is SELECT patient_id FROM table_name;
-
BEGIN
-
FOR I IN C1 LOOP
-
DBMS_OUTPUT.PUT_LINE(I.patient_id);
-
END LOOP;
-
END;
-
/
-
-
Thanks. I tried the cursor loop before, but I could not get it to work.
The code below does exactly what I want... as long as there is a continuous patient range (Current_pat). As soon as there is a gap, processing stops and I get the "no data found" message.
Maybe this is getting too specific to be discussed here.. in which case I humbly apologize.
Thanks again,
Willem
The rest is... -
-
declare
-
TYPE rec_data IS RECORD
-
(as11 number, as12 number, as13 number, as14 number,
-
as21 number, as22 number, as23 number, as24 number,
-
as31 number, as32 number, as33 number, as34 number
-
);
-
gegs rec_data;
-
First_Pat number;
-
Last_Pat number;
-
Current_Pat number;
-
teller number;
-
-
begin
-
select min(seq_med_diagnose) into First_Pat from med_diagnose_as;
-
select max(seq_med_diagnose) into Last_Pat from med_diagnose_as;
-
-
Current_pat:= First_Pat;
-
-
while Current_pat between First_Pat and Last_Pat
-
loop
-
-
select * into gegs
-
from (select *
-
from (select nvl(seq_alg_dsm_iv , 99999) "as11"
-
, nvl(lead(seq_alg_dsm_iv,1) over (order by seq_MED_diagnose_as), 99999) "as12"
-
, nvl(lead(seq_alg_dsm_iv,2) over (order by seq_MED_diagnose_as), 99999) "as13"
-
, nvl(lead(seq_alg_dsm_iv,3) over (order by seq_MED_diagnose_as), 99999) "as14"
-
from med_diagnose_as
-
where seq_med_diagnose = Current_Pat
-
and hc_as = 1
-
and rownum between 1 and 4
-
)
-
where rownum=1
-
)
-
, (select *
-
from (select nvl(seq_alg_dsm_iv , 99999) "as21"
-
, nvl(lead(seq_alg_dsm_iv,1) over (order by seq_MED_diagnose_as), 99999) "as22"
-
, nvl(lead(seq_alg_dsm_iv,2) over (order by seq_MED_diagnose_as), 99999) "as23"
-
, nvl(lead(seq_alg_dsm_iv,3) over (order by seq_MED_diagnose_as), 99999) "as24"
-
from med_diagnose_as
-
where seq_med_diagnose = Current_Pat
-
and hc_as = 2
-
and rownum between 1 and 4
-
)
-
where rownum=1
-
)
-
, (select *
-
from (select nvl(seq_alg_dsm_iv , 99999) "as31"
-
, nvl(lead(seq_alg_dsm_iv,1) over (order by seq_MED_diagnose_as), 99999) "as32"
-
, nvl(lead(seq_alg_dsm_iv,2) over (order by seq_MED_diagnose_as), 99999) "as33"
-
, nvl(lead(seq_alg_dsm_iv,3) over (order by seq_MED_diagnose_as), 99999) "as34"
-
from med_diagnose_as
-
where seq_med_diagnose = Current_Pat
-
and hc_as = 3
-
and rownum between 1 and 4
-
)
-
where rownum=1
-
)
-
;
-
-
Current_pat:= Current_pat+1;
-
-
dbms_output.put_line(Current_Pat || ',' || gegs.as11 || ',' || gegs.as11 || ',' || gegs.as12 || ',' || gegs.as13 || ',' || gegs.as14 || ',' ||
-
gegs.as21 || ',' || gegs.as22 || ',' || gegs.as23 || ',' || gegs.as24 || ','||
-
gegs.as31 || ',' || gegs.as32 || ',' || gegs.as33 || ',' || gegs.as34 );
-
end loop;
-
end;
-
Ofcourse that will happen becuase you are taking MIN and MAX values and if any value between MIN and MAX does not exist then it will result in NO DATA FOUND. You need to reimplement your code using cursor that way I showed you in my previous post. Try and post back what error you get using Cursor
Hi,
Sorry for not responding until now. I have been ill for a while.
The problem has been solved by our application provider in the latest release. I haven't got the time to work on this problem any longer.
Thank you for your help,
Regards,
Willem
Hi,
Sorry for not responding until now. I have been ill for a while.
The problem has been solved by our application provider in the latest release. I haven't got the time to work on this problem any longer.
Thank you for your help,
Regards,
Willem
Thats good that problem is resolved. ANyways, do post back when ever you have any further issues.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: drife |
last post by:
Hello,
Making the transition from Perl to Python, and have a
question about constructing a loop that uses an iterator
of type float. How does one do this in Python?
In Perl this construct...
|
by: Mike |
last post by:
Hello,
This game will not loop. It compiles, builds, and executes fine, but
the game will not loop around no matter what I do. What is wrong with
the code? What do I have to add to make it loop...
|
by: Joseph Garvin |
last post by:
When I first came to Python I did a lot of C style loops like this:
for i in range(len(myarray)):
print myarray
Obviously the more pythonic way is:
for i in my array:
print i
|
by: Ken |
last post by:
Hi All -
I have a filtered GridView. This GridView has a check box in the first
column. This check box is used to identify specific rows for delete
operations.
On the button click event I...
|
by: John Salerno |
last post by:
Here's an exercise I was doing to guess a number from 1-100. Just for
fun (ha ha) I decided to add some error checking too, and now when I run
it, the DOS prompt flashes real quick and disappears....
|
by: Tommy Grav |
last post by:
I have a list:
a =
I want to loop over a and then
loop over the elements in a
that is to the right of the current
element of the first loop
In C this would be equivalent to:
|
by: NetworkElf |
last post by:
Hi all,
Does anyone have some code that shows an example of how to loop through a
range of IP addresses? I'm using text boxes to get a start and end value for
the range. I was thinking about...
|
by: assgar |
last post by:
Hi
I am having problem with my loping.
I don't know if I have chosen the correct approach.
GOAL:
I need to insert into a table event types for a specific date range.
The calendar the event...
|
by: richie9648 |
last post by:
Hi All
I have created a macro which turns reports done by users into a format that is needed by me. The good this is that all the reports are in the same format.
However my question is around...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |