One Star

TRUNCATE TABLE ONLY IF NECESSARY

Hi,
i want read table and create different flow data filtering by a column.
For each flow i want truncate the target table of the flow only if the flow contain data.
It's possible to do?
See picture
4 REPLIES
Seventeen Stars

Re: TRUNCATE TABLE ONLY IF NECESSARY

It is possible, but not in the way describe. You have to check before if your query would return datasets (replace the result columns with a count(*)) and depending on the result you have to truncate the tables in separate tOracleRow components.
Probably you already though this, sorry there is no easy way to solve this.
Seven Stars

Re: TRUNCATE TABLE ONLY IF NECESSARY

The easiest way is include a row counter in each flow and put a tOracleRow between tMap and tOracleOutput. Make the statement something like: <row>.<column> == 1 ? "TRUNCATE TABLE <table>" : "SELECT Null"
One Star

Re: TRUNCATE TABLE ONLY IF NECESSARY

Hi,
how can I insert a row counter? I must use taggregaterow or something else? And after this:
<row>.<column> == 1 ? "TRUNCATE TABLE <table>" : "SELECT Null" --> I must truncate and insert if condition is true.
Whit your statement I can truncate but how can I insert?
Thanks in advance,
Gino.
Seven Stars

Re: TRUNCATE TABLE ONLY IF NECESSARY

Use e.g. Numeric.sequence("out1",1,1) in tMap to create a row counter. Make sure the sequence has a different name for each flow to a different table.
tOracleRow just does the truncation for the first row that passes through. tOracleOutput still does the insert.