How can I get position of an error in Oracle SQL query?

后端 未结 3 881
悲哀的现实
悲哀的现实 2021-01-18 05:52

How can I get position of an error in the query?

I need to get position in a query string which causes an error, like sqlplus does it:

S         


        
3条回答
  •  無奈伤痛
    2021-01-18 06:41

    After some ramblings when I almost lost hope, I found (thanks to correct search string in Google) following link: https://forums.oracle.com/thread/1000551

    SQL> DECLARE
      2     c   INTEGER := DBMS_SQL.open_cursor ();
      3  BEGIN
      4     DBMS_SQL.parse (c, 'select * form dual', DBMS_SQL.native);
      5
      6     DBMS_SQL.close_cursor (c);
      7  EXCEPTION
      8     WHEN OTHERS THEN
      9        DBMS_OUTPUT.put_line ('Last Error: ' || DBMS_SQL.LAST_ERROR_POSITION ());
     10        DBMS_SQL.close_cursor (c);
     11        RAISE;
     12  END;
     13  /
    Last Error: 9
    DECLARE
    *
    ERROR at line 1:
    ORA-00923: FROM keyword not found where expected
    ORA-06512: at line 11
    

提交回复
热议问题