Job Seekers   Employers
dbapool: Authors | Submissions | Contact Us
   Forgot password? | Sign up
  Home   Discussion Forum   Articles   Interview Questions   FAQs   Scripts   Rewards   Analyzer   White Papers   Blog   Certification   Downloads   Tools
 

Topic: SQL*Plus and PL/SQL >> Need help with Cursor

Disclaimer: The purpose of all dbapool forums including OCP and Other Oracle Certification forums is to help each other with specific issues but not to share dump and copyrighted exam content, materials or intellectual property. You may review the entire Oracle Certification Program Candidate Agreement online Here.



  


 Title: Need help with Cursor
 Pooja  Posted: Apr 13, 2005 08:25:35 AM

 Total Post: 3
 Joined: Apr, 2005






 Hello everyone,

I need some help with the SQL query posted below:

SET NOCOUNT ON


DECLARE cursor resolverate is
select hcfadrgcode, insplancode, sum(f.TOTALPAYMENTS)/sum(f.totalactualcharges) rr
from encounter e, encounterfinancialrecord f
where e.encounterid = f.encounterid
and e.encountertypecode = 'I'
and to_char(dischargetimestamp, 'YYYY-MM') >= '2004-01'
and to_char(dischargetimestamp, 'YYYY-MM') <= '2005-02'
and e.totalactualcharges > 0
and (arbal = 0 or bdind = 'Y')
group by hcfadrgcode, insplancode;

Open resolverate;

BEGIN

FOR test in resolverate
loop
select e.encounterid, (f.totalactualcharges * test.rr)
from encounter e, encounterfinancialrecord f
where e.encounterid = f.encounterid
and e.encountertypecode = 'I'
and e.hcfadrgcode = test.hcfadrgcode
and e.insplancode = test.insplancode;


end loop;

END;

/

When I run this code, I get several errors. And I don't even think if the syntax are correct or not. In my first cursor, I'm trying to get a rate based on hcfadrgcode and insplancode. And then I would like to assign that rate in my loop to all accounts that has same hcfadrgcode and insplancode. Please let me know if you need more information.

Thanks,

 Pooja
Posted: Apr 13, 2005 08:26:31 AM  

 Total Post: 3
 Joined: Apr, 2005






 
And I'm using SQL* PLUS Oracle application

 Vigyan
Posted: Apr 13, 2005 09:52:25 AM  

 Total Post: 386
 Joined: May, 2001






 
You can not use "select col1, col2 from" in a cursor program.

Declare variables before "BEGIN" and use "INTO" clause to select the data.

e.g. "select col1 into var_col1 from"

Hope it helps.

Vigyan


 Pooja
Posted: Apr 13, 2005 10:19:25 AM  

 Total Post: 3
 Joined: Apr, 2005






 
How would I do that using my code. I have never done cursor before and I'm bit confused about declaring variable before begin statement. Please guide me through my code.

Thank you so much

 Vigyan
Posted: Apr 18, 2005 02:10:28 PM  

 Total Post: 386
 Joined: May, 2001






 
Try this.


set serveroutput on
DECLARE
cursor resolverate is
select hcfadrgcode, insplancode, sum(f.TOTALPAYMENTS)/sum(f.totalactualcharges) rr
from encounter e, encounterfinancialrecord f
where e.encounterid = f.encounterid
and e.encountertypecode = 'I'
and to_char(dischargetimestamp, 'YYYY-MM') >= '2004-01'
and to_char(dischargetimestamp, 'YYYY-MM') <= '2005-02'
and e.totalactualcharges > 0
and (arbal = 0 or bdind = 'Y')
group by hcfadrgcode, insplancode;

var1 number;
var2 number;

BEGIN

FOR test in resolverate
loop
select e.encounterid, (f.totalactualcharges * test.rr) into var1, var2
from encounter e, encounterfinancialrecord f
where e.encounterid = f.encounterid
and e.encountertypecode = 'I'
and e.hcfadrgcode = test.hcfadrgcode
and e.insplancode = test.insplancode;

dbms_output.put_line(var1||' '||var2);

end loop;

END;

/


Make sure following query works on sqlplus if you get error.

select hcfadrgcode, insplancode, sum(f.TOTALPAYMENTS)/sum(f.totalactualcharges) rr
from encounter e, encounterfinancialrecord f
where e.encounterid = f.encounterid
and e.encountertypecode = 'I'
and to_char(dischargetimestamp, 'YYYY-MM') >= '2004-01'
and to_char(dischargetimestamp, 'YYYY-MM') <= '2005-02'
and e.totalactualcharges > 0
and (arbal = 0 or bdind = 'Y')
group by hcfadrgcode, insplancode;


Hope it helps.

Vigyan

 Time Zone: EDT

  




Forum Rules & Description


Who Can Read The Forum? Any registered user or guest
Who Can Post New Topics? Any registered user
Who Can Post Replies? Any registered user




 








Get FREE Magazines

Top 10 Forum User

  Murtuja Khokhar857
  Mohammed Taj746
  positive fanatic483
  Jayanta Sur479
  Vigyan Kaushik386
  Gopu Gopi333
  Gitesh Trivedi322
  Vinoth Kumar264
  neeraj sharma258
  Ramesh Jois246






oracle Mag



  About Us Advertise Terms of Use Privacy Newsletters Contact Us    

Home   Discussion Forum   FAQs  Articles  Jobs   Newsletters  Directory  Downloads 

Our Premium Sponsor
Confio Software