Parsing PL/SQL code to check against syntax and semantic errors

后端 未结 4 844
鱼传尺愫
鱼传尺愫 2021-01-14 04:40

Please consider following scenario:

  • I have a Text-Area and a Button on UI.
  • User will enter a PL/SQL block in
4条回答
  •  耶瑟儿~
    2021-01-14 05:03

    It is difficult and you probably have to consider all kind of possiblities and make sure that the users do not wreck you database by making sure to grant very little rights etc. You got the point.

    This is not the full solution but it points you into the right direction.

    You could try to embed it into a CREATE or REPLACE PROCEDURE and fetch errors. Something like this:

    declare
      text_area varchar2(4000) := 'declare x number; begin xy := x + 1; end;';
    begin
      execute immediate 'create or replace procedure DUMMY#__ IS BEGIN null; begin '|| text_area ||' end; END;';
    exception
        -- see comment below about error handling
        when others then 
            -- signal yourself it went wrong
            RAISE;   
    end;
    

    The trouble with an anonymous block would be that it is right away executed. But that way you only execute a createion of the procedure which does the compile. If you have several users you probably want to create different procedure names or you want to create different schemas even to prevent conflicts. As I said this is not the full solution but just pointing into some direction.

    "ORA-23344 success with compilation error" can be used to fetch compile errors.

提交回复
热议问题