I define a function outside a package, tried to call this function, failed.
how to fix it ? thanks
create or replace
package body test_erp AS
procedure init_data is
begin
logMessage('procedure init_data');
end init_data;
end test_erp;
/
show error
error is
PLS-00221: 'LOGMESSAGE' is not a procedure or is undefined
As the error suggests
logmessageis not a procedure. It’s a function. As functions return something you need to assign this to a variable. You know thatlogmessagereturns a number so you need to declare a variable to put this return value into.However, it looks like
logmessageshould in fact be a procedure. I assume you’re executing DML statements (update/insert) in this. A function call be used in aselectstatement unless this is the case, which means that there’s always the possibility of an error occurring. Iflogmessagewere a procedure you can declare anoutparameter to tell the calling procedure whether everything worked or not; something like the following:You can then call it as follows:
If
logmessageisn’t going to be used outside the packagetest_erpI would put it inside the package; it keeps the namespace cleaner and avoids it getting used mistakenly be another package / call etc.