I need to create auditing tables in Oracle using a Loading Knowledge Module (LKM).
Knowledge Modules typically create various tables, triggers and views which are named dynamically, e.g.: C$_tablename, J$_tablename, T$_tablename, JV$_tablename, etc. etc.
I would like to do something similar for my auditing tables, i.e. all audit tables would be called “tablename_audit”, but do not how to set this up in the LKM code.
As an example, the following LKM code is used to create a C$ work table:
create table <%=odiRef.getTable("L", "COLL_NAME", "A")%>
(
<%=odiRef.getColList("", "[CX_COL_NAME]\t[DEST_WRI_DT] NULL", ",\n\t", "","")%>
)
And the following IKM code creates an I$ flow table:
create table <%=odiRef.getTable("L", "INT_NAME", "W")%>
(
<%=odiRef.getColList("", "[COL_NAME]\t[DEST_WRI_DT] NULL", ",\n\t", "", "")%>
,IND_UPDATE char(1)
)
INT_NAME and COLL_NAME seem to be constants defined in the Substitution API, as specified here.
So, how can I use the knowledge module to create similar tables with dynamic names in an Oracle Database?
Thank you.
I managed to solve this as follows.
<%=odiRef.getTable("L", "TARG_NAME", "A")%>returns the target table name in DATABASE.”tablename” format.I therefore added a step to my LKM which uses Jython to extract the tablename from the DATABASE.”tablename” string, append “_audit” to the table name, and then save the DATABASE.”tablename_audit” string to a Jython variable, as shown below.
However, since Jython variables cannot be used from SQL scripts in ODI, I added another step to my LKM which fetches the Jython variable into a Java variable (which can then be used by ODI objects) using ODI Expert’s Jython to Java API.
I could then easily use the
JAVA_AUDIT_TABLEvariable in my SQL scripts to create the required tables in my target database.