PL/SQL: is there an instruction to completely stop the script execution?

后端 未结 4 1032
孤独总比滥情好
孤独总比滥情好 2021-02-13 16:23

I\'m trying to do some checkings on a DB schema at the beginning of a PL/SQL script.

If the checkings give unsuccessful results, I want to stop the script, to prevent th

4条回答
  •  不要未来只要你来
    2021-02-13 17:17

    If you don't want to raise an exception, you could try something like (untested):

    declare
      SOME_COUNT INTEGER;
    begin
      SELECT COUNT(*) INTO SOME_COUNT FROM SOME_TABLE WHERE ;
      IF (SOME_COUNT > 0) THEN
        DBMS_OUTPUT.PUT_LINE('Test failed, I don''want the rest of the script'
          || ' to be executed.');
    
        goto end_proc;
      END IF;
    
      -- A bunch of great code here
    
      <>
      null;  -- this could be a commit or other lines of code
    end;
    

    Some people hate any GOTO statements as they can lead to spaghetti code if abused, but in simple situations like this (again, assuming you don't want to raise an exception) they work well imo.

提交回复
热议问题