I get the following error, even though I have checked the code carefully. I don’t know what I’m missing.
LINE/COL ERROR
31/1 PLS-00103: Encountered the symbol “END” when expecting one of the
following:
CODE:
CREATE OR REPLACE PROCEDURE sp_ssjm_newworkorder
( workorderno IN NUMBER,
company IN CHAR,
attention IN CHAR,
datedue IN DATE,
loggedby IN CHAR
)
AS id NUMBER;
today DATE:=SYSDATE;
BEGIN
SELECT client_id --grab client_id
INTO id
FROM ssjm_client
WHERE ssjm_client.name=company;
IF id IS NULL THEN --check if client exists by checking if client_id is there
dbms_output.put_line('Please create client first');
GOTO the_end;
ELSE
INSERT INTO ssjm_workorder VALUES(workorderno,workorderno,company,loggedby,attention,'Received',today,datedue,id);
END IF;
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20999,'An error occured in' ||
SQLCODE || '-ERROR-' || SQLERRM);
<<the_end>>
END sp_ssjm_newworkorder;
There are several spots in your code needed attention:
<<the_end>>should be placed before theEXCEPTIONsection.NULLoperator should be used.To that end your code should look like this:
By all means try to avoid unconditional branching. Using
GOTOoperator is very, very not good practice. It kills readability, code like that hard to debug. It will cause you and everybody who will look at that code after you a headache. Moreover if the queryreturns no rows the exception
NO_DATA_FOUNDwill be immediately raised and execution of the code halts. SoIF id IS NULL THENcondition will never be evaluated. You may rewrite your code by removing that condition and addingNO_DATA_FOUNDexception handler in theEXCEPTIONsection of your code. And of course as @Rob van Wijk correctly pointed out in the commentthere is no need of
todayvariable,SYSDATEcan be used directly in thevaluesclause of theinsertstatement, andWHEN OTHERScan be removed as well.