Parsing affected db objects(Java version)

This article is aimed to help you fully take advantage of the general SQL parser to parse the SQL statement and retrieve detailed information about affected DB objects in a SQL script.

Here is an article about .NET version.

Let’s take this Oracle create package script for example:

CREATE OR REPLACE PACKAGE BODY emp_actions AS  -- body
  CURSOR desc_salary RETURN EmpRecTyp IS
     SELECT empno, sal FROM emp ORDER BY sal DESC;
  PROCEDURE hire_employee (
     ename  VARCHAR2,
     job    VARCHAR2,
     mgr    NUMBER,
     sal    NUMBER,
     comm   NUMBER,
     deptno NUMBER) IS
  BEGIN
     INSERT INTO emp VALUES (empno_seq.NEXTVAL, ename, job,
        mgr, SYSDATE, sal, comm, deptno);
  END hire_employee;

  PROCEDURE fire_employee (emp_id NUMBER) IS
  BEGIN
     DELETE FROM emp WHERE empno = emp_id;
  END fire_employee;
END emp_actions;

After processed by this Java demo, the result will be something like this:

Table affected:
emp   1(select)   0(create)   1(delete)   1(insert)   0(update)

Download this demo: Java version, C# version