Creating simple function
Objective:
  • Creating and Calling PL/SQL function Oracle way
  • using SQL Developer and SQL * Plus
In contrast to PostgreSQL , oracle creates and calls a function bit different way
 
In Oracle:  CTOF function was created under HR schema/user

code used:

/* compiled stored function */
create or replace
FUNCTION CTOF(i IN NUMBER)
RETURN NUMBER IS
t1 number(4,2);
BEGIN
dbms_output.put_line('Internal display');
dbms_output.put_line((i * 9/5) + 32);
t1:=((i*9/5)+32);
RETURN t1;
END ;
 

/* calling the stored function with parameter */
DECLARE
C NUMBER(4,2):=0;
BEGIN
C :=CTOF(29.25);
dbms_output.put_line('CTOF returned : '|| C);
END;
 

 

Compile (CTRL + F8) the function "CTOF";

Now call this function with this script, using another sql worksheeet

The query script using "SQLPlus"