Sunday, August 1, 2010

Table API Generator for Oracle

Idea is to only maintain tables and generate table API (TAPI) packages for data manipulation.
Generated:
  • insert, update, delete, querying procedures
  • documentation based on table columns comments
For example, to insert some data to table, should be used code below

DECLARE
  user_rec ap_users_ta.user_rec;
  user_tab ap_users_ta.user_tab;
BEGIN
  user_rec.id           := 1;
  user_rec.firstname    := 'FirstName';
  user_rec.lastname     := 'LastName';
  user_rec.country      := 'country';
  user_rec.create_date  := SYSDATE;
  user_tab(1) := user_rec;
  ap_users_ta.ins(user_tab);
END;

Example of selecting data:

SET serveroutput ON
DECLARE
  user_rec ap_users_ta.user_rec;
  user_cur ap_users_ta.user_cur;
BEGIN
  user_rec.firstname := 'First%';
  ap_users_ta.qry( user_cur, user_rec );
  FETCH user_cur INTO user_rec;
  CLOSE user_cur;
  dbms_output.put_line( user_rec.firstname || ', ' || user_rec.lastname );
END;

For more details and code, see Table API Generator project page.

No comments:

Post a Comment