In PL/SQL, the code below will fail. It doesn’t allow the definition of size for the varchar2 parameter. Do you know why? How do I fix it?
create or replace function logMessage(msg varchar2(2000))
return number as
begin
null;
return 1;
end logMessage;
/
error message is
1/33 PLS-00103: Encountered the symbol “(” when expecting
one of the following::= . ) , @ % default character The symbol “:=” was substituted for
“(” to continue.
You fix it by removing the size constraint. It’s not needed:
I assume your function is slightly more complicated than this?
The full syntax for the
create functionstatement from the documentation is:There’s a lot of information around the specifics if you’re interested but you may find TECH on the Net more useful.
In answer to your first question of why I don’t know and can’t find an answer. But to quote APC:
Put simply, you should know at run-time how long something is going to be and be able, therefore, to deal with it. There are a few options you can consider though:
If you know what length you want message to be you can define a variable, the default value of which is a
substrof the parameter:Alternatively, you can check the length in the function itself: