Home » SQL & PL/SQL » SQL & PL/SQL » ORA-01722 when returning ROWTYPE in function (oracle Database 11g Enterprise Edition Release 11.1.0.6.0)
ORA-01722 when returning ROWTYPE in function [message #653618] Tue, 12 July 2016 13:48 Go to next message
rkhatiwala
Messages: 178
Registered: April 2007
Senior Member
Hello,

I have function as follows. I am getting ORA-01722 Invalid Number. It is returning only one row, when SELECT statement is run in TOAD.

FUNCTION get_state_rules_fun (p_state  IN  varchar2)
  RETURN state_sales_tax_rules%rowtype IS
  v_st_rules      state_sales_tax_rules%rowtype;
BEGIN
	
  select *
    into v_st_rules
    from state_sales_tax_rules
   where state = p_state;
   
   return(v_st_rules);
exception
  when others then
   message('get_state_rules_fn err ='||sqlerrm);
   raise;
END;
Re: ORA-01722 when returning ROWTYPE in function [message #653619 is a reply to message #653618] Tue, 12 July 2016 13:51 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
so few lines & so many problems

remove & eliminate the whole EXCEPTION handler.

show how the function is invoked.
Re: ORA-01722 when returning ROWTYPE in function [message #653622 is a reply to message #653618] Tue, 12 July 2016 14:00 Go to previous messageGo to next message
rkhatiwala
Messages: 178
Registered: April 2007
Senior Member
This is how it is called

  if not check_veh_elig_fun(:sales_tax_info.vehicle_id) then

Here is the function without EXCEPTION
FUNCTION get_state_rules_fun (p_state  IN  varchar2)
  RETURN state_sales_tax_rules%rowtype IS
  v_st_rules      state_sales_tax_rules%rowtype;
BEGIN
	
  select *
    into v_st_rules
    from state_sales_tax_rules
   where state = p_state;
   
   return(v_st_rules);

END;
Re: ORA-01722 when returning ROWTYPE in function [message #653623 is a reply to message #653622] Tue, 12 July 2016 14:03 Go to previous messageGo to next message
rkhatiwala
Messages: 178
Registered: April 2007
Senior Member
Here is the other function:

UNCTION check_veh_elig_fun 
        (p_vehicle_id  IN  vehicles.vehicle_id%type) RETURN boolean IS
  v_state      varchar2(2);
  v_payment_type vehicles.veh_payment_type%type;
  v_request_code vehicles.request_code%type;
  v_st_rules   state_sales_tax_rules%rowtype;
  v_sales_tax_status_code vehicles.sales_tax_status_code%type;
  v_bool       boolean := false;
--  v_dummy      varchar2(1);
BEGIN
  select state_reg_code, veh_payment_type, request_code, sales_tax_status_code
    into v_state, v_payment_type, v_request_code, v_sales_tax_status_code
    from vehicles rv
   where rv.vehicle_id = p_vehicle_id
     and upper(record_status_code) not in ('REJECTED', 'CANCELLED')
     and rv.check_date is not null;

  if v_sales_tax_status_code = 'CLARION' then     -- old data
    v_bool := false;
  else
     v_st_rules  := get_state_rules_fun(v_state);
  
.
.
.
.


Re: ORA-01722 when returning ROWTYPE in function [message #653624 is a reply to message #653622] Tue, 12 July 2016 14:04 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>if not check_veh_elig_fun(:sales_tax_info.vehicle_id) then
what does above have to do with below?
>FUNCTION get_state_rules_fun (p_state IN varchar2)
Re: ORA-01722 when returning ROWTYPE in function [message #653625 is a reply to message #653624] Tue, 12 July 2016 14:08 Go to previous messageGo to next message
rkhatiwala
Messages: 178
Registered: April 2007
Senior Member
get_state_rules_fun(v_state) is called in check_veh_elig_fun

so in procedure, check_vehicle_id_pro - check_veh_elig_fun is called:
if not check_veh_elig_fun(:sales_tax_info.vehicle_id) then

and in check_veh_elig_fun :
v_st_rules := get_state_rules_fun(v_state);
Re: ORA-01722 when returning ROWTYPE in function [message #653626 is a reply to message #653625] Tue, 12 July 2016 14:16 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
which line in which code throws the error?
Re: ORA-01722 when returning ROWTYPE in function [message #653627 is a reply to message #653626] Tue, 12 July 2016 14:18 Go to previous messageGo to next message
rkhatiwala
Messages: 178
Registered: April 2007
Senior Member
It is throwing error, ORA-01722 INVALID NUMBER, in following function:

FUNCTION get_state_rules_fun (p_state  IN  varchar2)
  RETURN state_sales_tax_rules%rowtype IS
  v_st_rules      state_sales_tax_rules%rowtype;
BEGIN
	
  select *
    into v_st_rules
    from state_sales_tax_rules
   where state = p_state;
   
   return(v_st_rules);
exception
  when others then
   message('get_state_rules_fn err ='||sqlerrm);
   raise;
END;
Re: ORA-01722 when returning ROWTYPE in function [message #653629 is a reply to message #653627] Tue, 12 July 2016 14:22 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
What is column state in table state_sales_tax_rules datatype?

SY.
Re: ORA-01722 when returning ROWTYPE in function [message #653630 is a reply to message #653629] Tue, 12 July 2016 14:28 Go to previous messageGo to next message
rkhatiwala
Messages: 178
Registered: April 2007
Senior Member
state is VARCHAR2(2), in the table, and wherever referred to in the variable
Re: ORA-01722 when returning ROWTYPE in function [message #653632 is a reply to message #653630] Tue, 12 July 2016 14:36 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
rkhatiwala wrote on Tue, 12 July 2016 12:28
state is VARCHAR2(2), in the table, and wherever referred to in the variable

contains at least 1 non-numeric value
Re: ORA-01722 when returning ROWTYPE in function [message #653637 is a reply to message #653630] Tue, 12 July 2016 20:04 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3273
Registered: January 2010
Location: Connecticut, USA
Senior Member
Then:

1. Remove exception clause altogether from your function
2. Show SQL*Plus snippet where you compile the function
3. Show SQL*Plus snippet where you call the function along with all errors.

SY.
Re: ORA-01722 when returning ROWTYPE in function [message #653718 is a reply to message #653637] Fri, 15 July 2016 13:04 Go to previous messageGo to next message
Bill B
Messages: 1971
Registered: December 2004
Senior Member
Using when others is just asking for problems. You will never see the actual line that errors. Comment out or remove the exception block and you will see exactly where the error is occurring
Re: ORA-01722 when returning ROWTYPE in function [message #653719 is a reply to message #653718] Fri, 15 July 2016 14:45 Go to previous message
Michel Cadot
Messages: 68644
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Yes, read WHEN OTHERS.

Previous Topic: Parent child count?
Next Topic: Unpivot Query Help to transpose the data
Goto Forum:
  


Current Time: Wed Apr 24 00:37:30 CDT 2024