Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Ideas why function call not working

Frank LehmannAug 30 2024

Hi helpers,

i have a function which will get a token. This created token is used to get an api call to get data.
This function is within a package and i have created the values token and expired as package variables.

So the package looks like :

create or replace package token as
token clob;
expire date;
function return_token return clob;
end;

The package body looks like this:
create or replace package body token as
function return_token return clob is
begin

   if token is null or expiredate ≤ sysdate then  
        get\_token with another API call GET   
        returned xml data and this will get token and expire time.  
         
   end if;

   return token;  

end;
end; --body

This function will be used for a procedure to start an api call like this

procedure get_apidata(p_token in clob) is
begin
do_something with token;
end;

The call for this procedure is

get_apidata(token.return_token);

Till yet everything is OK and working.

But now i have 2 (or more) clients, which need different tokens, because they are mandatory.

So i want to change my function to get the client id and save the token for this client.

My new function return_token looks like this:

The package variables are not needed i think and deleted them.

function return_token(pclientid in number) return clob is

local_token clob;
local_expiredate date;
begin
select token,expiredate
into local_token,local_expiredate
from tb_client
where clientid=p_clientid;

 if local\_token is null or local\_expiredate ≤ sysdate then  
      get\_token with another API call GET   
      returned xml data and this will get token and expire time.  
      values are stored now in local\_token and local\_expiredate;  
       
      update client  
      set token = local\_token,  
      expiredate = local\_expiredate  
      where clientid=p\_clientid;  
 end if;

 return local\_token;  

end;

The call to the api_data looks like this:
get_apidata(token.return_token(p_clientid => <clientid>));

But this is not working.
I am getting a timeout while returning the api_data.
I am using the standard utl_http package to start requests.

Any ideas, while the new function is failing ?

Comments
Post Details
Added on Aug 30 2024
7 comments
154 views