Saturday, May 22, 2010

Why is Oracle throwing a fit with this PL/SQL program?

create or replace procedure complaint_details(rental_no_in IN number) IS





cursor complaint_cursor is


select rental_date


from rental


where rental.rental_no = rental_no_in;


cursor_row complaint_cursor%rowtype;


v_tenant_name varchar2(30) := '';


c_count number(2) := 0;


v_tenant_name := tenant_function(rental_no_in);


c_count := complaints_qty(rental_no_in);





begin


for complaint_row in complaint_cursor


loop


dmbs_output.put_line(v_tenant_name||' '||complaint_row.rental_date||


' '||c_count);


end loop;


end;





Here is the error message that Oracle throws right at me.


ERROR at line 10: PLS-00103: Encountered the symbol "=" when expecting one of the following:





constant exception


table LONG_ double ref


char time timestamp interval date binary national character


nchar


The symbol "" was substituted for "=" to continue.


1. create or replace procedure complaint_details(rental_no_in IN number) IS


2.


3. cursor complaint_cursor is

Why is Oracle throwing a fit with this PL/SQL program?
create or replace procedure complaint_details(rental_no_in IN number) IS





cursor complaint_cursor is


select rental_date


from rental


where rental.rental_no = rental_no_in;





cursor_row complaint_cursor%rowtype;


v_tenant_name varchar2(30) := '';


c_count number(2) := 0;


v_tenant_name varchar2(50) := tenant_function(rental_no_in);


c_count varchar2(50) := complaints_qty(rental_no_in);


begin


for cursor_row in complaint_cursor loop --%26gt; look this line


dmbs_output.put_line(v_tenant_... '||complaint_row.rental_date||' '||c_count);


end loop;


end;





The errors





When you create a variable, must identify datatype





v_tenant_name := tenant_function(rental_no_in); --%26gt; is wrong





v_tenant_name varchar2(50) := tenant_function(rental_no_in); --%26gt; is ok





you dont need to create a variable





cursor_row complaint_cursor%rowtype;





Is automatic when user "for loop"
Reply:Great Question with all the right details. Your problem is with these two lines (if you fix only the first, it will give you the same error for line 11) :


v_tenant_name := tenant_function(rental_no_in);


c_count := complaints_qty(rental_no_in);





This is illegal. The error message is telling you what you need to do - declare these variables correctly, e.g.


v_tenant_name varchar2(100); c_count number(3);





You may then assign values to these variables in the body of your procedure by calling the functions either with values or variables (that have been given a value), e.g.


...


begin


....


v_tenant_name := tenant_function(rental_no_in);


c_count := complaints_qty(rental_no_in);


for complaint_row in complaint_cursor


loop


....


end;


/


No comments:

Post a Comment